mouse961

RadarII

Jul 23rd, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. radar = peripheral.wrap("bottom")
  2. radius = 500
  3. scale = 50
  4.  
  5. w, h = term.getSize()
  6.  
  7. term.clear()
  8.  
  9. function colorScreen(color)
  10. for a = 2,w-1 do
  11. for b = 1,h do
  12. paintutils.drawPixel(a,b,color)
  13. end
  14. end
  15. end
  16.  
  17. function textOut(x, y, text, fg, bg)
  18. term.setCursorPos(x, y)
  19. term.setTextColor(fg)
  20. term.setBackgroundColor(bg)
  21. term.write(text)
  22. local xt,yt = term.getCursorPos()
  23. term.setCursorPos(1, yt + 1)
  24. end
  25.  
  26. function translateXZ(oldX, oldZ, i)
  27. local x = radarX - oldX
  28. local z = radarZ - oldZ
  29.  
  30. x = x / (radius / scale)
  31. z = z / (radius / scale)
  32.  
  33. x = x + (w / 2)
  34. z = z + (h / 2)
  35.  
  36.  
  37. x = math.floor(x);
  38. z = math.floor(z);
  39.  
  40. return x,z
  41. end
  42.  
  43. function drawContact(x, y, z, name, color)
  44. local newX, newZ = translateXZ(x, z)
  45.  
  46. paintutils.drawPixel(newX, newZ, color)
  47. textOut(newX - 3, newZ + 1, "[" .. name .. "]", colors.white, colors.black)
  48. end
  49.  
  50. function scanAndDraw()
  51. if (radar.getEnergyLevel() < radius*radius) then
  52. hh = math.floor(h / 2);
  53. hw = math.floor(w / 2);
  54.  
  55. paintutils.drawLine(hw - 5, hh - 1, hw + 5, hh - 1, colors.red);
  56. paintutils.drawLine(hw - 5, hh, hw + 5, hh, colors.red);
  57. textOut(hw - 4, hh,"LOW POWER", colors.white, colors.red);
  58. paintutils.drawLine(hw - 5, hh + 1, hw + 5, hh + 1, colors.red);
  59. sleep(1);
  60.  
  61. return 0;
  62. end;
  63. radar.scanRadius(radius);
  64. sleep(2);
  65.  
  66. redraw();
  67.  
  68. numResults = radar.getResultsCount();
  69.  
  70. if (numResults ~= 0) then
  71. for i = 0, numResults-1 do
  72. freq, cx, cy, cz = radar.getResult(i);
  73.  
  74. drawContact(cx, cy, cz, freq, colors.red)
  75. end
  76. end
  77.  
  78. drawContact(radarX, radarY, radarZ, "RAD", colors.yellow);
  79. end
  80.  
  81. function redraw()
  82. --shell.run("clear")
  83. colorScreen(colors.green)
  84.  
  85. paintutils.drawLine(1, 1, w, 1, colors.black)
  86.  
  87. textOut(h, 1, "= Q-Radar v0.1 =", colors.white, colors.black)
  88.  
  89. textOut(w - 3, 1, "[X]", colors.white, colors.red)
  90.  
  91. paintutils.drawLine(1, h, w, h, colors.black);
  92. textOut(4, h, "Energy: " .. radar.getEnergyLevel() .. " Eu | Scan radius: " .. radius, colors.white, colors.black)
  93. end
  94.  
  95. mrun = true
  96. while (mrun) do
  97. radarX, radarY, radarZ = radar.pos();
  98. scanAndDraw();
  99. end
  100.  
  101. term.clear();
Advertisement
Add Comment
Please, Sign In to add comment