Author Topic: My Best Clock  (Read 7915 times)

0 Members and 1 Guest are viewing this topic.

Marked as best answer by SierraKen on December 06, 2019, 03:17:50 pm

Offline SierraKen

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

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

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/