Advertisement
Guest User

r

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