Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- YOU NEED TO DOWNLOAD THIS SCRIPT TO RUN IT! https://pastebin.com/umb1p8mJ
- print("_______ _______ _______ _______ _______")
- print("| | ___ | |_____| | | |")
- print("|_____ |_____ | |_____ | | | | |")
- print("")
- if not http then
- error("HTTP API is disabled! Enable it in your ComputerCraft.cfg")
- end
- print("Select Display Mode:")
- print("1. Craft-OS-PC GFX Mode (256 Colors)")
- print("2. Text Mode (51x19)")
- print("3. Mosaic Blocks (102x57)")
- write("Enter choice (1, 2, or 3): ")
- local choice
- while true do
- local event, p1 = os.pullEvent("char")
- if p1 == "1" or p1 == "2" or p1 == "3" then
- choice = tonumber(p1)
- print(p1)
- break
- end
- end
- local serverUrl = "http://localhost:5000/stream?mode=" .. choice
- print("Connecting to capture card stream...")
- local response = http.get(serverUrl, nil, true)
- if not response then
- error("Could not connect to the Flask server.")
- end
- local originalMode = term.getGraphicsMode()
- local screenWidth, screenHeight = 51, 19
- local pixelWidth, pixelHeight, frameSize
- if choice == 1 then
- term.setGraphicsMode(2)
- local cubeSize = 5
- for i = 16, 255 do
- local index = i - 16
- local rIndex = math.floor(index / (cubeSize * cubeSize))
- local gIndex = math.floor((index % (cubeSize * cubeSize)) / cubeSize)
- local bIndex = index % cubeSize
- local r = math.floor(rIndex * 255 / (cubeSize - 1))
- local g = math.floor(gIndex * 255 / (cubeSize - 1))
- local b = math.floor(bIndex * 255 / (cubeSize - 1))
- term.setPaletteColor(i, r / 255, g / 255, b / 255)
- end
- pixelWidth = screenWidth * 6
- pixelHeight = screenHeight * 9
- frameSize = pixelWidth * pixelHeight
- else
- term.setGraphicsMode(0)
- term.clear()
- pixelWidth = screenWidth * 6
- pixelHeight = screenHeight * 9
- frameSize = pixelWidth * pixelHeight
- end
- print("Streaming active. Press 'Q' to quit.")
- local running = true
- parallel.waitForAny(
- function()
- while running do
- local chunk = response.read(frameSize)
- if not chunk or #chunk < frameSize then
- print("\nStream connection lost or lagging.")
- break
- end
- if choice == 1 then
- -- FIXED & OPTIMIZED: Build a table of all row strings and push in one go
- term.setFrozen(true)
- local rows = {}
- local idx = 1
- for y = 0, pixelHeight - 1 do
- rows[y + 1] = chunk:sub(idx, idx + pixelWidth - 1)
- idx = idx + pixelWidth
- end
- term.drawPixels(0, 0, rows)
- term.setFrozen(false)
- sleep(0.001)
- elseif choice == 2 then
- local fullPixelWidth = screenWidth * 6
- for ty = 0, screenHeight - 1 do
- for tx = 0, screenWidth - 1 do
- local sampleX = tx * 6
- local sampleY = ty * 9
- local byteOffset = sampleY * fullPixelWidth + sampleX + 1
- local color = chunk:byte(byteOffset) or 0
- term.setCursorPos(tx + 1, ty + 1)
- term.setBackgroundColor(2 ^ color)
- term.write(" ")
- end
- end
- sleep(0.001)
- else
- for ty = 0, screenHeight - 1 do
- for tx = 0, screenWidth - 1 do
- local sampleX = tx * 6
- local sampleY = ty * 9
- local s0 = chunk:byte((sampleY + 1) * pixelWidth + (sampleX + 1) + 1) or 0
- local s1 = chunk:byte((sampleY + 1) * pixelWidth + (sampleX + 4) + 1) or 0
- local s2 = chunk:byte((sampleY + 4) * pixelWidth + (sampleX + 1) + 1) or 0
- local s3 = chunk:byte((sampleY + 4) * pixelWidth + (sampleX + 4) + 1) or 0
- local s4 = chunk:byte((sampleY + 7) * pixelWidth + (sampleX + 1) + 1) or 0
- local s5 = chunk:byte((sampleY + 7) * pixelWidth + (sampleX + 4) + 1) or 0
- local counts = {}
- local function tally(c)
- counts[c] = (counts[c] or 0) + 1
- end
- tally(s0); tally(s1); tally(s2); tally(s3); tally(s4); tally(s5)
- local fgColor, maxCount = 0, -1
- local bgColor = 0
- local secondMax = -1
- for col, cnt in pairs(counts) do
- if cnt > maxCount then
- secondMax = maxCount
- bgColor = fgColor
- maxCount = cnt
- fgColor = col
- elseif cnt > secondMax then
- secondMax = cnt
- bgColor = col
- end
- end
- if secondMax == -1 then
- bgColor = fgColor
- end
- local bitmask = 0
- if s0 == fgColor then bitmask = bitmask + 1 end
- if s1 == fgColor then bitmask = bitmask + 2 end
- if s2 == fgColor then bitmask = bitmask + 4 end
- if s3 == fgColor then bitmask = bitmask + 8 end
- if s4 == fgColor then bitmask = bitmask + 16 end
- if s5 == fgColor then bitmask = bitmask + 32 end
- local charCode = 128 + math.floor(bitmask / 2)
- term.setCursorPos(tx + 1, ty + 1)
- term.setTextColor(2 ^ fgColor)
- term.setBackgroundColor(2 ^ bgColor)
- local success, err = pcall(function()
- term.write(string.char(charCode))
- end)
- if not success then
- term.write(" ")
- end
- end
- end
- sleep(0.001)
- end
- end
- end,
- function()
- while running do
- local event, p1 = os.pullEvent("key")
- if event == "key" and p1 == keys.q then
- running = false
- end
- end
- end
- )
- response.close()
- term.setGraphicsMode(originalMode)
- term.clear()
- print("Stream closed successfully.")
Add Comment
Please, Sign In to add comment