Updated radar scripts

Added workaround for OC OpenOS bug on background color handling
Fixed title centering
Code cleanup
This commit is contained in:
LemADEC 2015-08-16 18:24:04 +02:00
parent cd9b221e99
commit 132ab7da5c
2 changed files with 48 additions and 45 deletions

View file

@ -51,8 +51,8 @@ function translateXZ(oldX, oldZ, i)
x = x + (w / 2) x = x + (w / 2)
z = z + (h / 2) z = z + (h / 2)
x = math.floor(x); x = math.floor(x)
z = math.floor(z); z = math.floor(z)
return x,z return x,z
end end
@ -67,33 +67,33 @@ end
function scanAndDraw() function scanAndDraw()
local energy, energyMax = radar.getEnergyLevel() local energy, energyMax = radar.getEnergyLevel()
if (energy < radius*radius) then if (energy < radius*radius) then
hh = math.floor(h / 2); hh = math.floor(h / 2)
hw = math.floor(w / 2); hw = math.floor(w / 2)
paintutils.drawLine(hw - 5, hh - 1, hw + 5, hh - 1, colors.red); paintutils.drawLine(hw - 5, hh - 1, hw + 5, hh - 1, colors.red)
paintutils.drawLine(hw - 5, hh, hw + 5, hh, colors.red); paintutils.drawLine(hw - 5, hh, hw + 5, hh, colors.red)
textOut(hw - 4, hh,"LOW POWER", colors.white, colors.red); textOut(hw - 4, hh,"LOW POWER", colors.white, colors.red)
paintutils.drawLine(hw - 5, hh + 1, hw + 5, hh + 1, colors.red); paintutils.drawLine(hw - 5, hh + 1, hw + 5, hh + 1, colors.red)
sleep(1); sleep(1)
return 0; return 0
end; end
radar.scanRadius(radius); radar.scanRadius(radius)
sleep(2); sleep(2)
redraw(); redraw()
numResults = radar.getResultsCount(); numResults = radar.getResultsCount()
if (numResults ~= 0) then if (numResults ~= 0) then
for i = 0, numResults-1 do for i = 0, numResults-1 do
freq, cx, cy, cz = radar.getResult(i); freq, cx, cy, cz = radar.getResult(i)
drawContact(cx, cy, cz, freq, colors.red) drawContact(cx, cy, cz, freq, colors.red)
end end
end end
drawContact(radarX, radarY, radarZ, "RAD", colors.yellow); drawContact(radarX, radarY, radarZ, "RAD", colors.yellow)
end end
function redraw() function redraw()
@ -101,19 +101,19 @@ function redraw()
paintutils.drawLine(1, 1, w, 1, colors.black) paintutils.drawLine(1, 1, w, 1, colors.black)
textOut(h, 1, "= Q-Radar v0.1 =", colors.white, colors.black) textOut((w / 2) - 8, 1, "= Q-Radar v0.1 =", colors.white, colors.black)
textOut(w - 3, 1, "[X]", colors.white, colors.red) textOut(w - 3, 1, "[X]", colors.white, colors.red)
paintutils.drawLine(1, h, w, h, colors.black); paintutils.drawLine(1, h, w, h, colors.black)
local energy, energyMax = radar.getEnergyLevel() local energy, energyMax = radar.getEnergyLevel()
textOut(4, h, "Energy: " .. energy .. " EU | Scan radius: " .. radius, colors.white, colors.black) textOut(4, h, "Energy: " .. energy .. " EU | Scan radius: " .. radius, colors.white, colors.black)
end end
radarX, radarY, radarZ = radar.pos()
mrun = true mrun = true
while (mrun) do while (mrun) do
radarX, radarY, radarZ = radar.pos(); scanAndDraw()
scanAndDraw();
end end
term.clear(); term.clear()

View file

