Author Topic: Mantel Clock Mini  (Read 3118 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Mantel Clock Mini
« on: January 02, 2021, 03:35:28 pm »
This is pretty much the same as my regular Mantel Clock, except I cut the size of it all in half. It uses a 400 x 300 window so you can keep it running and watch it while doing other work on your computer. I also had to decrease the font size of the Roman Numerals. I cut everything in half down to the widths of the hands. I'll probably use this one a lot more than my original one. That is why I made a new topic for it, so nobody passes it up. It also uses the new way of the hour hand moving between hours as the minutes go, as I just added to the original one a couple days ago. Plus of course it does the same chiming song of the famous Westminster Quarters song that Dav helped me with. Thanks again Dav! I also kept the ability to hear it at any time using the Space Bar. I hope you all get this one because I'm sure you will want to use it more often than the large one. Oh, I also had to move a couple of the hours over so they wouldn't go over the white circles.

Code: QB64: [Select]
  1. 'Mantel Clock Mini by SierraKen with help for Westminster Quarters hourly song by Dav on the QB64.org forum.
  2. 'Created on 1-2-2020
  3. 'This is made from my regular Mantel Clock.
  4. 'I made this so you can keep it running and away from your other computer work.
  5. SCREEN _NEWIMAGE(400, 300, 32)
  6. _TITLE "Mantel Clock Mini - Space Bar plays chimes."
  7.     _LIMIT 50
  8.     a = _KEYHIT
  9.     IF a = 27 THEN END
  10.     IF a = 32 THEN song = 1: a = 0: _DELAY 1
  11.     CX = 200: CY = 150: R = 150: C = _RGB32(0, 78, 0)
  12.     fillCircle CX, CY, R, C
  13.     LINE (50, 150)-(350, 300), C, BF
  14.     CX = 200: CY = 150: R = 100: C = _RGB32(183, 139, 100)
  15.     fillCircle CX, CY, R, C
  16.     FOR lines = .25 TO 5 STEP .1
  17.         CIRCLE (200, 150), 125 + lines, _RGB32(0, 55, 0), 2 * _PI, _PI
  18.     NEXT lines
  19.     LINE (70, 150)-(75, 380), _RGB32(0, 55, 0), BF
  20.     LINE (325, 150)-(330, 380), _RGB32(0, 55, 0), BF
  21.  
  22.     FOR sc = 1 TO 60
  23.         ss = (60 - sc) * 6 + 180
  24.         x2 = INT(SIN(ss / 180 * 3.141592) * 70) + 200
  25.         y2 = INT(COS(ss / 180 * 3.141592) * 70) + 150
  26.         CIRCLE (x2, y2), 1, _RGB32(230, 230, 230)
  27.         n2 = (60 - sc) * 6 + 180
  28.         x3 = INT(SIN(n2 / 180 * 3.141592) * 80) + 195
  29.         y3 = INT(COS(n2 / 180 * 3.141592) * 80) + 147.5
  30.         COLOR _RGB32(0, 0, 0), _RGB32(183, 139, 100)
  31.         IF sc = 5 THEN _PRINTSTRING (x3, y3), "I"
  32.         IF sc = 10 THEN _PRINTSTRING (x3, y3), "II"
  33.         IF sc = 15 THEN _PRINTSTRING (x3, y3), "III"
  34.         IF sc = 20 THEN _PRINTSTRING (x3, y3), "IV"
  35.         IF sc = 25 THEN _PRINTSTRING (x3, y3), "V"
  36.         IF sc = 30 THEN _PRINTSTRING (x3, y3), "VI"
  37.         IF sc = 35 THEN _PRINTSTRING (x3, y3), "VII"
  38.         IF sc = 40 THEN _PRINTSTRING (x3 - 14, y3), "VIII"
  39.         IF sc = 45 THEN _PRINTSTRING (x3 - 2, y3), "IX"
  40.         IF sc = 50 THEN _PRINTSTRING (x3, y3), "X"
  41.         IF sc = 55 THEN _PRINTSTRING (x3, y3), "XI"
  42.         IF sc = 60 THEN _PRINTSTRING (x3 - 4, y3), "XII"
  43.     NEXT sc
  44.     COLOR , _RGB32(0, 0, 0)
  45.     clock song
  46.     CX = 200: CY = 150: R = 5: C = _RGB32(0, 0, 0)
  47.     fillCircle CX, CY, R, C
  48.     _DISPLAY
  49.     CLS
  50.  
  51. 'from Steve Gold standard
  52. SUB fillCircle (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  53.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  54.     DIM X AS INTEGER, Y AS INTEGER
  55.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  56.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  57.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  58.     WHILE X > Y
  59.         RadiusError = RadiusError + Y * 2 + 1
  60.         IF RadiusError >= 0 THEN
  61.             IF X <> Y + 1 THEN
  62.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  63.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  64.             END IF
  65.             X = X - 1
  66.             RadiusError = RadiusError - X * 2
  67.         END IF
  68.         Y = Y + 1
  69.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  70.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  71.     WEND
  72.  
  73. SUB clock (song)
  74.     hours = (TIMER \ 3600)
  75.     minutes = TIMER \ 60 - hours * 60
  76.     seconds = (TIMER - hours * 3600 - minutes * 60)
  77.     hours = hours + (minutes / 60) 'Code added to make hour hand move between numbers.
  78.     ho$ = LEFT$(TIME$, 2): hou = VAL(ho$)
  79.     min$ = MID$(TIME$, 4, 2): minu = VAL(min$)
  80.     seco$ = RIGHT$(TIME$, 2): secon = VAL(seco$)
  81.  
  82.     'Seconds
  83.     s = (60 - seconds) * 6 + 180
  84.     x = INT(SIN(s / 180 * 3.141592) * 60) + 200
  85.     y = INT(COS(s / 180 * 3.141592) * 60) + 150
  86.     FOR b = -2.5 TO 2.5 STEP .1
  87.         LINE (200 + b, 150)-(x, y), _RGB32(255, 255, 128)
  88.         LINE (200, 150 + b)-(x, y), _RGB32(255, 255, 128)
  89.     NEXT b
  90.     'Minutes
  91.     m = 180 - minutes * 6
  92.     xx = INT(SIN(m / 180 * 3.141592) * 60) + 200
  93.     yy = INT(COS(m / 180 * 3.141592) * 60) + 150
  94.     FOR b = -2.5 TO 2.5 STEP .1
  95.         LINE (200 + b, 150)-(xx, yy), _RGB32(0, 0, 0)
  96.         LINE (200, 150 + b)-(xx, yy), _RGB32(0, 0, 0)
  97.     NEXT b
  98.     'Hours
  99.     h = 360 - hours * 30 + 180
  100.     xxx = INT(SIN(h / 180 * 3.141592) * 45) + 200
  101.     yyy = INT(COS(h / 180 * 3.141592) * 45) + 150
  102.     FOR b = -2.5 TO 2.5 STEP .1
  103.         LINE (200 + b, 150)-(xxx, yyy), _RGB32(0, 0, 0)
  104.         LINE (200, 150 + b)-(xxx, yyy), _RGB32(0, 0, 0)
  105.     NEXT b
  106.     'Chimes
  107.     IF (minu = 0 AND secon = 0) OR song = 1 THEN
  108.         song = 0
  109.  
  110.         'note frequencies
  111.         FOR notes = 1 TO 20
  112.             IF notes = 1 THEN note = 311.13 'D#
  113.             IF notes = 2 THEN note = 246.94 'B
  114.             IF notes = 3 THEN note = 277.18 'C#
  115.             IF notes = 4 THEN note = 185.00 'F#
  116.             IF notes = 5 THEN note = 0
  117.             IF notes = 6 THEN note = 185.00 'F#
  118.             IF notes = 7 THEN note = 277.18 'C#
  119.             IF notes = 8 THEN note = 311.13 'D#
  120.             IF notes = 9 THEN note = 246.94 'B
  121.             IF notes = 10 THEN note = 0
  122.             IF notes = 11 THEN note = 311.13 'D#
  123.             IF notes = 12 THEN note = 277.18 'C3
  124.             IF notes = 13 THEN note = 246.94 'B
  125.             IF notes = 14 THEN note = 185.00 'F#
  126.             IF notes = 15 THEN note = 0
  127.             IF notes = 16 THEN note = 185.00 'F#
  128.             IF notes = 17 THEN note = 277.18 'C#
  129.             IF notes = 18 THEN note = 311.13 'D#
  130.             IF notes = 19 THEN note = 246.94 'B
  131.             IF notes = 20 THEN note = 0
  132.  
  133.             DO
  134.                 'queue some sound
  135.                 DO WHILE _SNDRAWLEN < 0.5 'you may wish to adjust this
  136.                     sample = SIN(ttt * note * ATN(1) * 8) '340Hz sine wave (ttt * 440 * 2p)
  137.                     sample = sample * EXP(-ttt * 3) 'fade out eliminates clicks after sound
  138.                     _SNDRAW sample
  139.                     ttt = ttt + 1 / _SNDRATE 'sound card sample frequency determines time
  140.                 LOOP
  141.                 'do other stuff, but it may interrupt sound
  142.             LOOP WHILE ttt < 1 'play for 1 second
  143.             DO WHILE _SNDRAWLEN > 0 'Finish any left over queued sound!
  144.             LOOP
  145.             ttt = 0
  146.         NEXT notes
  147.         hour2 = hou
  148.         IF hour2 > 12 THEN hour2 = hour2 - 12
  149.         IF hour2 = 0 THEN hour2 = 12
  150.         FOR chimes = 1 TO hour2
  151.             ttt = 0
  152.             DO
  153.                 'queue some sound
  154.                 DO WHILE _SNDRAWLEN < 0.1 'you may wish to adjust this
  155.                     sample = SIN(ttt * 240 * ATN(1) * 8) '340Hz sine wave (ttt * 440 * 2p)
  156.                     sample = sample * EXP(-ttt * 3) 'fade out eliminates clicks after sound
  157.                     _SNDRAW sample
  158.                     ttt = ttt + 1 / _SNDRATE 'sound card sample frequency determines time
  159.                 LOOP
  160.                 'do other stuff, but it may interrupt sound
  161.             LOOP WHILE ttt < 2 'play for 2 seconds
  162.             DO WHILE _SNDRAWLEN > 0 'Finish any left over queued sound!
  163.             LOOP
  164.         NEXT chimes
  165.     END IF
  166.     two:
  167.  

« Last Edit: January 02, 2021, 03:36:53 pm by SierraKen »