QB64.org Forum

Active Forums => Programs => Topic started by: SierraKen on December 01, 2019, 09:12:41 pm

Title: My Best Clock
Post by: SierraKen on December 01, 2019, 09:12:41 pm
For the first time I decided to use a .bmp picture as a background to a program I make. So I made this clock face using an old CAD program I have called Breeze Designer. Then I used the code from a clock I put on this forum a few months ago, which is also on my website. Here is the .zip file of the .bas and .bmp files needed and a picture of it I will add to the forum. It gongs on the top of every hour like my other one does (without using any extra sound files).  Hope you guys like it.

-Ken
Title: Re: My Best Clock
Post by: SierraKen on December 02, 2019, 01:34:06 pm
And (of course) I made it even better! lol Just now I figured out how to make the clock hands look more real instead of just 1 LINE command.
Here is the updated version. Check out the picture too. I'm sure you all can make something like this already, but I like it. Please tell me what you think.


Title: Re: My Best Clock
Post by: bplus on December 02, 2019, 02:04:04 pm
Looks nice.
Title: Re: My Best Clock
Post by: SierraKen on December 02, 2019, 04:29:24 pm
Thanks bplus! I like small projects like this that are easy to figure out.
Title: Re: My Best Clock
Post by: bplus on December 02, 2019, 07:43:58 pm
Ken, We can make that clock face with QB64, interested?
Title: Re: My Best Clock
Post by: SierraKen on December 02, 2019, 07:47:43 pm
Sure!!! I guess we could with PAINT and a bunch of math that I have no idea of.  lol But if you want to help with that, go at it!
Title: Re: My Best Clock
Post by: bplus on December 02, 2019, 08:25:26 pm
This is faster and more accurate than PAINT for filling a triangle with a color:
Code: QB64: [Select]
  1. SUB fillTriangle (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  2.     STATIC a&
  3.     D = _DEST
  4.     IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32)
  5.      _DEST a&
  6.     PSET (0, 0), K
  7.     _DEST D
  8.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)

Feed it 3 points locations (x, y) and a _RGB32() color and a filled triangle magically appears!

So you can use that for your clock hands for practice.

OK so far?

Here comes a simple lesson about angles:

If the minute hand is pointing at angle a degrees, then it's opposite is a - 180 degrees or a + 180 degrees same difference.

Say we want nice iso triangle for the hands, the angle of one point is a - 120 degrees and the angle of the other point is a + 120 degrees.
 
If we want the 2 points at base of iso triagnle r distance away from the clock center, then the points are

xPlus120 = xCenter + r * COS(_D2R(a + 120))
yPlus120 = yCenter + r * SIN(_D2R(a + 120))

xMinus120 = xCenter + r * COS(_D2R(a - 120))
yMinus120 = yCenter + r * SIN(_D2R(a - 120))

xMinuteHand = xCenter + MinuteHandLength * COS(_D2R(a))
yMinuteHand = yCenter + MinuteHandLength * SIN(_D2R(a))

and there is your 3 points for a triangle to fill.

a is the angle of the minute hand in degrees.
r is the distance from center of clock you want to put the base of the iso Triangle, the ends of the clock hands.
_D2R is a function that converts an angle in Degrees to an angle in Radians so that SIN and COS work correctly.

BTW you are converting degrees to radians using these things:
(degreeAngle / 180 * 3.141592) = same as _D2R function, maybe better because they are all constants, so feel free to change the _D2R(degreeAngle) to (degreeAngle / 180 * 3.141592).

See if you get clock hands improved? I don't know if you know what you are doing for minute hand angles though??? If you do get that, all the above is piece of cake. :)

With this practice of clock hands, the clock face will be easier to follow.

Title: Re: My Best Clock
Post by: SierraKen on December 02, 2019, 08:42:41 pm
Oh wow bplus, so all of that was just for the hands? That's a lot more bits than my 2 loops. To be honest, I really don't remember from school what COS and SIN do. I was never good in Trig.  I appreciate the lesson but with my head injury and memory problems, I doubt I could jump into it that fast. This is another reason why I have been very slow in gaining much higher in my programming than what I know how to do now. I might look into this sometime soon, but I have a lot on my plate for the next couple of days. So I'll look more into this in a couple days or so and see what I can come up with. I'll put it all on a Notepad.
Title: Re: My Best Clock
Post by: bplus on December 02, 2019, 08:53:42 pm
Don't let SIN and COS throw you. All they do here is help locate points around a center, like the clock given the angle use the formula for X and Y and up comes your locations is all.