@ -1,4 +1,5 @@
local component = require("component") local component = require("component")
local computer = require("computer")
local term = require("term") local term = require("term")
radius = 500 radius = 500
scale = 50 scale = 50
@ -25,6 +26,7 @@ function textOut(x, y, text, fg, bg)
component.gpu.setBackground(bg) component.gpu.setBackground(bg)
component.gpu.setForeground(fg) component.gpu.setForeground(fg)
component.gpu.set(x, y, text) component.gpu.set(x, y, text)
component.gpu.setBackground(0x000000)
end end
end end
end end
@ -35,6 +37,7 @@ function drawBox(x, y, width, height, color)
if w then if w then
component.gpu.setBackground(color) component.gpu.setBackground(color)
component.gpu.fill(x, y, width, height, " ") component.gpu.fill(x, y, width, height, " ")
component.gpu.setBackground(0x000000)
end end
end end
end end
@ -49,8 +52,8 @@ function translateXZ(oldX, oldZ, i)
x = x + (w / 2) x = x + (w / 2)
z = z + (h / 2) z = z + (h / 2)
x = math.floor(x); x = math.floor(x)
z = math.floor(z); z = math.floor(z)
return x,z return x,z
end end
@ -65,31 +68,31 @@ end
function scanAndDraw() function scanAndDraw()
local energy, energyMax = radar.getEnergyLevel() local energy, energyMax = radar.getEnergyLevel()
if (energy < radius * radius) then if (energy < radius * radius) then
hh = math.floor(h / 2); hh = math.floor(h / 2)
hw = math.floor(w / 2); hw = math.floor(w / 2)
drawBox(hw - 5, hh - 1, 11, 3, 0xFF0000); drawBox(hw - 5, hh - 1, 11, 3, 0xFF0000)
textOut(hw - 4, hh, "LOW POWER", 0xFFFFFF, 0xFF0000); textOut(hw - 4, hh, "LOW POWER", 0xFFFFFF, 0xFF0000)
os.sleep(1); os.sleep(1)
return 0; return 0
end; end
radar.scanRadius(radius); radar.scanRadius(radius)
os.sleep(2); os.sleep(2)
redraw(); redraw()
numResults = radar.getResultsCount(); numResults = radar.getResultsCount()
if (numResults ~= 0) then if (numResults ~= 0) then
for i = 0, numResults-1 do for i = 0, numResults-1 do
freq, cx, cy, cz = radar.getResult(i); freq, cx, cy, cz = radar.getResult(i)
drawContact(cx, cy, cz, freq, 0xFF0000) drawContact(cx, cy, cz, freq, 0xFF0000)
end end
end end
drawContact(radarX, radarY, radarZ, "RAD", 0xFFFF00); drawContact(radarX, radarY, radarZ, "RAD", 0xFFFF00)
end end
function redraw() function redraw()
@ -97,10 +100,10 @@ function redraw()
drawBox(1, 1, w, 1, 0x000000) drawBox(1, 1, w, 1, 0x000000)
drawBox(1, 1, 1, h, 0x000000) drawBox(1, 1, 1, h, 0x000000)
drawBox(1, h, w, 1, 0x000000); drawBox(1, h, w, 1, 0x000000)
drawBox(w, h, 1, h, 0x000000); drawBox(w, 1, w, h, 0x000000)
textOut(h, 1, "= Q-Radar v0.1 =", 0xFFFFFF, 0x000000) textOut((w / 2) - 8, 1, "= Q-Radar v0.1 =", 0xFFFFFF, 0x000000)
textOut(w - 3, 1, "[X]", 0xFFFFFF, 0xFF0000) textOut(w - 3, 1, "[X]", 0xFFFFFF, 0xFF0000)
@ -108,10 +111,10 @@ function redraw()
textOut(4, h, "Energy: " .. energy .. " EU | Scan radius: " .. radius, 0xFFFFFF, 0x000000) textOut(4, h, "Energy: " .. energy .. " EU | Scan radius: " .. radius, 0xFFFFFF, 0x000000)
end end
mrun = true radarX, radarY, radarZ = radar.pos()
while (mrun) do
radarX, radarY, radarZ = radar.pos(); while component.isAvailable("warpdriveRadar") do
scanAndDraw(); scanAndDraw()
end end
term.clear(); term.clear()