Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitorSide = "left"
- local file = "skgk.nfp" --file to read from
- local monitor = peripheral.wrap(monitorSide)
- local aniIdentifier = "--!--" --Identifier for new animation frame
- --returns the color from ID
- function getColor(hex)
- if hex == "0" then return colors.white
- elseif hex == "1" then return colors.orange
- elseif hex == "2" then return colors.magenta
- elseif hex == "3" then return colors.lightBlue
- elseif hex == "4" then return colors.yellow
- elseif hex == "5" then return colors.lime
- elseif hex == "6" then return colors.pink
- elseif hex == "7" then return colors.gray
- elseif hex == "8" then return colors.lightGray
- elseif hex == "9" then return colors.cyan
- elseif hex == "a" then return colors.purple
- elseif hex == "b" then return colors.blue
- elseif hex == "c" then return colors.brown
- elseif hex == "d" then return colors.green
- elseif hex == "e" then return colors.red
- elseif hex == "f" then return colors.black
- else return colors.black
- end
- end
- --Reads in a file and returns it in an 3 dimensional array (frame, x, y)
- function readFile(file)
- result = {}
- file = fs.open(file, "r")
- line = file.readLine()
- index = 0
- animation = 0
- result[animation] = {}
- while line ~= nil do
- if line == aniIdentifier then
- animation = animation + 1
- result[animation] = {}
- index = 0
- line = file.readLine()
- else
- result[animation][index] = {}
- for i = 0, string.len(line) do
- char = string.sub(line, i, i)
- if char == nil then char = "" end
- result[animation][index][i] = char
- end
- index = index + 1
- line = file.readLine()
- end
- end
- file.close()
- return result
- end
- --Prints a 2D array to the screen. Currently unused.
- function print2DArray(a)
- for i = 0, #a, 1 do
- for j = 0, #a[i], 1 do
- item = a[i][j];
- if item == nil then item = "null" end
- write(item)
- end
- print()
- end
- end
- --Draws the frame to the screen.
- function draw(a)
- for i = 0, #a, 1 do
- for j = 0, #a[i], 1 do
- item = a[i][j];
- monitor.setCursorPos(j, i + 1)
- monitor.setBackgroundColor(getColor(item))
- monitor.write(" ")
- end
- print()
- end
- end
- --Resets the monitor
- monitor.setCursorPos(1, 1)
- monitor.setBackgroundColor(colors.black)
- monitor.clear()
- local width = 8 * 10 + 2;
- local height = 5 * 6 + 3;
- pixels = readFile(file)
- --Loops through all the pixels and draws them!
- if #pixels == 1 then
- draw(pixels[0])
- else
- while true do
- for i = 0, #pixels do
- monitor.clear()
- monitor.setCursorPos(1, 1)
- draw(pixels[i])
- sleep(0.1)
- end
- end
- end
- --Resets cursor position so image is always seen from top left
- monitor.setCursorPos(1, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement