-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.lua
More file actions
325 lines (280 loc) · 8.35 KB
/
clock.lua
File metadata and controls
325 lines (280 loc) · 8.35 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
-- clock.lua
-- (c) 2025 eightyfivenine
-- repo: https://github.com/user8595/cc-scripts
local hour, min = math.modf(os.time())
local minDisp = 0
local tW, tH = term.getSize()
local loopFunc = true
-- bg objects
local bgState = 1 -- 1-7
local sunYOff, moonYOff = 0, 0
local mBgCol = colors.lightGray
local starObj = {}
local timeMode = 1 -- 1 = game, 2 = utc
local switchFunc = true
local textInfo = {}
local headerCol, headerText
term.clear()
term.setBackgroundColor(0x8000)
for i = 1, 10, 1 do
table.insert(starObj, {
x = math.random(1, tW),
y = math.random(1, tH - 3),
id = math.random(0, 1) -- 0 = blue, 1 = yellow
})
end
table.insert(textInfo, { "r to shuffle stars, q to close", 0, 1 })
function tableClear(t)
for k in pairs(t) do
t[k] = nil
end
end
function bgRender()
paintutils.drawFilledBox(0, 0, tW, tH, colors.black)
if bgState == 1 then
sunYOff = tH + 2
if tW > 29 and tH > 12 then
moonYOff = 0
else
moonYOff = tH - 13
end
mBgCol = colors.lightGray
for _, star in ipairs(starObj) do
if star.id == 1 then
paintutils.drawPixel(star.x, star.y, colors.blue)
else
paintutils.drawPixel(star.x, star.y, colors.yellow)
end
end
end
if bgState == 2 then
if tW > 29 and tH > 12 then
sunYOff = tH - 12
moonYOff = tH - 8
else
sunYOff = tH - 9
moonYOff = tH - 6
end
mBgCol = colors.gray
for _, star in ipairs(starObj) do
paintutils.drawPixel(star.x, star.y, colors.gray)
end
end
if bgState == 3 then
if tW > 29 and tH > 12 then
sunYOff = tH - 15
else
sunYOff = tH - 11
end
moonYOff = tH - 32
mBgCol = colors.gray
end
if bgState == 4 then
sunYOff = tH - 13
moonYOff = tH - 32
mBgCol = colors.gray
end
if bgState == 5 then
if tW > 29 and tH > 12 then
sunYOff = tH - 14
else
sunYOff = tH - 12
end
moonYOff = tH - 4
mBgCol = colors.gray
end
if bgState == 6 then
if tW > 29 and tH > 12 then
sunYOff = tH - 8
moonYOff = tH - 11
else
sunYOff = tH - 6
moonYOff = tH - 9
end
mBgCol = colors.gray
for _, star in ipairs(starObj) do
paintutils.drawPixel(star.x, star.y, colors.gray)
end
end
if bgState == 7 then
if tW > 29 and tH > 12 then
sunYOff = tH + 2
moonYOff = tH - 16
else
sunYOff = tH + 2
moonYOff = tH - 13
end
mBgCol = colors.lightGray
for _, star in ipairs(starObj) do
if star.id == 1 then
paintutils.drawPixel(star.x, star.y, colors.blue)
else
paintutils.drawPixel(star.x, star.y, colors.yellow)
end
end
end
-- offset by 0, then 0 = 1
if tW > 29 and tH > 12 then
for i = 0, 5, 1 do
paintutils.drawLine(1 * i + 1 + 2, tH - 3 - 1 * (i - 1), 1 * i + 1 + (10 - (i * 2)) + 2, tH - 3 - 1 * (i - 1),
colors.green)
end
for i = 0, 8, 1 do
paintutils.drawLine(1 * i + 1 + 6 + 2, tH - 3 - 1 * (i - 1), 1 * i + 1 + (16 - (i * 2)) + 6 + 2,
tH - 3 - 1 * (i - 1), colors.brown)
end
else
for i = 0, 2, 1 do
paintutils.drawLine(1 * i + 1 + 2, tH - 3 - 1 * (i - 1), 1 * i + 1 + (4 - (i * 2)) + 2, tH - 3 - 1 * (i - 1),
colors.green)
end
for i = 0, 3, 1 do
paintutils.drawLine(1 * i + 1 + 3 + 2, tH - 3 - 1 * (i - 1), 1 * i + 1 + (6 - (i * 2)) + 3 + 2,
tH - 3 - 1 * (i - 1), colors.brown)
end
end
paintutils.drawFilledBox(tW - 9, 3 + moonYOff, tW - 3, 8 + moonYOff, mBgCol)
paintutils.drawFilledBox(tW - 10, 4 + moonYOff, tW - 2, 7 + moonYOff, mBgCol)
paintutils.drawPixel(tW - 4, 4 + moonYOff, colors.gray)
paintutils.drawPixel(tW - 8, 5 + moonYOff, colors.gray)
paintutils.drawPixel(tW - 5, 7 + moonYOff, colors.gray)
paintutils.drawFilledBox(tW - 9, 3 + sunYOff, tW - 3, 8 + sunYOff, colors.yellow)
paintutils.drawFilledBox(tW - 10, 4 + sunYOff, tW - 2, 7 + sunYOff, colors.yellow)
end
function displayRender()
paintutils.drawLine(0, tH, tW, tH, colors.gray)
paintutils.drawLine(tW - 8, tH, tW, tH, colors.red)
paintutils.drawFilledBox(0, tH - 1, tW, tH - 1, headerCol)
term.setCursorPos(2, tH - 1)
term.write(headerText)
term.setCursorPos(tW - 6, tH)
term.setBackgroundColor(colors.red)
term.write(string.format("%02d", math.floor(hour)) .. ":" .. string.format("%02d", math.floor(minDisp)))
term.setCursorPos(0, 2)
term.setBackgroundColor(colors.red)
term.write(os.date(" %d/%m/%Y "))
for i, text in ipairs(textInfo) do
term.setCursorPos(1, 1 + (i - 1))
if text[3] ~= 3 then
if timeMode == 1 then
term.setBackgroundColor(colors.green)
else
term.setBackgroundColor(colors.blue)
end
else
term.setBackgroundColor(colors.orange)
end
term.write(text[1])
end
end
function textUpdate()
if timeMode == 1 then
hour, min = math.modf(os.time())
else
hour, min = math.modf(os.time("local"))
end
minDisp = min * 60
for i, text in ipairs(textInfo) do
text[2] = text[2] + 0.05
if text[2] > 2 then
table.remove(textInfo, i)
end
end
if hour >= 0 and hour < 5 then
headerCol = colors.blue
headerText = "It is midnight now"
bgState = 1
end
if hour >= 5 and hour < 6 then
headerCol = colors.yellow
headerText = "It is dawn before sunrise"
bgState = 2
end
if hour >= 6 and hour < 12 then
headerCol = colors.orange
headerText = "It is morning now"
bgState = 3
end
if hour >= 12 and hour < 15 then
headerCol = colors.yellow
headerText = "It is day now"
bgState = 4
end
if hour >= 15 and hour < 18 then
headerCol = colors.orange
headerText = "It is afternoon now"
bgState = 5
end
if hour >= 18 and hour < 19 then
headerCol = colors.lightBlue
headerText = "It is dusk now"
bgState = 6
end
if hour >= 19 and hour < 24 then
headerCol = colors.lightBlue
headerText = "It is night now"
bgState = 7
end
end
function keyFunc()
while true do
local _, key = os.pullEvent("key")
if key == keys.q then
loopFunc = false
switchFunc = false
break
end
if key == keys.r then
if hour >= 19 or hour >= 0 and hour <= 6 then
tableClear(textInfo)
table.insert(textInfo, { "randomized stars", 0, 3 })
end
for _, star in ipairs(starObj) do
star.x = math.random(1, tW)
star.y = math.random(1, tH - 3)
star.id = math.random(0, 1)
end
end
end
end
function tModeSwitch()
while switchFunc do
local eventData = { os.pullEvent() }
local event = eventData[1]
if event == "mouse_click" then
timeMode = timeMode + 1
tableClear(textInfo)
-- on [2], 2 = 1, 3 = 2, and so on
if timeMode == 3 then
table.insert(textInfo, { "game time mode", 0, 2 })
end
if timeMode == 2 then
table.insert(textInfo, { "real time mode", 0, 1 })
end
if timeMode > 2 then
timeMode = 1
end
if timeMode < 1 then
timeMode = 2
end
end
end
end
function mainUpdate()
while loopFunc do
sleep(0.05)
tW, tH = term.getSize()
term.setBackgroundColor(0x8000)
-- term.setCursorPos(2, 2)
bgRender()
displayRender()
textUpdate()
end
return
end
parallel.waitForAll(mainUpdate, keyFunc, tModeSwitch)
term.setCursorPos(1, 1)
term.clear()
term.setBackgroundColor(0x8000)
term.clear()
term.setBackgroundColor(0x8000)