Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- if #tArgs < 1 then
- error("Usage: view <image filename>")
- end
- if not fs.exists(tArgs[1]) then
- error("Not an image file")
- end
- image = paintutils.loadImage(tArgs[1])
- local w, h = term.getSize()
- local imgW = 0
- local imgH = 0
- local imgWMax = 0
- for i, v in pairs(image) do
- imgH = imgH + 1
- imgW = 0
- for k, e in pairs(v) do
- imgW = imgW + 1
- if imgW > imgWMax then
- imgWMax = imgW
- end
- end
- end
- imgW = imgWMax
- drawX = w / 2 - imgW / 2 + 1
- drawY = h / 2 - imgH / 2 + 1
- local begin = true
- while true do
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- paintutils.drawImage(image, drawX, drawY)
- if begin then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(1, h)
- term.write("Arrow keys to move, Ctrl to quit")
- end
- events = {os.pullEvent()}
- if events[1] == "key" then
- if events[2] == 200 then
- drawY = drawY + 1
- begin = false
- elseif events[2] == 205 then
- drawX = drawX - 1
- begin = false
- elseif events[2] == 208 then
- drawY = drawY - 1
- begin = false
- elseif events[2] == 203 then
- drawX = drawX + 1
- begin = false
- elseif events[2] == 29 then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- break
- end
- sleep(.1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement