forked from OpenPrograms/Sangar-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
holo-count.lua
115 lines (109 loc) · 1.95 KB
/
holo-count.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
-- Generates a random heightmap and displays scrolling text above it.
local component = require("component")
local keyboard = require("keyboard")
local hologram = component.hologram
hologram.clear()
-- in this example all of these must be five wide
local glyphs = {
[0]=[[
XXX
X X
X X X
X X
XXX
]],
[1]=[[
XX
X X
X
X
X
]],
[2]=[[
XXXX
X
X
X
XXXXX
]],
[3]=[[
XXXX
X
XXX
X
XXXX
]],
[4]=[[
X X
X X
XXXXX
X
X
]],
[5]=[[
XXXXX
X
XXXX
X
XXXX
]],
[6]=[[
XXX
X
XXXX
X X
XXX
]],
[7]=[[
XXXXX
X
XXX
X
X
]],
[8]=[[
XXX
X X
XXX
X X
XXX
]],
[9]=[[
XXX
X X
XXXX
X
XXX
]]
}
-- Prepopulate data table; this represents the whole hologram data as a single
-- linear array, nested as y,z,x. In other words, if the hologram were 3x3x3:
-- {(1,1,1),(1,2,1),(1,3,1),(1,1,2),(1,2,2),(1,3,2),(1,1,3),(1,2,3),(1,3,3),(2,1,1),...}
-- Each entry must be a single char; they are merged into a single byte array
-- (or string) before sending the data to the hologram via table.concat. We don't
-- keep the data as a string, because we'd have to create a new string when
-- modifying it, anyway (because you can't do myString[3]="\0").
local data = {}
for i = 1, 32*48*48 do data[i] = "\0" end
local w,h=5,5
local x0 = math.floor((48-w)/2)
local z0 = math.floor(48/2)
local y0 = math.floor((32-h)/2)
print("Press Ctrl+W to stop.")
for i = 1, math.huge do
local num = glyphs[i % 9 + 1]
for y = 1, h do
for x = 1, w do
-- flip chars vertically, because hologram y axis goes up
local charIdx = 1 + (x-1)+(h-y)*(w+1)
local dataIdx = 1 + (y0+y-1) + z0*32 + (x0+x-1)*32*48
data[dataIdx] = num:sub(charIdx, charIdx) == " " and "\0" or "\1"
end
end
hologram.setRaw(table.concat(data))
os.sleep(0) -- for event handling for keyboard keydown checks.
if keyboard.isKeyDown(keyboard.keys.w) and keyboard.isControlDown() then
hologram.clear()
os.exit()
end
end