forked from OpenPrograms/Sangar-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geo2holo.lua
57 lines (53 loc) · 1.47 KB
/
geo2holo.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
local component = require("component")
if not component.isAvailable("geolyzer") then
io.stderr:write("This program requires a Geolyzer to run.\n")
return
end
if not component.isAvailable("hologram") then
io.stderr:write("This program requires a Hologram Projector to run.\n")
return
end
local sx, sz = 48, 48
local ox, oz = -24, -24
local starty, stopy = -5
local function validateY(value, min, max, default)
value = tonumber(value) or default
if value < min or value > max then
io.stderr:write("invalid y coordinate, must be in [" .. min .. ", " .. max .. "]\n")
os.exit(1)
end
return value
end
do
local args = {...}
starty = validateY(args[1], -32, 31, starty)
stopy = validateY(args[2], starty, starty + 32, math.min(starty + 32, 31))
end
component.hologram.clear()
for x=ox,sx+ox do
for z=oz,sz+oz do
local hx, hz = 1 + x - ox, 1 + z - oz
local column = component.geolyzer.scan(x, z, false)
for y=1,1+stopy-starty do
local color = 0
if column then
local hardness = column[y + starty + 32]
if hardness == 0 or not hardness then
color = 0
elseif hardness < 3 then
color = 2
elseif hardness < 100 then
color = 1
else
color = 3
end
end
if component.hologram.maxDepth() > 1 then
component.hologram.set(hx, y, hz, color)
else
component.hologram.set(hx, y, hz, math.min(color, 1))
end
end
os.sleep(0)
end
end