Advertisement
Doob

ComputronicsCameraAdv

Jul 15th, 2015
955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.06 KB | None | 0 0
  1. local component = require('component')
  2. local term = require('term')
  3. local event = require('event')
  4. local camera = component.camera
  5. local gpu = component.gpu
  6.  
  7. local tDiamondZ = {
  8.   {0.04, 1},
  9.   {0.036, 0.9},
  10.   {0.032, 0.8},
  11.   {0.028, 0.7},
  12.   {0.024, 0.6},
  13.   {0.02, 0.5},
  14.   {0.016, 0.4},
  15.   {0.012, 0.3},
  16.   {0.008, 0.2},
  17.   {0.004, 0.1}
  18. }
  19.  
  20. local tGoldZ = {
  21.   {0.08, 1},
  22.   {0.072, 0.9},
  23.   {0.064, 0.8},
  24.   {0.056, 0.7},
  25.   {0.48, 0.6},
  26.   {0.04, 0.5},
  27.   {0.032, 0.4},
  28.   {0.024, 0.3},
  29.   {0.016, 0.2},
  30.   {0.008, 0.1}
  31. }
  32.  
  33. local color_gray = {
  34.   0x000000,
  35.   0x111111,
  36.   0x222222,
  37.   0x333333,
  38.   0x444444,
  39.   0x555555,
  40.   0x666666,
  41.   0x777777,
  42.   0x888888,
  43.   0x999999,
  44.   0xAAAAAA,
  45.   0xBBBBBB,
  46.   0xCCCCCC,
  47.   0xDDDDDD,
  48.   0xEEEEEE,
  49.   0xFFFFFF
  50. }
  51.  
  52. local color_gold = {
  53.   0x000000,
  54.   0x0000FF,
  55.   0x00AAAA,
  56.   0x00FFFF,
  57.   0x008800,
  58.   0x00FF00,
  59.   0xFFFF00,
  60.   0xAAAA00,
  61.   0xFF0000
  62. }
  63.  
  64. local color_rainbow = {
  65.   0x000000,
  66.   0x000040,
  67.   0x000080,
  68.   0x002480,
  69.   0x0000BF,
  70.   0x0024BF,
  71.   0x002400,
  72.   0x004900,
  73.   0x006D00,
  74.   0x009200,
  75.   0x00B600,
  76.   0x33DB00,
  77.   0x99FF00,
  78.   0xCCFF00,
  79.   0xFFDB00,
  80.   0xFFB600,
  81.   0xFF9200,
  82.   0xFF6D00,
  83.   0xFF4900,
  84.   0xFF2400,
  85.   0xFF0000
  86. }
  87.  
  88. function render(size, zoom, color, side)
  89.   local tbl = {}
  90.   if side == 'up' then
  91.     look = camera.distanceUp
  92.   elseif side == 'down' then
  93.     look = camera.distanceDown
  94.   else
  95.     look = camera.distance
  96.   end
  97.   term.clear()
  98.   term.setCursor(1,1)
  99.   local yp = 1
  100.   for j = -zoom, zoom, size do
  101.     for i = zoom, -zoom, -size do
  102.       local d = look(i, 0-j)
  103.       local a = 1
  104.       if d>0 then
  105.         a = 2+((#color-1)-math.min(#color-1, (d/1.2)))
  106.       end
  107.       gpu.setForeground(color[math.floor(a)])
  108.       term.write('██')
  109.     end
  110.     yp=yp+1
  111.     term.setCursor(1,yp)
  112.   end
  113. end
  114.  
  115. fgrnd = gpu.getForeground()
  116. xres, yres = gpu.getResolution()
  117. term.clear()
  118.  
  119. print('Использование:\n[z] - приблизить\n[c] - отдалить\n[backspace] - сбросить\n[x] - перейти в улучшенный режим\n (корректное отбражение только на мониторах III уровня)\n[q] - выйти\nДля продолжения нажмите любую клавишу.')
  120.  
  121. if gpu.maxResolution() == 160 then
  122.   clr = color_gray
  123.   zoom = tDiamondZ
  124.   gpu.setResolution(99, 50)
  125. elseif gpu.maxResolution() == 80 then
  126.   clr = color_gold
  127.   zoom = tGoldZ
  128.   gpu.setResolution(52, 26)
  129. else
  130.   print('Используемое устройство вывода не поддерживается.')
  131.   os.exit()
  132. end
  133.  
  134. local zm = 1
  135. while true do
  136.   _, _ , _, code, _, _ = event.pull('key_down')
  137.   if code == 44 then
  138.     zm = zm+1
  139.     if zm > #zoom then
  140.       zm = 1
  141.     end
  142.   elseif code == 46 then
  143.     zm = zm-1
  144.     if zm < 1 then
  145.       zm = 1
  146.     end
  147.   elseif code == 45 then
  148.     clr = color_rainbow
  149.   elseif code == 14 then
  150.     zm = 1
  151.   elseif code == 16 then
  152.     gpu.setForeground(fgrnd)
  153.     gpu.setResolution(xres, yres)
  154.     term.clear()
  155.     os.exit()
  156.   end
  157.   render(zoom[zm][1], zoom[zm][2], clr)
  158. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement