Author Topic: My Best Clock  (Read 9329 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: My Best Clock
« Reply #15 on: December 04, 2019, 03:32:47 pm »
Quote
Pete thought it looked like an umbrella before; now I think it looks like my doggy’s water bowl.  LOL!

Let me know how it does with water. :-))
« Last Edit: December 04, 2019, 03:37:31 pm by bplus »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: My Best Clock
« Reply #16 on: December 04, 2019, 03:50:03 pm »
Let me know how it does with water. :-))

You want what? A watered down version? Sorry. You need FreeBASIC for that!
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: My Best Clock
« Reply #17 on: December 04, 2019, 04:00:29 pm »
Dang that's genius bplus! Amazing job you did there. I'll put this one on my website instead. It's apps like this that make me wish I could put the .exe online without Windows having a fit saying I am an unknown programmer with their security stuff. There's a way around that but it sure scares people downloading. So for now the code will go as a .txt file on my website and that will be good enough. I think Microsoft charges programmers a lot of money to be "known". Although I'm not sure if the $19 fee for Windows Store apps would apply to that or not. Anyways, thanks again B+.  Oh and if I ever do put the .exe online, I won't charge a penny for it so no worries.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: My Best Clock
« Reply #18 on: December 04, 2019, 04:34:15 pm »
LOL I was confused over this code B+, until you say at the bottom that it's part of your own project you are working on. lol

PS I was a little bit off with the arm ends near center of the clock, this code:
Code: QB64: [Select]
  1. xPlus120 = xCenter + r * COS(_D2R(a + 120))
  2. yPlus120 = yCenter + r * SIN(_D2R(a + 120))
  3.  
  4. xMinus120 = xCenter + r * COS(_D2R(a - 120))
  5. yMinus120 = yCenter + r * SIN(_D2R(a - 120))
  6.  
Draws the base of the iso Triangle on the same side of clock center as the pointed end. I intended to put the points of the base iso triangle on the other side of the clock center than the arm point, to do that, r had to be negative (equivalent to subtracting PI, I think):
Code: QB64: [Select]
  1. xPlus120 = xCenter - r * COS(_D2R(a + 120))
  2. yPlus120 = yCenter - r * SIN(_D2R(a + 120))
  3.  
  4. xMinus120 = xCenter - r * COS(_D2R(a - 120))
  5. yMinus120 = yCenter - r * SIN(_D2R(a - 120))
  6.  
Also I did the angles in radians, = in terms of PI, since this is mostly gobblely-gook to Ken :)
Oh wait, the arms code is all Ken's except my mod of seconds hand back to a line, still Ken's numbers... I redrew my own alarm clock with this clockface and my own arms code, testing what I said above. Still need to install the lovely chimes Ken has going here!. :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: My Best Clock
« Reply #19 on: December 04, 2019, 07:29:46 pm »
Re: About the iso triangle base for the arms

Man! I had it right the first time with the +r, dang it!
Code: QB64: [Select]
  1. xPlus120 = xCenter + r * COS(_D2R(a + 120))
  2. yPlus120 = yCenter + r * SIN(_D2R(a + 120))
  3.  
  4. xMinus120 = xCenter + r * COS(_D2R(a - 120))
  5. yMinus120 = yCenter + r * SIN(_D2R(a - 120))
Is correct as written.

I was rereading Ken's last post and redid the geometry, -r doesn't make sense!

It was pure luck that it worked (in my other program the -r) because I was working in radians NOT degrees and I needed to convert the 120 degrees to 2*Pi/3 Radians which I hadn't, although strangely -r does work with 120 degrees unconverted to radians??? another life miracle :)

@Ken
About that 19$ for something from MS, doesn't sound like you know what you are getting, I sure don't.
As for strangers running your exe's, I would advise posting source code and links to downloading QB64 so your audience can do these exe's for themselves AND with QB64 working on different platforms, you potentially have a wider base with source bas code than with exe's. I know Linux people are much more Do-It-Yourselfers than MS users, generally speaking. 


 

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: My Best Clock
« Reply #20 on: December 04, 2019, 07:40:33 pm »
Thanks bplus. Well I only partly know about the $19 in that it lets programmers put stuff in the Windows Store. The things I don't know about is what kind of things they accept and what containers to use, and of course if it requires even more money to verify me as a known programmer. So, I'm not going to do it anytime soon. And I can't just put a .zip of an .exe on my website because of the warnings Windows gives. Windows even gives a warning for a .bas file that's zipped up and from the Internet. But that isn't as bad. That is why I try to put almost all my programs as .txt files for people to copy/paste to their QB64 language. The reason I brought all of this up is because I have a lot of friends and family that I would love to share my creations with. But since they don't know anything about programming and don't want to, all I can do is make photos and videos of them. But that's OK, it's just my hobby and I'm fine with that. Plus I got this forum. :). 
Oh and one more thing about websites, it costs a lot of money to be a verified website with its files as well. Some websites cost in the $100's every few years just to keep it secure and known by Microsoft. So I can't do that on mine. How I miss the 90's... :) But on the other hand, I understand their reasoning with so many hackers out there these days.
« Last Edit: December 04, 2019, 07:46:21 pm by SierraKen »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: My Best Clock
« Reply #21 on: December 05, 2019, 05:04:20 pm »
Solution for smooth movement seconds:

Code: QB64: [Select]
  1.  
  2.  
  3. SCREEN _NEWIMAGE(800, 600, 32)
  4. CX = 400
  5. CY = 300
  6. R = 150
  7.  
  8.     GETTIME Hours, minutes, seconds, miliseconds
  9.     IF Hours > 12 THEN Hours = Hours - 12
  10.     IF seconds = 0 THEN seconds = 60
  11.     Hx = CX + COS(-_PI / 2 + _PI(2) / 12 * Hours) * R * .85
  12.     Hy = CY + SIN(-_PI / 2 + _PI(2) / 12 * Hours) * R * .85
  13.     Mx = CX + COS(-_PI / 2 + _PI(2) / 60 * minutes) * R * .8
  14.     My = CY + SIN(-_PI / 2 + _PI(2) / 60 * minutes) * R * .8
  15.     Sx = CX + COS(-_PI / 2 + _PI(2) / 60 * (miliseconds / 100 + seconds)) * R * .8
  16.     Sy = CY + SIN(-_PI / 2 + _PI(2) / 60 * (miliseconds / 100 + seconds)) * R * .8
  17.  
  18.     CLS
  19.     CIRCLE (CX, CY), R
  20.     stp = 0
  21.     FOR D = 0 TO _PI(2) STEP _PI(2) / 60
  22.         IF stp MOD 5 = 0 THEN dd = 10 ELSE dd = 5
  23.         Dx = CX + COS(-_PI / 2 + D) * R
  24.         Dy = CY + SIN(-_PI / 2 + D) * R
  25.         Dx2 = CX + COS(-_PI / 2 + D) * (R - dd)
  26.         Dy2 = CY + SIN(-_PI / 2 + D) * (R - dd)
  27.         LINE (Dx, Dy)-(Dx2, Dy2)
  28.         stp = stp + 1
  29.     NEXT
  30.  
  31.  
  32.     LINE (CX, CY)-(Hx, Hy)
  33.     LINE (CX, CY)-(Mx, My), &HFFFFFF00
  34.     LINE (CX, CY)-(Sx, Sy), &HFFFF0000
  35.  
  36.     _DISPLAY
  37.     _LIMIT 30
  38.  
  39. SUB GETTIME (Hodina, Minuta, Sekunda, Setina)
  40.     hodnota = TIMER
  41.     IF hodnota < 60 THEN hodin = 0: minut = 0: sekund = hodnota: GOTO a1
  42.     IF hodnota > 60 AND hodnota < 3600 THEN hodin = 0: minut = hodnota / 60: GOTO a2
  43.     Hodina = hodnota / 3600
  44.     hodin$ = STR$(Hodina)
  45.     tecka = INSTR(0, hodin$, ".")
  46.     Minuta = (VAL("0." + RIGHT$(hodin$, LEN(hodin$) - tecka)) * 0.6) * 100
  47.     a2:
  48.     minut$ = STR$(Minuta)
  49.     tecka = INSTR(0, STR$(Minuta), ".")
  50.     sekund = (VAL("0." + RIGHT$(minut$, LEN(minut$) - tecka)) * 0.6) * 100
  51.     a1:
  52.     sekund$ = STR$(sekund)
  53.     tecka = INSTR(0, sekund$, ".")
  54.     Setina = (VAL("0." + RIGHT$(sekund$, LEN(sekund$) - tecka)) * 1) * 100
  55.  
  56.     Minuta = INT(Minuta)
  57.     Sekunda = INT(sekund)
  58.     IF Sekunda = 60 THEN Sekunda = 0
  59.  

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: My Best Clock
« Reply #22 on: December 05, 2019, 06:40:08 pm »
Thanks Petr! All I needed from your code there was _LIMIT 30. But how did you figure out how to use 30? I also removed the _DELAY command so now the second hand is smooth and doesn't move every second, instead it always moves.
I hope you guys like this.. B+ what do you think? I'll put it on my website soon after a couple more tests. So far I've only tested it for 2 minutes.

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. SCREEN _NEWIMAGE(360, 368, 32)
  7. clockFace& = _NEWIMAGE(xmax, ymax, 32)
  8. _DEST clockFace&
  9. drawClockFace
  10.     _LIMIT 30
  11.     CLS
  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.     NEXT
  52.  
  53.     'Chimes
  54.     IF minu = 0 AND secon = 0 THEN
  55.         hour2 = hou
  56.         IF hour2 > 12 THEN hour2 = hour2 - 12
  57.         IF hour2 = 0 THEN hour2 = 12
  58.         FOR chimes = 1 TO hour2
  59.             ttt = 0
  60.             DO
  61.                 'queue some sound
  62.                 DO WHILE _SNDRAWLEN < 0.1 'you may wish to adjust this
  63.                     sample = SIN(ttt * 340 * ATN(1) * 8) '340Hz sine wave (ttt * 440 * 2p)
  64.                     sample = sample * EXP(-ttt * 3) 'fade out eliminates clicks after sound
  65.                     _SNDRAW sample
  66.                     ttt = ttt + 1 / _SNDRATE 'sound card sample frequency determines time
  67.                 LOOP
  68.                 'do other stuff, but it may interrupt sound
  69.             LOOP WHILE ttt < 2 'play for 2 seconds
  70.             DO WHILE _SNDRAWLEN > 0 'Finish any left over queued sound!
  71.             LOOP
  72.         NEXT chimes
  73.     END IF
  74.  
  75.     two:
  76.     _DISPLAY
  77.  
  78. SUB drawClockFace
  79.     DIM angle, r, n AS INTEGER, c AS _UNSIGNED LONG, x1, y1, x2, y2
  80.     DIM level AS INTEGER, shade AS INTEGER, rr, gg, bb
  81.     rr = 20: gg = 10: bb = 5
  82.     CLS
  83.     angle = p2 / 12: r = yCenter * .95
  84.     FOR level = 0 TO 2
  85.         x1 = xCenter + COS(0 - pd2) * r: y1 = yCenter + SIN(0 - pd2) * r
  86.         FOR n = 1 TO 12
  87.             x2 = xCenter + COS(n * angle - pd2) * r: y2 = yCenter + SIN(n * angle - pd2) * r
  88.             IF n > 6 THEN shade = n - 6 ELSE shade = 6 - n
  89.             IF n = 12 THEN shade = 6
  90.             IF level = 1 THEN shade = 6 - shade
  91.             c = _RGB32((level * 60) + rr + shade * 50, (level * 30) + gg + shade * 30, (level * 15) + bb + shade * 15)
  92.             fillTriangle xCenter, yCenter, x1, y1, x2, y2, c
  93.             x1 = x2: y1 = y2
  94.         NEXT
  95.         IF level = 0 THEN r = r - 15 ELSE r = r - 50
  96.     NEXT
  97.  
  98. SUB fillTriangle (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  99.     DIM d AS LONG
  100.     STATIC a&
  101.     d = _DEST
  102.     IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32)
  103.     _DEST a&
  104.     PSET (0, 0), K
  105.     _DEST d
  106.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  107.  
« Last Edit: December 05, 2019, 06:57:04 pm by SierraKen »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: My Best Clock
« Reply #23 on: December 05, 2019, 07:53:53 pm »
Now all it needs is a nightlight effect to tell if it's AM or PM... and dog repellent, in case Steve downloads it.

Hey, I gave it a try and saved it to my file archives. It has a lot of great components in a nice compact coding format. Hooray! A horse a committee put together, instead of a three-humped camel.

Pete ^^^:D
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: My Best Clock
« Reply #24 on: December 05, 2019, 10:15:22 pm »
LOL Pete. I like how this clock runs in the background and gongs at me when the hour is up. So I don't even have to look at a clock if I don't want to.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: My Best Clock
« Reply #25 on: December 05, 2019, 11:18:08 pm »
Quote
B+ what do you think?

Hi Ken, Fine if you like it, great. :)

Me, I am never satisfied, I'm up to this now for alarm clock that chimes the hour thanks to your clock!
Code: QB64: [Select]
  1. OPTION _EXPLICIT 'B+ 2019-11-03   Alarm clock with Hour Chimes
  2. 'variation on alarm clock 2019-06-22
  3. 'designed for xmax = ymax = 320 but anything bigger should be OK
  4. '2019-12-05 changed face again, changed arms by adding a trangle opposite point end
  5. 'improved Alarm input screen and installed Ken's chimes to indicate the hour
  6.  
  7. CONST xmax = 500, ymax = 500, xCenter = xmax / 2, yCenter = ymax / 2, p = 3.14159265, p2 = p * 2, pd2 = p / 2
  8. TYPE armType
  9.     a AS SINGLE 'radian angle
  10.     l AS SINGLE ' length
  11.     iso AS SINGLE 'iso tri base, now for radius arm width perpedicular to point direction
  12.     c AS _UNSIGNED LONG 'color
  13. DIM SHARED clockFace&, alarm$
  14.  
  15. SCREEN _NEWIMAGE(xmax, ymax, 32)
  16. _SCREENMOVE (_DESKTOPWIDTH - xmax) / 2, (_DESKTOPHEIGHT - ymax) / 2
  17.  
  18. DIM t$, h, m, s, chimes, sample, ttt
  19.  
  20. COLOR &HFF00DDDD
  21. clockFace& = _NEWIMAGE(xmax, ymax, 32)
  22. _DEST clockFace&
  23. drawClockFace
  24.  
  25.     outputClock
  26.     'Chimes
  27.     t$ = TIME$
  28.     h = VAL(MID$(t$, 1, 2))
  29.     m = VAL(MID$(t$, 4, 2))
  30.     s = VAL(MID$(t$, 7, 2))
  31.     IF m = 0 AND s < 1 THEN
  32.         IF h > 12 THEN h = h - 12
  33.         IF h = 0 THEN h = 12
  34.         FOR chimes = 1 TO h
  35.             ttt = 0
  36.             DO
  37.                 'queue some sound
  38.                 DO WHILE _SNDRAWLEN < 0.1 'you may wish to adjust this
  39.                     sample = SIN(ttt * 340 * ATN(1) * 8) '340Hz sine wave (ttt * 440 * 2p)
  40.                     sample = sample * EXP(-ttt * 3) 'fade out eliminates clicks after sound
  41.                     _SNDRAW sample
  42.                     ttt = ttt + 1 / _SNDRATE 'sound card sample frequency determines time
  43.                 LOOP
  44.                 'do other stuff, but it may interrupt sound
  45.             LOOP WHILE ttt < 2 'play for 2 seconds
  46.             DO WHILE _SNDRAWLEN > 0 'Finish any left over queued sound!
  47.             LOOP
  48.         NEXT chimes
  49.     END IF
  50.     IF UCASE$(INKEY$) = "A" THEN setAlarm
  51.     _DISPLAY
  52.     _LIMIT 60
  53.  
  54. SUB outputClock
  55.     IF alarm$ = "" THEN _TITLE "<a> to Set Alarm Clock" ELSE _TITLE "Alarm Clock is Set"
  56.     _PUTIMAGE , clockFace&, 0
  57.     drawArms
  58.     _PRINTSTRING (6, ymax - 21), TIME$
  59.     IF alarm$ <> "" THEN
  60.         _PRINTSTRING (xmax - 53, ymax - 21), "@" + alarm$
  61.         IF MID$(TIME$, 1, 5) = alarm$ THEN
  62.             _TITLE "Press any to stop beeping..."
  63.             BEEP
  64.         END IF
  65.         IF LEN(INKEY$) THEN alarm$ = ""
  66.     END IF
  67.  
  68. SUB drawClockFace
  69.     DIM angle, r, n AS INTEGER, c AS _UNSIGNED LONG, x1, y1, x2, y2
  70.     DIM level AS INTEGER, shade AS INTEGER, rr, gg, bb
  71.     rr = 10: gg = 5: bb = 2
  72.     CLS
  73.     angle = p2 / 60: r = yCenter * .95
  74.     FOR level = 0 TO 10
  75.         x1 = xCenter + COS(0 - pd2) * r: y1 = yCenter + SIN(0 - pd2) * r
  76.         FOR n = 1 TO 60
  77.             x2 = xCenter + COS(n * angle - pd2) * r: y2 = yCenter + SIN(n * angle - pd2) * r
  78.             IF n > 30 THEN shade = n - 30 ELSE shade = 30 - n
  79.             IF n = 60 THEN shade = 30
  80.             IF level = 1 THEN shade = 30 - shade
  81.             c = _RGB32(((level * 1.5) + rr + shade * 10), ((level * .75) + gg + shade * 5), ((level * .4) + bb + shade * 2.5))
  82.             fillTriangle xCenter, yCenter, x1, y1, x2, y2, c
  83.             x1 = x2: y1 = y2
  84.         NEXT
  85.         IF level = 0 THEN r = r - .1 * yCenter ELSE r = r - .02 * yCenter
  86.     NEXT
  87.  
  88. SUB drawArms
  89.     DIM xPlus90, yPlus90, xMinus90, yMinus90, xop, yop, xPoint, yPoint, t AS DOUBLE, i AS INTEGER, rr, c AS _UNSIGNED LONG
  90.     DIM arms(1 TO 3) AS armType
  91.     arms(1).c = &HFF222211: arms(2).c = &HFF331111: arms(3).c = &HFF663322
  92.     arms(1).l = yCenter * .6: arms(2).l = yCenter * .8: arms(3).l = yCenter * .84
  93.     arms(1).iso = yCenter * .065: arms(2).iso = yCenter * .05: arms(3).iso = yCenter * .04 ' don't use in arm 3
  94.     t = TIMER
  95.     'the follwing angles are in radians with pd2 = Pi/2 subtracted
  96.     arms(1).a = (t / 3600) / 12 * p2 - pd2
  97.     arms(2).a = (t / 60 - 60 * INT(arms(1).a)) / 60 * p2 - pd2
  98.     arms(3).a = (t - INT(arms(1).a) * 3600 - INT(arms(2).a) * 60) / 60 * p2 - pd2
  99.     FOR i = 1 TO 3
  100.         xPlus90 = xCenter + arms(i).iso * COS(arms(i).a + pd2)
  101.         yPlus90 = yCenter + arms(i).iso * SIN(arms(i).a + pd2)
  102.  
  103.         xMinus90 = xCenter + arms(i).iso * COS(arms(i).a - pd2)
  104.         yMinus90 = yCenter + arms(i).iso * SIN(arms(i).a - pd2)
  105.  
  106.         xPoint = xCenter + arms(i).l * COS(arms(i).a)
  107.         yPoint = yCenter + arms(i).l * SIN(arms(i).a)
  108.  
  109.         xop = xCenter + 3 * arms(i).iso * COS(arms(i).a - p)
  110.         yop = yCenter + 3 * arms(i).iso * SIN(arms(i).a - p)
  111.  
  112.         IF i < 3 THEN
  113.             fillTriangle xPlus90, yPlus90, xMinus90, yMinus90, xPoint, yPoint, arms(i).c
  114.             fillTriangle xPlus90, yPlus90, xMinus90, yMinus90, xop, yop, arms(i).c
  115.         ELSEIF i = 3 THEN 'line works better here
  116.             LINE (xop, yop)-(xPoint, yPoint), arms(i).c
  117.         END IF
  118.     NEXT
  119.     FOR rr = 5 TO 1 STEP -1
  120.         IF rr MOD 2 THEN c = &HFF663322 ELSE c = &HFF000000
  121.         CIRCLE (xCenter, yCenter), rr, c
  122.     NEXT
  123.  
  124. SUB fillTriangle (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  125.     DIM d AS LONG
  126.     STATIC a&
  127.     d = _DEST
  128.     IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32)
  129.     _DEST a&
  130.     PSET (0, 0), K
  131.     _DEST d
  132.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  133.  
  134. SUB setAlarm
  135.     DIM s$
  136.     s$ = "For time: hh = 00-23 : mm = 00-59"
  137.     CLS
  138.     _PRINTSTRING ((_WIDTH - 8 * LEN(s$)) / 2, _HEIGHT / 2 - 10), s$
  139.     _DISPLAY
  140.     s$ = "Enter hh:mm "
  141.     inputG 8 * (_WIDTH / 8 - LEN(s$) - 8) / 2, _HEIGHT / 2 + 10, s$, alarm$, 8
  142.  
  143. 'INPUT for Graphics screen
  144. SUB inputG (x, y, prmpt$, var$, expectedLenVar%) 'input for a graphics screen x, y is where the prompt will start , returns through var$
  145.     DIM tmp$, k$, saveAD
  146.     saveAD = _AUTODISPLAY
  147.     _KEYCLEAR
  148.     _PRINTSTRING (x, y), prmpt$ + " {}"
  149.     IF saveAD <> -1 THEN _DISPLAY
  150.     DO
  151.         k$ = INKEY$
  152.         IF LEN(k$) = 1 THEN
  153.             SELECT CASE ASC(k$)
  154.                 CASE 13: var$ = tmp$: EXIT SUB
  155.                 CASE 27: var$ = "": EXIT SUB
  156.                 CASE 8 'backspace
  157.                     IF LEN(tmp$) THEN
  158.                         IF LEN(tmp$) = 1 THEN tmp$ = "" ELSE tmp$ = LEFT$(tmp$, LEN(tmp$) - 1)
  159.                     END IF
  160.                 CASE ELSE: IF ASC(k$) > 31 THEN tmp$ = tmp$ + k$
  161.             END SELECT
  162.             _PRINTSTRING (x, y), prmpt$ + " {" + tmp$ + "}" + SPACE$(expectedLenVar% - LEN(tmp$)) 'spaces needed at end to clear backspace chars
  163.             IF saveAD <> -1 THEN _DISPLAY
  164.         END IF
  165.     LOOP
  166.  
  167.  
Clock current update.PNG
* Clock current update.PNG (Filesize: 40.87 KB, Dimensions: 502x528, Views: 173)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: My Best Clock
« Reply #26 on: December 06, 2019, 12:42:12 am »
That's one of the most amazing clocks I've ever seen on any computer B+. That's better than the stuff on Microsoft's Windows Store, seriously. LOL now I want to experiment more with the clock face. :) I might make a few clocks.
« Last Edit: December 06, 2019, 12:43:52 am by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: My Best Clock
« Reply #27 on: December 06, 2019, 01:25:27 am »
Here's a template for anyone to use of just clock hands with no clock face background. I'm thinking of making one where the user can press the space bar to change to a few different kinds of backgrounds within the same app. But here is the template I will use. I adjusted the center-point to be in the exact center and added a tiny blue pin in the middle. Feel free to change the colors and sizes of course. I also shrank the hour hand to half the size and am using a non-stop second hand. This also includes the gong sounds on top of every hour.

Code: QB64: [Select]
  1. 'Use this template however you see fit. This was made by Ken G. with help from the QB64.org forum.
  2. _TITLE "Clock Hands"
  3. SCREEN _NEWIMAGE(350, 350, 32)
  4. i = _NEWIMAGE(350, 350, 32)
  5. ' ----------------------------------------
  6. ' Draw clock here and use  _DEST i and _DEST 0
  7. '_DEST i
  8.  
  9.  
  10.  
  11. '_DEST 0
  12. '-----------------------------------------
  13.  
  14.     _LIMIT 30
  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.     'Seconds
  22.     s = (60 - seconds) * 6 + 180
  23.     x = INT(SIN(s / 180 * 3.141592) * 125) + 175
  24.     y = INT(COS(s / 180 * 3.141592) * 125) + 175
  25.     FOR b = -5 TO 5 STEP .1
  26.         LINE (175 + b, 175)-(x, y), _RGB32(155, 83, 155)
  27.         LINE (175, 175 + b)-(x, y), _RGB32(155, 83, 155)
  28.     NEXT b
  29.     'Minutes
  30.     m = 180 - minutes * 6
  31.     xx = INT(SIN(m / 180 * 3.141592) * 120) + 175
  32.     yy = INT(COS(m / 180 * 3.141592) * 120) + 175
  33.     FOR b = -5 TO 5 STEP .1
  34.         LINE (175 + b, 175)-(xx, yy), _RGB32(0, 255, 255)
  35.         LINE (175, 175 + b)-(xx, yy), _RGB32(0, 255, 255)
  36.     NEXT b
  37.     'Hours
  38.     h = 360 - hours * 30 + 180
  39.     xxx = INT(SIN(h / 180 * 3.141592) * 50) + 175
  40.     yyy = INT(COS(h / 180 * 3.141592) * 50) + 175
  41.     FOR b = -5 TO 5 STEP .1
  42.         LINE (175 + b, 175)-(xxx, yyy), _RGB32(0, 255, 0)
  43.         LINE (175, 175 + b)-(xxx, yyy), _RGB32(0, 255, 0)
  44.     NEXT b
  45.     FOR sz = .25 TO 5 STEP .25
  46.         CIRCLE (175, 175), sz, _RGB32(0, 105, 255)
  47.     NEXT sz
  48.  
  49.     'Chimes
  50.     IF minu = 0 AND secon = 0 THEN
  51.         hour2 = hou
  52.         IF hour2 > 12 THEN hour2 = hour2 - 12
  53.         IF hour2 = 0 THEN hour2 = 12
  54.         FOR chimes = 1 TO hour2
  55.             ttt = 0
  56.             DO
  57.                 'queue some sound
  58.                 DO WHILE _SNDRAWLEN < 0.1 'you may wish to adjust this
  59.                     sample = SIN(ttt * 340 * ATN(1) * 8) '340Hz sine wave (ttt * 440 * 2p)
  60.                     sample = sample * EXP(-ttt * 3) 'fade out eliminates clicks after sound
  61.                     _SNDRAW sample
  62.                     ttt = ttt + 1 / _SNDRATE 'sound card sample frequency determines time
  63.                 LOOP
  64.                 'do other stuff, but it may interrupt sound
  65.             LOOP WHILE ttt < 2 'play for 2 seconds
  66.             DO WHILE _SNDRAWLEN > 0 'Finish any left over queued sound!
  67.             LOOP
  68.         NEXT chimes
  69.     END IF
  70.     two:
  71.     _DISPLAY
  72.     CLS
  73.     _PUTIMAGE (0, 0), i
  74.  
« Last Edit: December 06, 2019, 01:52:48 am by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: My Best Clock
« Reply #28 on: December 06, 2019, 05:54:52 pm »
I decided to make 10 clocks in 1 if I can. Every minute it will change to a different clock face. I got 4 done so far. :) Might take a few days but when I'm done I'll post it here. It's coming out really cool, can't wait until I show it.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: My Best Clock
« Reply #29 on: December 06, 2019, 07:08:43 pm »
Hey nice idea!