The tricky thing about the clock is that you want your 0 angle due North instead of due East, so you subtract 90 degrees from every angle, for hour, minute and second. Did you know you were doing that? :)
Title: Re: My Best Clock
Post by: bplus on December 03, 2019, 10:23:18 pm
Hi Ken,

Here is clock face as promised so you no longer need to zip with image file, a few other changes also...
Code: QB64: [Select]
  1. _TITLE "Clock by Ken G. and b+" 'b+ mod 2019-12-03
  2. CONST xmax = 360, ymax = 368, xCenter = xmax / 2, yCenter = ymax / 2, p = 3.14159265, p2 = p * 2, pd2 = p / 2
  3. DIM SHARED clockFace&
  4. 'i = _LOADIMAGE("kclock.bmp", 32)
  5. SCREEN _NEWIMAGE(360, 368, 32)
  6. clockFace& = _NEWIMAGE(xmax, ymax, 32)
  7. _DEST clockFace&
  8. drawClockFace
  9.     CLS
  10.     _PUTIMAGE , clockFace&, 0
  11.  
  12.     hours = TIMER \ 3600
  13.     minutes = TIMER \ 60 - hours * 60
  14.     seconds = (TIMER - hours * 3600 - minutes * 60)
  15.     ho$ = LEFT$(TIME$, 2): hou = VAL(ho$)
  16.     min$ = MID$(TIME$, 4, 2): minu = VAL(min$)
  17.     seco$ = RIGHT$(TIME$, 2): secon = VAL(seco$)
  18.  
  19.     'Hours
  20.     h = 360 - hours * 30 + 180
  21.     xxx = INT(SIN(h / 180 * 3.141592) * 100) + 180
  22.     yyy = INT(COS(h / 180 * 3.141592) * 100) + 184
  23.     FOR b = -8 TO 8 STEP .1
  24.         LINE (180 + b, 184)-(xxx, yyy), _RGB32(155, 0, 0)
  25.         LINE (180, 184 + b)-(xxx, yyy), _RGB32(155, 0, 0)
  26.     NEXT b
  27.  
  28.     'Minutes
  29.     m = 180 - minutes * 6
  30.     xx = INT(SIN(m / 180 * 3.141592) * 150) + 180
  31.     yy = INT(COS(m / 180 * 3.141592) * 150) + 184
  32.     FOR b = -5 TO 5 STEP .1
  33.         LINE (180 + b, 184)-(xx, yy), _RGB32(155, 80, 40)
  34.         LINE (180, 184 + b)-(xx, yy), _RGB32(155, 80, 40)
  35.     NEXT b
  36.  
  37.     'Seconds
  38.     s = (60 - seconds) * 6 + 180
  39.     x = INT(SIN(s / 180 * 3.141592) * 165) + 180
  40.     y = INT(COS(s / 180 * 3.141592) * 165) + 184
  41.     'FOR b = -5 TO 5 STEP .1
  42.     ' LINE (180 + b, 184)-(x, y), _RGB32(255, 164, 100)
  43.     LINE (180, 184)-(x, y), _RGB32(255, 164, 84)
  44.     'NEXT b
  45.  
  46.     'fix clock arms with knob
  47.     FOR rrr = 6 TO 0 STEP -.25
  48.         CIRCLE (180, 184), rrr, _RGB32(1.5 * (255 - 25 * rrr), 1.5 * (128 - 17 * rrr), 1.5 * (64 - 8 * rrr))
  49.     NEXT
  50.  
  51.     'Chimes
  52.     IF minu = 0 AND secon = 0 THEN
  53.         hour2 = hou
  54.         IF hour2 > 12 THEN hour2 = hour2 - 12
  55.         IF hour2 = 0 THEN hour2 = 12
  56.         FOR chimes = 1 TO hour2
  57.             ttt = 0
  58.             DO
  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.                 LOOP
  66.                 'do other stuff, but it may interrupt sound
  67.             LOOP WHILE ttt < 2 'play for 2 seconds
  68.             DO WHILE _SNDRAWLEN > 0 'Finish any left over queued sound!
  69.             LOOP
  70.         NEXT chimes
  71.     END IF
  72.     _DELAY 1
  73.  
  74.     two:
  75.     _DISPLAY
  76.  
  77. SUB drawClockFace
  78.     DIM angle, r, n AS INTEGER, c AS _UNSIGNED LONG, x1, y1, x2, y2
  79.     DIM level AS INTEGER, shade AS INTEGER, rr, gg, bb
  80.     rr = 20: gg = 10: bb = 5
  81.     CLS
  82.     angle = p2 / 12: r = yCenter * .95
  83.     FOR level = 0 TO 2
  84.         x1 = xCenter + COS(0 - pd2) * r: y1 = yCenter + SIN(0 - pd2) * r
  85.         FOR n = 1 TO 12
  86.             x2 = xCenter + COS(n * angle - pd2) * r: y2 = yCenter + SIN(n * angle - pd2) * r
  87.             IF n > 6 THEN shade = n - 6 ELSE shade = 6 - n
  88.             IF n = 12 THEN shade = 6
  89.             IF level = 1 THEN shade = 6 - shade
  90.             c = _RGB32((level * 60) + rr + shade * 50, (level * 30) + gg + shade * 30, (level * 15) + bb + shade * 15)
  91.             fillTriangle xCenter, yCenter, x1, y1, x2, y2, c
  92.             x1 = x2: y1 = y2
  93.         NEXT
  94.         IF level = 0 THEN r = r - 15 ELSE r = r - 50
  95.     NEXT
  96.  
  97. SUB fillTriangle (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  98.     DIM d AS LONG
  99.     STATIC a&
  100.     d = _DEST
  101.     IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32)
  102.     _DEST a&
  103.     PSET (0, 0), K
  104.     _DEST d
  105.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  106.  
  107.  


Title: Re: My Best Clock
Post by: bplus on December 04, 2019, 10:26:41 am
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!. :)
Title: Re: My Best Clock
Post by: Pete on December 04, 2019, 12:25:59 pm
Did you guys change the contrast between the inner and outer clock housing? The image originally posted appeared to have a brighter inner housing, which frankly made me think it was an umbrella clock. It's raining here today, so I was afraid to run it, in fear of getting wet when I checked the time... but when I ran the updated version, it had more of a concave appearance than the photo posted, which makes it look more the the type of clock I'm used to seeing with that similar design. Am I right, or are my eyes just playing tricks on me? I'm no artist, but I believe there is something about having the object appear with a darker contrast towards the center will make the object appear recessed or concave. In any event, nice project guys.

Pete
Title: Re: My Best Clock
Post by: bplus on December 04, 2019, 12:52:48 pm
Hi Pete,

If you are asking if I changed the fake 3D face coloring then yes, yes I did:
 


Reversing the middle layer shading.
Title: Re: My Best Clock
Post by: Pete on December 04, 2019, 12:57:27 pm
Yep, that's what I was inquiring about. Thanks. Now I can call the pharmacy and cancel my anti-hallucinogenic prescription. Darn, just when they started making them in gummies, too.

Pete
Title: Re: My Best Clock
Post by: SMcNeill on December 04, 2019, 01:02:25 pm
Pete thought it looked like an umbrella before; now I think it looks like my doggy’s water bowl.  LOL!
Title: Re: My Best Clock
Post by: bplus 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. :-))
Title: Re: My Best Clock
Post by: Pete 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!
Title: Re: My Best Clock
Post by: SierraKen 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.
Title: Re: My Best Clock
Post by: SierraKen 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!. :)
Title: Re: My Best Clock
Post by: bplus 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. 


 
Title: Re: My Best Clock
Post by: SierraKen 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.
Title: Re: My Best Clock
Post by: Petr 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.  
Title: Re: My Best Clock
Post by: SierraKen 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.  
Title: Re: My Best Clock
Post by: Pete 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
Title: Re: My Best Clock
Post by: SierraKen 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.
Title: Re: My Best Clock
Post by: bplus 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.  
Title: Re: My Best Clock
Post by: SierraKen 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.
Title: Re: My Best Clock
Post by: SierraKen 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.  
Title: Re: My Best Clock
Post by: SierraKen 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.
Title: Re: My Best Clock
Post by: bplus on December 06, 2019, 07:08:43 pm
Hey nice idea!
Title: Re: My Best Clock
Post by: SierraKen 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.  
Title: Re: My Best Clock
Post by: Pete 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