Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- coord = {x = 0, y = 0}
- size = {x = 0, y = 0}
- time = 0
- function main()
- mon = peripheral.wrap("left")
- size.x, size.y = mon.getSize()
- local col = 0
- while true do
- sleep(0.05)
- time = time + 0.1
- for x = 1, size.x do
- for y = 1, size.y do
- coord.x = x
- coord.y = y
- col = pixel()
- mon.setCursorPos(x, y)
- mon.setBackgroundColor(getCol(col.r * 255, col.g * 255, col.b * 255))
- mon.write(' ')
- end
- end
- end
- end
- function pixel()
- local col = {}
- col.r = coord.x / size.x
- col.g = coord.y / size.y
- col.b = 0.5 + 0.5 * math.sin(time)
- return col
- end
- function sqr(x)
- return x*x
- end
- cols = {{240, 240, 240, colors.white},
- {242, 178, 51, colors.orange},
- {229, 127, 216, colors.magenta},
- {153, 178, 242, colors.lightBlue},
- {222, 222, 108, colors.yellow},
- {127, 204, 25, colors.lime},
- {242, 178, 204, colors.pink},
- {76, 76, 76, colors.gray},
- {153, 153, 153, colors.lightGray},
- {76, 153, 178, colors.cyan},
- {178, 102, 229, colors.purple},
- {51, 102, 204, colors.blue},
- {127, 102, 76, colors.brown},
- {87, 166, 78, colors.green},
- {204, 76, 76, colors.red},
- {0, 0, 0, colors.black}}
- function getCol(r, g, b)
- local dst = 0
- local best = 2147483647
- local col = 0
- for i = 1, #cols do
- dst = sqr(r - cols[i][1]) +
- sqr(g - cols[i][2]) +
- sqr(b - cols[i][3])
- if dst < best then
- best = dst
- col = cols[i][4]
- end
- end
- return col
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement