### Author Topic: My Best Clock  (Read 1103 times)

Marked as best answer by SierraKen on December 06, 2019, 10:17:50 PM

#### SierraKen ##### Re: My Best Clock
« Reply #30 on: December 06, 2019, 08:11:21 PM »
Thanks b+ :).

Well I am finished now. Surprisingly I was able to find some cool patterns and designs experimenting with my old Fun With Math program and other programs. It changes to a different clock every minute change. After 10 clocks, it goes back to the beginning. It also still has the gong sound on top of the hour. This was really fun to make. I hope it's fun for you all to use and check out.
Below this code I will also add the original clock that b+ and Petr helped me on. That way I can make this post the best one and have both since both are equally as good. I didn't add the original clock to the changing clocks one because I wanted to make something from only myself this time. It feels good to learn something and be able to do it yourself sometimes.

Edit: I just added an animated GIF as an attachment, hopefully you guys can see the 10 clock pictures with this animation. The GIF changes every second. I also added a picture of b+'s version as an attachment.

Code: QB64: [Select]
1. 'Clocks by Ken G.
2. 'A clock face changes every minute. There are 10 clock faces.
3. 'Thank you to QB64.org Forum for the help!
4.
5. _TITLE "Clocks by Ken G."
6. SCREEN _NEWIMAGE(350, 350, 32)
7. i = _NEWIMAGE(350, 350, 32)
8.     _LIMIT 30
9.     hours = TIMER \ 3600
10.     minutes = TIMER \ 60 - hours * 60
11.     seconds = (TIMER - hours * 3600 - minutes * 60)
12.     ho\$ = LEFT\$(TIME\$, 2): hou = VAL(ho\$)
13.     min\$ = MID\$(TIME\$, 4, 2): minu = VAL(min\$)
14.     seco\$ = RIGHT\$(TIME\$, 2): secon = VAL(seco\$)
15.     IF oldminu <> minu THEN
16.         mi = mi + 1
17.         IF mi = 1 THEN GOSUB clock1:
18.         IF mi = 2 THEN GOSUB clock2:
19.         IF mi = 3 THEN GOSUB clock3:
20.         IF mi = 4 THEN GOSUB clock4:
21.         IF mi = 5 THEN GOSUB clock5:
22.         IF mi = 6 THEN GOSUB clock6:
23.         IF mi = 7 THEN GOSUB clock7:
24.         IF mi = 8 THEN GOSUB clock8:
25.         IF mi = 9 THEN GOSUB clock9:
26.         IF mi = 10 THEN GOSUB clock10:
27.         IF mi > 10 THEN mi = 1: GOSUB clock1:
28.     oldminu = minu
29.     'Seconds
30.     s = (60 - seconds) * 6 + 180
31.     x = INT(SIN(s / 180 * 3.141592) * 125) + 175
32.     y = INT(COS(s / 180 * 3.141592) * 125) + 175
33.     FOR b = -5 TO 5 STEP .1
34.         LINE (175 + b, 175)-(x, y), _RGB32(155, 83, 155)
35.         LINE (175, 175 + b)-(x, y), _RGB32(155, 83, 155)
36.     NEXT b
37.     'Minutes
38.     m = 180 - minutes * 6
39.     xx = INT(SIN(m / 180 * 3.141592) * 120) + 175
40.     yy = INT(COS(m / 180 * 3.141592) * 120) + 175
41.     FOR b = -5 TO 5 STEP .1
42.         LINE (175 + b, 175)-(xx, yy), _RGB32(0, 255, 255)
43.         LINE (175, 175 + b)-(xx, yy), _RGB32(0, 255, 255)
44.     NEXT b
45.     'Hours
46.     h = 360 - hours * 30 + 180
47.     xxx = INT(SIN(h / 180 * 3.141592) * 50) + 175
48.     yyy = INT(COS(h / 180 * 3.141592) * 50) + 175
49.     FOR b = -5 TO 5 STEP .1
50.         LINE (175 + b, 175)-(xxx, yyy), _RGB32(0, 255, 0)
51.         LINE (175, 175 + b)-(xxx, yyy), _RGB32(0, 255, 0)
52.     NEXT b
53.     FOR sz = .25 TO 5 STEP .25
54.         CIRCLE (175, 175), sz, _RGB32(0, 105, 255)
55.     NEXT sz
56.
57.     'Chimes
58.     IF minu = 0 AND secon = 0 THEN
59.         hour2 = hou
60.         IF hour2 > 12 THEN hour2 = hour2 - 12
61.         IF hour2 = 0 THEN hour2 = 12
62.         FOR chimes = 1 TO hour2
63.             ttt = 0
64.                 'queue some sound
65.                 DO WHILE _SNDRAWLEN < 0.1 'you may wish to adjust this
66.                     sample = SIN(ttt * 340 * ATN(1) * 8) '340Hz sine wave (ttt * 440 * 2p)
67.                     sample = sample * EXP(-ttt * 3) 'fade out eliminates clicks after sound
68.                     _SNDRAW sample
69.                     ttt = ttt + 1 / _SNDRATE 'sound card sample frequency determines time
70.                 'do other stuff, but it may interrupt sound
71.             LOOP WHILE ttt < 2 'play for 2 seconds
72.             DO WHILE _SNDRAWLEN > 0 'Finish any left over queued sound!
73.         NEXT chimes
74.     two:
75.     _PUTIMAGE (0, 0)-(350, 350), i
76.
77. clock1:
78. LINE (0, 0)-(350, 350), _RGB32(0, 0, 0), BF
79. FOR tt = 1 TO 1000
80.     s = 0
81.     a = a + .5
82.     IF a > 175 THEN a = 1
83.     b = INT(RND * 2) + 1
84.     IF b > 1 THEN c = 255
85.     IF b = 1 THEN c = 0
86.     FOR d = 0 TO a STEP .125
87.         c = c + 1
88.         IF c > 255 THEN c = 0
89.         s = s + 1
90.         x = COS(s * 3.141592 / 180) * d
91.         y = SIN(s * 3.151492 / 180) * d
92.         CIRCLE (x + 175, y + 175), 2, _RGB32(c, 0, 0)
93.     NEXT d
94. NEXT tt
95. a = 0
96. s = 0
97.
98. clock2:
99. c = 0
100. LINE (0, 0)-(350, 350), _RGB32(0, 0, 0), BF
101. FOR tt = 1 TO 1000
102.     s = 0
103.     a = a + .5
104.     IF a > 175 THEN a = 1
105.     b = INT(RND * 2) + 1
106.     IF b > 1 THEN c = 255
107.     IF b = 1 THEN c = 0
108.     FOR d = a TO 0 STEP -.125
109.         c = c + 1
110.         IF c > 255 THEN c = 0
111.         s = s + 1
112.         x = COS(s * 3.141592 / 180) * d
113.         y = SIN(s * 3.151492 / 180) * d
114.         CIRCLE (x + 175, y + 175), 2, _RGB32(0, c, 0)
115.     NEXT d
116. NEXT tt
117. c = 0
118. s = 0
119. a = 0
120.
121. clock3:
122. LINE (0, 0)-(350, 350), _RGB32(0, 0, 0), BF
123. FOR r = 1 TO 120 STEP 5
124.     one2:
125.     seco = seco + 1
126.     s = (60 - seco) * 6 + 180
127.     x = INT(SIN(s / 180 * 3.141592) * 175) + 175
128.     y = INT(COS(s / 180 * 3.141592) * 175) + 175
129.     CIRCLE (x, y), r, _RGB32(0, 0, r * 5)
130.     IF seco > 60 THEN
131.         seco = 0
132.         GOTO two2:
133.     GOTO one2:
134.     two2:
135. s = 0
136. seco = 0
137.
138. clock4:
139. LINE (0, 0)-(350, 350), _RGB32(0, 0, 0), BF
140. FOR rr = 0 TO 140 STEP 20
141.     c1 = INT(RND * 255)
142.     c2 = INT(RND * 255)
143.     c3 = INT(RND * 255)
144.     one3:
145.     seco = seco + 1
146.     s = (60 - seco) * 6 + (160 - rr)
147.     x = INT(SIN(s / 180 * 3.141592) * (160 - rr)) + 175
148.     y = INT(COS(s / 180 * 3.141592) * (160 - rr)) + 175
149.     CIRCLE (x, y), 2, _RGB32(c1, c2, c3)
150.     IF seco > 60 THEN
151.         seco = 0
152.         GOTO two3:
153.     GOTO one3:
154.     two3:
155. NEXT rr
156. seco = 0
157.
158. clock5:
159. LINE (0, 0)-(350, 350), _RGB32(0, 0, 0), BF
160. c1 = 0: c2 = 100: c3 = 100
161. FOR rr = 0 TO 140 STEP .1
162.     c2 = c2 + 1
163.     c3 = c3 + 1
164.     one4:
165.     seco = seco + 1
166.     s = (60 - seco) * 6 + (160 - rr)
167.     x = INT(SIN(s / 180 * 3.141592) * (160 - rr)) + 175
168.     y = INT(COS(s / 180 * 3.141592) * (160 - rr)) + 175
169.     CIRCLE (x, y), .25, _RGB32(c1, c2, c3)
170.     IF seco > 60 THEN
171.         seco = 0
172.         GOTO two4:
173.     GOTO one4:
174.     two4:
175. NEXT rr
176. seco = 0
177.
178. clock6:
179. LINE (0, 0)-(350, 350), _RGB32(0, 0, 0), BF
180. c1 = 100: c2 = 100: c3 = 0
181. FOR rr = 0 TO 140 STEP .1
182.     c2 = c2 + 1
183.     c3 = c3 + 1
184.     one5:
185.     seco = seco + 1
186.     s = (60 - seco) * 6 + 160
187.     x = INT(SIN(s / 180 * 3.141592) * (160 - rr)) + 175
188.     y = INT(COS(s / 180 * 3.141592) * (160 - rr)) + 175
189.     CIRCLE (x, y), .25, _RGB32(c1, c2, c3)
190.     IF seco > 60 THEN
191.         seco = 0
192.         GOTO two5:
193.     GOTO one5:
194.     two5:
195. NEXT rr
196. seco = 0
197.
198. clock7:
199. LINE (0, 0)-(350, 350), _RGB32(0, 0, 0), BF
200. c1 = 100: c2 = 100: c3 = 100
201. FOR rr = 0 TO 140 STEP .1
202.     c1 = c1 + 1
203.     c2 = c2 + 1
204.     c3 = c3 + 1
205.     one6:
206.     seco = seco + 1
207.     s = (60 - seco) * 6 + 160 + rr
208.     x = INT(SIN(s / 180 * 3.141592) * (160 + rr)) + 175
209.     y = INT(COS(s / 180 * 3.141592) * (160 + rr)) + 175
210.     CIRCLE (x, y), .25, _RGB32(c1, c2, c3)
211.     IF seco > 60 THEN
212.         seco = 0
213.         GOTO two6:
214.     GOTO one6:
215.     two6:
216. NEXT rr
217. seco = 0
218.
219. clock8:
220. LINE (0, 0)-(350, 350), _RGB32(0, 0, 0), BF
221. c1 = 100: c2 = 0: c3 = 0
222. FOR rr = -50 TO 50 STEP .25
223.     c1 = c1 + 1
224.     c2 = c2 + 1
225.     one7:
226.     seco = seco + .25
227.     s = (60 - seco) * 6 + 160
228.     x = INT(SIN(s / 90 * 3.141592) * 160) + 175
229.     y = INT(COS(s / 180 * 3.141592) * 160) + 175
230.     CIRCLE (x + rr, y), 2, _RGB32(c1, c2, c3)
231.     IF seco > 60 THEN
232.         seco = 0
233.         GOTO two7:
234.     GOTO one7:
235.     two7:
236. NEXT rr
237. seco = 0
238.
239. clock9:
240. LINE (0, 0)-(350, 350), _RGB32(0, 0, 0), BF
241. c1 = 0: c2 = 50: c3 = 50
242. FOR rr = 0 TO 160 STEP .05
243.     c2 = c2 + .05
244.     c3 = c3 + .05
245.     one8:
246.     seco = seco + .05
247.     s = (60 - seco) * 6 + 160 - rr
248.     x = INT(SIN(s / 180 * 3.141592) * (160 - rr)) + 175
249.     y = INT(COS(s / 180 * 3.141592) * (160 - rr)) + 175
250.     CIRCLE (x, y), .25, _RGB32(c1, c2, c3)
251.     IF seco > 60 THEN
252.         seco = 0
253.         GOTO two8:
254.     GOTO one8:
255.     two8:
256. NEXT rr
257. seco = 0
258.
259. clock10:
260. LINE (0, 0)-(350, 350), _RGB32(0, 0, 0), BF
261. one9:
262. seco = seco + .01
263. s = (60 - seco) * 6 + 180
264. x = INT(SIN(s / 360 * 3.141592) * 180) + 175
265. y = INT(COS(s / 1.57 * 3.141592) * 180) + 175
266. CIRCLE (x, y), 2, _RGB32(0, 255, 0)
267. IF seco > 60 THEN
268.     seco = 0
269.     GOTO two9:
270. GOTO one9:
271. two9:
272. seco = 0
273.

Here is the original clock with amazing graphics for the clock face that b+ made:

Code: QB64: [Select]
1. 'Clock by Ken G and b+. Also thank you to Petr from the QB64.org forum for smooth second hand movement.
2.
3. _TITLE "Clock by Ken G., b+, and Petr" 'b+ mod 2019-12-03
4. CONST xmax = 360, ymax = 368, xCenter = xmax / 2, yCenter = ymax / 2, p = 3.14159265, p2 = p * 2, pd2 = p / 2
5. DIM SHARED clockFace&
7. SCREEN _NEWIMAGE(360, 368, 32)
8. clockFace& = _NEWIMAGE(xmax, ymax, 32)
9. _DEST clockFace&
10. drawClockFace
11.     _LIMIT 30
12.     _PUTIMAGE , clockFace&, 0
13.
14.     hours = TIMER \ 3600
15.     minutes = TIMER \ 60 - hours * 60
16.     seconds = (TIMER - hours * 3600 - minutes * 60)
17.     ho\$ = LEFT\$(TIME\$, 2): hou = VAL(ho\$)
18.     min\$ = MID\$(TIME\$, 4, 2): minu = VAL(min\$)
19.     seco\$ = RIGHT\$(TIME\$, 2): secon = VAL(seco\$)
20.
21.     'Hours
22.     h = 360 - hours * 30 + 180
23.     xxx = INT(SIN(h / 180 * 3.141592) * 100) + 180
24.     yyy = INT(COS(h / 180 * 3.141592) * 100) + 184
25.     FOR b = -8 TO 8 STEP .1
26.         LINE (180 + b, 184)-(xxx, yyy), _RGB32(155, 0, 0)
27.         LINE (180, 184 + b)-(xxx, yyy), _RGB32(155, 0, 0)
28.     NEXT b
29.
30.     'Minutes
31.     m = 180 - minutes * 6
32.     xx = INT(SIN(m / 180 * 3.141592) * 150) + 180
33.     yy = INT(COS(m / 180 * 3.141592) * 150) + 184
34.     FOR b = -5 TO 5 STEP .1
35.         LINE (180 + b, 184)-(xx, yy), _RGB32(155, 80, 40)
36.         LINE (180, 184 + b)-(xx, yy), _RGB32(155, 80, 40)
37.     NEXT b
38.
39.     'Seconds
40.     s = (60 - seconds) * 6 + 180
41.     x = INT(SIN(s / 180 * 3.141592) * 165) + 180
42.     y = INT(COS(s / 180 * 3.141592) * 165) + 184
43.     'FOR b = -5 TO 5 STEP .1
44.     ' LINE (180 + b, 184)-(x, y), _RGB32(255, 164, 100)
45.     LINE (180, 184)-(x, y), _RGB32(255, 164, 84)
46.     'NEXT b
47.
48.     'fix clock arms with knob
49.     FOR rrr = 6 TO 0 STEP -.25
50.         CIRCLE (180, 184), rrr, _RGB32(1.5 * (255 - 25 * rrr), 1.5 * (128 - 17 * rrr), 1.5 * (64 - 8 * rrr))
51.
52.     'Chimes
53.     IF minu = 0 AND secon = 0 THEN
54.         hour2 = hou
55.         IF hour2 > 12 THEN hour2 = hour2 - 12
56.         IF hour2 = 0 THEN hour2 = 12
57.         FOR chimes = 1 TO hour2
58.             ttt = 0
59.                 'queue some sound
60.                 DO WHILE _SNDRAWLEN < 0.1 'you may wish to adjust this
61.                     sample = SIN(ttt * 340 * ATN(1) * 8) '340Hz sine wave (ttt * 440 * 2p)
62.                     sample = sample * EXP(-ttt * 3) 'fade out eliminates clicks after sound
63.                     _SNDRAW sample
64.                     ttt = ttt + 1 / _SNDRATE 'sound card sample frequency determines time
65.                 'do other stuff, but it may interrupt sound
66.             LOOP WHILE ttt < 2 'play for 2 seconds
67.             DO WHILE _SNDRAWLEN > 0 'Finish any left over queued sound!
68.         NEXT chimes
69.
70.     two:
71.
72. SUB drawClockFace
73.     DIM angle, r, n AS INTEGER, c AS _UNSIGNED LONG, x1, y1, x2, y2
74.     DIM level AS INTEGER, shade AS INTEGER, rr, gg, bb
75.     rr = 20: gg = 10: bb = 5
76.     angle = p2 / 12: r = yCenter * .95
77.     FOR level = 0 TO 2
78.         x1 = xCenter + COS(0 - pd2) * r: y1 = yCenter + SIN(0 - pd2) * r
79.         FOR n = 1 TO 12
80.             x2 = xCenter + COS(n * angle - pd2) * r: y2 = yCenter + SIN(n * angle - pd2) * r
81.             IF n > 6 THEN shade = n - 6 ELSE shade = 6 - n
82.             IF n = 12 THEN shade = 6
84.             c = _RGB32((level * 60) + rr + shade * 50, (level * 30) + gg + shade * 30, (level * 15) + bb + shade * 15)
85.             fillTriangle xCenter, yCenter, x1, y1, x2, y2, c
86.             x1 = x2: y1 = y2
87.         IF level = 0 THEN r = r - 15 ELSE r = r - 50
88.
89. SUB fillTriangle (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
90.     STATIC a&
91.     d = _DEST
92.     IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32)
93.     _DEST a&
94.     PSET (0, 0), K
95.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
96.
« Last Edit: December 07, 2019, 04:53:43 PM by SierraKen »

#### Pete ##### Re: My Best Clock
« Reply #31 on: December 06, 2019, 08:43:22 PM »
If your clock could talk, it might tell you, "It's not a fan." Well of course it's not, it's a clock! Of course if you speed up that second had 10- fold, well...

Kidding aside, I actually do like the other static designs better. Especially for telling time. I found myself checking my compute clock, to figure out if I was looking a 4:20 or 5:20. I did, however, like the red swirl pattern. That was also the easiest one to view and figure out the time. I could see that on an iWatch. Of course variety is the spice of life and having a setting menu, so the user could decide, classic face, favorite geometric face, AM / PM faces, or cycle through faces. Well, you can't lose there.

Pete