Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modem = peripheral.wrap("right")
- Nradar = "radar_0"
- Nmon = "monitor_0"
- radius = 10000
- scale = 50
- w, h = term.getSize()
- term.clear()
- function colorScreen(color)
- for a = 2,w-1 do
- for b = 1,h do
- paintutils.drawPixel(a,b,color)
- end
- end
- end
- function textOut(x, y, text, fg, bg)
- term.setCursorPos(x, y)
- term.setTextColor(fg)
- term.setBackgroundColor(bg)
- term.write(text)
- local xt,yt = term.getCursorPos()
- term.setCursorPos(1, yt + 1)
- end
- function translateXZ(oldX, oldZ, i)
- local x = radarX - oldX
- local z = radarZ - oldZ
- x = x / (radius / scale)
- z = z / (radius / scale)
- x = x + (w / 2)
- z = z + (h / 2)
- x = math.floor(x);
- z = math.floor(z);
- return x,z
- end
- function drawContact(x, y, z, name, color)
- local newX, newZ = translateXZ(x, z)
- paintutils.drawPixel(newX, newZ, color)
- textOut(newX - 3, newZ + 1, "[" .. name .. "]", colors.white, colors.black)
- end
- function scanAndDraw()
- if (modem.callRemote(Nradar,"getEnergyLevel") < radius*radius) then
- hh = math.floor(h / 2);
- hw = math.floor(w / 2);
- paintutils.drawLine(hw - 5, hh - 1, hw + 5, hh - 1, colors.red);
- paintutils.drawLine(hw - 5, hh, hw + 5, hh, colors.red);
- textOut(hw - 4, hh,"LOW POWER", colors.white, colors.red);
- paintutils.drawLine(hw - 5, hh + 1, hw + 5, hh + 1, colors.red);
- sleep(1);
- return 0;
- end;
- modem.callRemote(Nradar,"scanRadiusW",radius);
- sleep(2);
- redraw();
- numResults = modem.callRemote(Nradar,"getResultsCountW");
- if (numResults ~= 0) then
- for i = 0, numResults-1 do
- freq, cx, cy, cz = modem.callRemote(Nradar,"getResultW",i);
- drawContact(cx, cy, cz, freq, colors.red)
- end
- end
- drawContact(radarX, radarY, radarZ, "RAD", colors.yellow);
- end
- function redraw()
- colorScreen(colors.green)
- textOut(1, h, "Energy: " .. modem.callRemote(Nradar,"getEnergyLevel") .. " Eu | Scan radius: " .. radius, colors.white, colors.black)
- end
- --mrun = true
- --while (mrun) do
- radarX = modem.callRemote(Nradar,"getRadarX");
- radarY = modem.callRemote(Nradar,"getRadarY");
- radarZ = modem.callRemote(Nradar,"getRadarZ");
- scanAndDraw();
- --end
- term.clear();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement