--@name Image Loader --@author local maxOps = 98000 local imgSize = 512 --local urlTxt = "http://puu.sh/7YPX6.txt" -- Cat1 --local urlTxt = "http://puu.sh/7YQeN.txt" -- Cat2 --local urlTxt = "http://puu.sh/7YPZU.txt" -- cecube --local urlTxt = "http://puu.sh/7YRHF.txt" -- natmini --local urlTxt = "http://puu.sh/7YSAG.txt" -- nat3 --local urlTxt = "http://puu.sh/7YQJN.txt" -- JB --local urlTxt = "http://puu.sh/7ZGtv.txt" -- d3 x184 local urlTxt = "http://puu.sh/7ZPSf.txt" -- hatsune local urlTxt = "http://puu.sh/7ZQ5E.txt" -- hatsune2 local http = loadLibrary("http") local wire = loadLibrary("wire") local hook = loadLibrary("hook") wire.adjustInputs({"Screen"}, {"wirelink"}) --wire.createInputs({"Screen"}, {"wirelink"}) local Screen = wire.ports.Screen local imgData = "" function rgb2digiN(input) if input == "0" then return "000" elseif string.len(input) == 1 then return "00" .. input elseif string.len(input) == 2 then return "0" .. input else return input end end function rgb2digi(col1, col2, col3) return tonumber(rgb2digiN(col1) .. rgb2digiN(col2) .. rgb2digiN(col3)) end --print(rgb2digi(1, 1, 255)) local getPixels = { onChar = 1, pixelColor = Color(0, 0, 0), } function getPixels:next() local x = 0 local i = 0 local resultString = "" while x < 3 do i = i + 1 --x = x + 1 --print(imgData[self.onChar]) resultString = resultString .. imgData[self.onChar] if resultString[string.len(resultString)] == ',' then x = x + 1 end self.onChar = self.onChar + 1 end return string.split(resultString, ",") end function imgLoad(body, length, headers, code) imgData = body local currentPixel = 0 hook.add("think", "image", function() local pixelX = 0 local pixelY = 0 while (opsUsed() < maxOps) do local colors = getPixels:next() pixelX = currentPixel % imgSize pixelY = math.floor(currentPixel / imgSize) --print("x: " .. pixelX .. " y: " .. pixelY) Screen[pixelX + pixelY * imgSize] = rgb2digi(colors[1], colors[2], colors[3]) currentPixel = currentPixel + 1 --print(currentPixel) if currentPixel >= imgSize * imgSize then hook.remove("think", "image") break end end end) end function imgFail(reason) --print("Failed to load image: " .. reason) end if SERVER then if wire.ports.Screen then Screen[1048574] = 1 -- Clear Screen[1048569] = 3 Screen[1048572] = imgSize Screen[1048573] = imgSize http.get(urlTxt, imgLoad, imgFail) end --print(http.canRequest()) end