Advertisement
Doob

cameraX4

Jul 23rd, 2015
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.68 KB | None | 0 0
  1. local component = require('component')
  2. local term = require('term')
  3. local camera = component.camera
  4. local gpu = component.gpu
  5.  
  6. local color = {
  7.   0x000000,
  8.   0x111111,
  9.   0x222222,
  10.   0x333333,
  11.   0x444444,
  12.   0x555555,
  13.   0x666666,
  14.   0x777777,
  15.   0x000040,
  16.   0x000080,
  17.   0x002480,
  18.   0x0000BF,
  19.   0x0024BF,
  20.   0x002400,
  21.   0x004900,
  22.   0x006D00,
  23.   0x009200,
  24.   0x00B600,
  25.   0x33DB00,
  26.   0x99FF00,
  27.   0xCCFF00,
  28.   0xFFDB00,
  29.   0xFFB600,
  30.   0xFF9200,
  31.   0xFF6D00,
  32.   0xFF4900,
  33.   0xFF2400,
  34.   0xFF0000
  35. }
  36.  
  37. function render(size, zoom, fog, side) -- возвращает картинку и расстояние до первого блока напротив камеры
  38.   local tbl = {}
  39.   local pixel, d
  40.   if not fog then
  41.     fog = 1.2
  42.   end
  43.   if side == 0 then
  44.     look = camera.distanceDown
  45.   elseif side == 1 then
  46.     look = camera.distanceUp
  47.   else
  48.     look = camera.distance
  49.   end
  50.   local yp = 1
  51.   for j = -zoom, zoom, size do
  52.     tbl[yp] = {}
  53.     for i = zoom, -zoom, -size do
  54.       d = look(i, 0-j)
  55.       pixel = 1
  56.       if d > 0 then
  57.         pixel = 2+((#color-1)-math.min(#color-1, (d/fog)))
  58.       end
  59.       table.insert(tbl[yp], color[math.floor(pixel)])
  60.     end
  61.     yp = yp + 1
  62.   end
  63.   return tbl, look(0, 0)
  64. end
  65.  
  66. local function printX4(data)
  67.   term.clear()
  68.   for i = 1, #data, 2 do
  69.     for j = 1, #data[i] do
  70.       gpu.setBackground(data[i][j])
  71.       gpu.setForeground(data[i+1][j])
  72.       if i == 1 then
  73.         gpu.set(j, i, '-')
  74.       else
  75.         gpu.set(j, i-(i/2), '-')
  76.       end
  77.     end
  78.   end
  79. end
  80.  
  81. local fgrnd = gpu.getForeground()
  82. local bgrnd = gpu.getBackground()
  83. printX4(render(0.039, 1, 0.9))
  84. gpu.setForeground(fgrnd)
  85. gpu.setBackground(bgrnd)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement