View difference between Paste ID: 4Gh5tJDc and bUraSkGB
SHOW: | | - or go back to the newest paste.
1-
radar = peripheral.wrap("bottom")
1+
modem = peripheral.wrap("right")
2-
radius = 500
2+
Nradar = "radar_0"
3
Nmon = "monitor_0"
4
5
radius = 10000
6
scale = 50
7
8
w, h = term.getSize()
9
10-
  for a = 2,w-1 do
10+
11-
         for b = 1,h do
11+
12-
           paintutils.drawPixel(a,b,color)
12+
13-
         end
13+
 for a = 2,w-1 do
14
  for b = 1,h do
15
    paintutils.drawPixel(a,b,color)
16
  end
17
 end
18
end
19
20
function textOut(x, y, text, fg, bg)
21
 term.setCursorPos(x, y)
22
 term.setTextColor(fg)
23
 term.setBackgroundColor(bg)
24
 term.write(text)
25
 local xt,yt = term.getCursorPos()
26
 term.setCursorPos(1, yt + 1)
27-
	local x = radarX - oldX
27+
28-
	local z = radarZ - oldZ
28+
29-
	
29+
30
 local x = radarX - oldX
31
 local z = radarZ - oldZ
32
 x = x / (radius / scale)
33
 z = z / (radius / scale)
34
 x = x + (w / 2)
35
 z = z + (h / 2)
36-
 
36+
37
 z = math.floor(z);
38
 return x,z
39-
 
39+
40-
	return x,z
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 (modem.callRemote(Nradar,"getEnergyLevel") < radius*radius) then
50
    hh = math.floor(h / 2);
51-
  if (radar.getEnergyLevel() < radius*radius) then
51+
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
  modem.callRemote(Nradar,"scanRadiusW",radius);
62
  sleep(2);
63-
  radar.scanRadiusW(radius);
63+
64
  redraw();
65
  
66
  numResults = modem.callRemote(Nradar,"getResultsCountW");
67
  
68-
  numResults = radar.getResultsCountW();
68+
69
    for i = 0, numResults-1 do
70
      freq, cx, cy, cz = modem.callRemote(Nradar,"getResultW",i);
71
      
72-
      freq, cx, cy, cz = radar.getResultW(i);
72+
73
    end
74
  end
75
  
76
  drawContact(radarX, radarY, radarZ, "RAD", colors.yellow);
77
end
78
79
function redraw()
80
   colorScreen(colors.green)
81
   textOut(1, h, "Energy: " .. modem.callRemote(Nradar,"getEnergyLevel") .. " Eu | Scan radius: " .. radius, colors.white, colors.black)
82-
   --shell.run("clear")
82+
83
84-
   
84+
--mrun = true
85-
   paintutils.drawLine(1, 1, w, 1, colors.black)
85+
--while (mrun) do
86-
   
86+
 radarX = modem.callRemote(Nradar,"getRadarX");
87-
   textOut(h, 1, "= Q-Radar v0.1 =", colors.white, colors.black)
87+
 radarY = modem.callRemote(Nradar,"getRadarY");
88-
   
88+
 radarZ = modem.callRemote(Nradar,"getRadarZ");
89-
   textOut(w - 3, 1, "[X]", colors.white, colors.red)
89+
90-
   
90+
--end
91-
   paintutils.drawLine(1, h, w, h, colors.black);
91+
92-
   textOut(4, h, "Energy: " .. radar.getEnergyLevel() .. " Eu | Scan radius: " .. radius, colors.white, colors.black)
92+