1+ using os
2+ using math
3+
4+ # distance from a to b
5+ func distance(a :: Number,b :: Number)->Number {
6+ return ({math.max(a,b)} - {math.min(a,b)})
7+ }
8+
9+ # returns b if a is closer to b and c if a is closer to c
10+ func closer_to(a :: Number,b :: Number,c :: Number)->Number {
11+ if({distance(a,b)} < {distance(a,c)}) {
12+ return b
13+ }
14+ return c
15+ }
16+
17+ # returns the closest direction for a given time
18+ func closest(a :: Number)->Number {
19+ if({closer_to(a,45,15)} == 15) {
20+ if({closer_to(a,0,30)} == 30) {
21+ return {closer_to(a,15,30)}
22+ }
23+ else {
24+ return {closer_to(a,0,15)}
25+ }
26+ }
27+ else {
28+ if({closer_to(a,0,30)} == 30) {
29+ return {closer_to(a,45,30)}
30+ }
31+ else {
32+ return {closer_to(a,0,45)}
33+ }
34+ }
35+ }
36+
37+ func get_min_pos()->List {
38+ new L0 [
39+ ["","","","","","","","",""],
40+ ["","","","","|","","","",""],
41+ ["","","","","|","","","",""],
42+ ["","","","","","","","",""],
43+ ["","","","","","","","",""],
44+ ["","","","","","","","",""],
45+ ["","","","","","","","",""]
46+ ]
47+ new L15 [
48+ ["","","","","","","","",""],
49+ ["","","","","","","","",""],
50+ ["","","","","","","","",""],
51+ ["","","","","","-","-","-",""],
52+ ["","","","","","","","",""],
53+ ["","","","","","","","",""],
54+ ["","","","","","","","",""]
55+ ]
56+ new L30 [
57+ ["","","","","","","","",""],
58+ ["","","","","","","","",""],
59+ ["","","","","","","","",""],
60+ ["","","","","","","","",""],
61+ ["","","","","|","","","",""],
62+ ["","","","","|","","","",""],
63+ ["","","","","","","","",""]
64+ ]
65+ new L45 [
66+ ["","","","","","","","",""],
67+ ["","","","","","","","",""],
68+ ["","","","","","","","",""],
69+ ["","-","-","-","","","","",""],
70+ ["","","","","","","","",""],
71+ ["","","","","","","","",""],
72+ ["","","","","","","","",""]
73+ ]
74+
75+ new clst {closest({os.time("minutes")})}
76+
77+ if(clst == 0) {
78+ return L0
79+ }
80+ elif(clst == 15) {
81+ return L15
82+ }
83+ elif(clst == 30) {
84+ return L30
85+ }
86+ elif(clst == 45) {
87+ return L45
88+ }
89+ }
90+
91+ func get_hour_pos()->List {
92+ new L0 [
93+ ["","","","","","","","",""],
94+ ["","","","","","","","",""],
95+ ["","","","","#","","","",""],
96+ ["","","","","","","","",""],
97+ ["","","","","","","","",""],
98+ ["","","","","","","","",""],
99+ ["","","","","","","","",""]
100+ ]
101+ new L15 [
102+ ["","","","","","","","",""],
103+ ["","","","","","","","",""],
104+ ["","","","","","","","",""],
105+ ["","","","","","#","#","",""],
106+ ["","","","","","","","",""],
107+ ["","","","","","","","",""],
108+ ["","","","","","","","",""]
109+ ]
110+ new L30 [
111+ ["","","","","","","","",""],
112+ ["","","","","","","","",""],
113+ ["","","","","","","","",""],
114+ ["","","","","","","","",""],
115+ ["","","","","#","","","",""],
116+ ["","","","","","","","",""],
117+ ["","","","","","","","",""]
118+ ]
119+ new L45 [
120+ ["","","","","","","","",""],
121+ ["","","","","","","","",""],
122+ ["","","","","","","","",""],
123+ ["","","#","#","","","","",""],
124+ ["","","","","","","","",""],
125+ ["","","","","","","","",""],
126+ ["","","","","","","","",""]
127+ ]
128+
129+ new clst {closest({os.time("hours")})}
130+
131+ if(clst == 0) {
132+ return L0
133+ }
134+ elif(clst == 15) {
135+ return L15
136+ }
137+ elif(clst == 30) {
138+ return L30
139+ }
140+ elif(clst == 45) {
141+ return L45
142+ }
143+ }
144+
145+ func generate_buffer()->String {
146+ new buffer ">> CLOCK: <<\n"
147+
148+ new min_pos {get_min_pos()}
149+ new hour_pos {get_hour_pos()}
150+
151+ new time_numbers [
152+ ["","","","","0","","","",""],
153+ ["","","","","","","","",""],
154+ ["","","","","","","","",""],
155+ ["9","","","","@","","","","3"],
156+ ["","","","","","","","",""],
157+ ["","","","","","","","",""],
158+ ["","","","","6","","","",""]
159+ ]
160+
161+ for y in {min_pos.length()} {
162+ new line_m {min_pos.at(y)}
163+ new line_h {hour_pos.at(y)}
164+ new line_t {time_numbers.at(y)}
165+ for x in {line_h.length()} {
166+ new add " "
167+ if({line_m.at(x)} != "") {
168+ set add {line_m.at(x)}
169+ }
170+ if({line_h.at(x)} != "") {
171+ set add {line_h.at(x)}
172+ }
173+ if({line_t.at(x)} != "") {
174+ set add {line_t.at(x)}
175+ }
176+
177+ set buffer (buffer + add)
178+ }
179+ if(y+1 != {min_pos.length()}) {
180+ set buffer (buffer + "\n")
181+ }
182+ }
183+ return buffer
184+ }
185+
186+ func schedule()->Void {
187+ while(1) {
188+ os.clear()
189+ print {generate_buffer()}
190+ os.sleep(3000)
191+ }
192+ }
193+
194+ if({os.main_file()}) {
195+ schedule()
196+ }
0 commit comments