Created
July 22, 2024 15:07
-
-
Save Qman11010101/aacd23b4838ab2b0c254a87077d8aba6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function drawPx(x, y, color, mon) | |
mon.setBackgroundColor(color) | |
mon.setCursorPos(x, y) | |
mon.write(" ") | |
end | |
print("Image Display v0.0.1") | |
local url = ... | |
if url == nil then | |
print("Usage: imagedisp <URL>") | |
end | |
-- Get monitor's direction | |
print("Detecting monitor...") | |
local p_dirs = peripheral.getNames() | |
local monitorSide = "" | |
for i = 1, #p_dirs do | |
periType = peripheral.getType(p_dirs[i]) | |
if periType == "monitor" then | |
monitorSide = p_dirs[i] | |
print("Monitor found on "..monitorSide.." side!") | |
break | |
end | |
end | |
-- Get monitor's handler | |
local mon = peripheral.wrap(monitorSide) | |
mon.setTextScale(0.5) | |
-- Get image from Internet | |
print("Downloading image from "..url.."...") | |
local width, height = mon.getSize() | |
local imgHandler = http.get("https://qwertyman0213.npkn.net/ccconverter/?image="..url.."&width="..width.."&height="..height) | |
print("Loading image...") | |
local imageText = imgHandler.readAll() | |
local hex_table = {["0"] = 1, ["1"] = 2, ["2"] = 4, ["3"] = 8, ["4"] = 16, ["5"] = 32, ["6"] = 64, ["7"] = 128, ["8"] = 256, ["9"] = 512, ["a"] = 1024, ["b"] = 2048, ["c"] = 4096, ["d"] = 8192, ["e"] = 16384, ["f"] = 32768} | |
local crrX = 1 | |
local crrY = 1 | |
for i=1, #imageText do | |
local char = string.sub(imageText, i, i) | |
if char == "\n" then | |
crrY = crrY + 1 | |
crrX = 1 | |
else | |
local colorValue = hex_table[char] | |
drawPx(crrX, crrY, colorValue, mon) | |
crrX = crrX + 1 | |
end | |
end | |
print("Done!") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment