Doob

camera+terminalglasses

Apr 22nd, 2016
190
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require('component')
  2. local ob = component.openperipheral_bridge
  3. local camera = component.camera
  4.  
  5. local color = {}
  6.  
  7. local r, g, b = 255, 0, 0
  8.  
  9. for g = 0, 255, 8 do
  10.   table.insert(color, r*65536+g*256+b)
  11. end
  12. g = 255
  13. for r = 255, 0, -8 do
  14.   table.insert(color, r*65536+g*256+b)
  15. end
  16. r = 0
  17. for b = 0, 255, 8 do
  18.   table.insert(color, r*65536+g*256+b)
  19. end
  20. b = 255
  21. for g = 255, 0, -8 do
  22.   table.insert(color, r*65536+g*256+b)
  23. end
  24.  
  25. function render(size, zoom, fog, side)
  26.   local tbl, d, pix = {}
  27.   if not fog then
  28.     fog = 1.2
  29.   end
  30.   if side == 0 then
  31.     look = camera.distanceDown
  32.   elseif side == 1 then
  33.     look = camera.distanceUp
  34.   else
  35.     look = camera.distance
  36.   end
  37.   local yp = 1
  38.   for x = zoom, -zoom, -size do
  39.     tbl[yp] = {}
  40.     for y = -zoom, zoom, size do
  41.       d = look(x, 0-y)
  42.       if d < 0 then d = 32 end
  43.       table.insert(tbl[yp], color[math.ceil(d*(#color/32))])
  44.     end
  45.     yp = yp + 1
  46.   end
  47.   return tbl
  48. end
  49.  
  50. local function draw(data, size)
  51.   if not size then
  52.     size = 2
  53.   end
  54.   for j = 1, #data do
  55.     for i = 1, #data[j] do
  56.       ob.addBox(i*size, j*size, size, size, data[i][j])
  57.       os.sleep()
  58.     end
  59.     ob.sync()
  60.   end
  61. end
  62.  
  63. ob.clear()
  64.  
  65. draw(render(0.03, 1, 1), 3)
RAW Paste Data