Author Topic: CLOCK.BAS  (Read 6027 times)

0 Members and 1 Guest are viewing this topic.

Offline Colonel_Panic

  • Newbie
  • Posts: 54
    • View Profile
CLOCK.BAS
« on: November 06, 2021, 10:57:25 pm »
CLOCK.BAS
---------------

my first program post on QB64... CLOCK.BAS

its, well... its yet another CLOCK program.
I wanted to "learn graphics" as I have always been a "business programmer".

NOTE:  I cut and pasted example HELP code, because the DRAW command impressed me with the TA thing.
           then I wasn't happy until I did "ghetto 360 degrees" fake-LED rotating numbers

apologies for the 'code style' which is "did not know I would eventually post it"

PS: screenshot... http://i.imgur.com/EkNLjfN.png


Code: QB64: [Select]
  1. maxx = 420
  2. maxy = 420
  3. x = INT(maxx / 2)
  4. y = INT(maxy / 2)
  5. SCREEN _NEWIMAGE(maxx, maxy, 32)
  6. _title "Clock"
  7. GOSUB draw_clock:
  8.  
  9. again:
  10. 'LOCATE 1, 1: PRINT "hours:";: LINE INPUT hour$: hour = VAL(hour$)
  11. 'LOCATE 1, 1: PRINT STRING$(64, " ")
  12. 'LOCATE 1, 1: PRINT "minutes:";: LINE INPUT minute$: minute = VAL(minute$)
  13.  
  14. z$ = TIME$
  15. GOSUB draw_digital: ': PRINT z$
  16. hour = VAL(LEFT$(z$, 2))
  17. IF hour > 12 THEN hour = hour - 12
  18. minute = VAL(MID$(z$, 4, 2))
  19. second = VAL(MID$(z$, 7, 2))
  20. 'IF second = 0 THEN _SCREENCLICK _SCREENX, _SCREENY
  21. GOSUB draw_clock:
  22. GOSUB draw_hands:
  23. loop1:
  24. IF TIME$ <> z$ THEN GOTO again: ELSE GOTO loop1:
  25.  
  26.  
  27. 'draw hands
  28. draw_hands:
  29. DRAW "TA0"
  30. 'hour hand (thicker little hand)
  31. 'IF hour = 0 THEN SYSTEM
  32. PSET (x, y), colr&
  33. DRAW "TA " + STR$((-30 * hour) + INT(minute / -2))
  34. DRAW "U15L1D15R2U15L1 L7U100R14D100L7 L6U99R12D98L12"
  35.  
  36. 'minute hand (thinner big hand)
  37. DRAW "TA0"
  38. PSET (x, y), colr&
  39. DRAW "TA " + STR$(-6 * minute)
  40. DRAW "U20L1D20R2U20L1 L5U120R10D120L5 L6U121R12D120L12"
  41.  
  42. 'second hand
  43. DRAW "TA0"
  44. PSET (x, y), colr&
  45. DRAW "TA " + STR$(-6 * second)
  46. DRAW "U145L1D145R2U145"
  47. 'try rotating seconds display
  48. DRAW "TA0"
  49. PSET (x, y), _RGB32(255, 0, 0) 'colr&
  50. DRAW "TA " + STR$(-6 * second)
  51. DRAW "bU183 bL15bU10"
  52. zecs$ = RIGHT$(STR$(100 + second), 2)
  53. zecs$ = LTRIM$(zecs$)
  54. zecs$ = RTRIM$(zecs$)
  55. ch$ = LEFT$(zecs$, 1): GOSUB draw_digit:
  56. DRAW "TA0"
  57. PSET (x, y), _RGB32(255, 0, 0) 'colr&
  58. DRAW "TA " + STR$(-6 * second)
  59. DRAW "bU183 bR5bU10"
  60. ch$ = RIGHT$(zecs$, 1): GOSUB draw_digit
  61.  
  62.  
  63. draw_clock:
  64. 'colr& = _RGB32(128, 128, 128)
  65. colr& = _RGB32(95, 95, 95)
  66. FOR csize = 150 TO 152
  67.   CIRCLE (x, y), csize, colr&
  68. NEXT csize
  69. FOR csize = 158 TO 160
  70.   CIRCLE (x, y), csize, colr&
  71. NEXT csize
  72. FOR csize = 197 TO 202
  73.   CIRCLE (x, y), csize, colr&
  74. NEXT csize
  75. CIRCLE (x, y), 7, colr&
  76. PAINT (x, y), colr&
  77. 'DRAW "U10D20U10R10L20"
  78. colr& = _RGB32(128, 128, 55)
  79. FOR Ang = 0 TO 360 STEP 6
  80.   PSET (x, y), colr&
  81.   DRAW "TA " + STR$(Ang) + "BU150" + "U10L1D10R2U10"
  82. NEXT Ang
  83.  
  84. colr& = _RGB32(128, 188, 61)
  85. FOR Ang = 0 TO 360 STEP 30
  86.   PSET (x, y), colr&
  87.   DRAW "TA " + STR$(Ang) + "BU150" + "U20L1D20R2U20L1" + "BU15"
  88.   FOR csize = 4 TO 5
  89.     CIRCLE STEP(0, 0), csize, colr&
  90.   NEXT csize
  91. NEXT Ang
  92.  
  93. FOR csize = 1 TO 3
  94.   CIRCLE (x, y), csize, _RGB32(0, 0, 0)
  95. NEXT csize
  96. 'face numbers
  97. COLOR _RGB32(6, 255, 255)
  98. _PRINTSTRING (x - 8, y - 140), "12"
  99. _PRINTSTRING (x + 62, y - 122), "1"
  100. _PRINTSTRING (x + 62, y + 106), "5"
  101. _PRINTSTRING (x - 70, y + 106), "7"
  102. _PRINTSTRING (x - 74, y - 122), "11"
  103. _PRINTSTRING (x + 112, y - 71), "2"
  104. _PRINTSTRING (x + 112, y + 62), "4"
  105. _PRINTSTRING (x - 120, y + 62), "8"
  106. _PRINTSTRING (x - 120, y - 71), "10"
  107. _PRINTSTRING (x - 4, y + 130), "6"
  108. _PRINTSTRING (x + 130, y - 8), "3"
  109. _PRINTSTRING (x - 138, y - 8), "9"
  110.  
  111.  
  112.  
  113. draw_digital:
  114. PSET (0, 0), _RGB32(255, 0, 0)
  115. DRAW "BR10BD10"
  116. ch$ = LEFT$(z$, 1): GOSUB draw_digit:
  117. PSET (0, 0), _RGB32(255, 0, 0)
  118. DRAW "BR30BD10"
  119. ch$ = MID$(z$, 2, 1): GOSUB draw_digit:
  120. PSET (0, 0), _RGB32(255, 0, 0)
  121. DRAW "BR50BD10"
  122. ch$ = MID$(z$, 4, 1): GOSUB draw_digit:
  123. PSET (0, 0), _RGB32(255, 0, 0)
  124. DRAW "BR70BD10"
  125. ch$ = MID$(z$, 5, 1): GOSUB draw_digit:
  126. PSET (0, 0), _RGB32(255, 0, 0)
  127. DRAW "BR340BD10"
  128. ch$ = MID$(z$, 7, 1): GOSUB draw_digit:
  129. PSET (0, 0), _RGB32(255, 0, 0)
  130. DRAW "BR360BD10"
  131. ch$ = RIGHT$(z$, 1): GOSUB draw_digit:
  132.  
  133.  
  134.  
  135. draw_digit:
  136. IF ch$ = "0" THEN DRAW "R10D10D10L10U10U10"
  137. IF ch$ = "1" THEN DRAW "BR10D10D10"
  138. IF ch$ = "2" THEN DRAW "R10D10L10D10R10"
  139. IF ch$ = "3" THEN DRAW "R10D10L10R10D10L10"
  140. IF ch$ = "4" THEN DRAW "D10R10U10D10D10"
  141. IF ch$ = "5" THEN DRAW "R10L10D10R10D10L10"
  142. IF ch$ = "6" THEN DRAW "R10L10D10D10R10U10L10"
  143. IF ch$ = "7" THEN DRAW "R10D10D10"
  144. IF ch$ = "8" THEN DRAW "R10D10L10U10D10D10R10U10"
  145. IF ch$ = "9" THEN DRAW "R10D10L10U10R10D20L10"
  146.  
  147.  
  148.  

Offline Colonel_Panic

  • Newbie
  • Posts: 54
    • View Profile
Re: CLOCK.BAS
« Reply #1 on: November 06, 2021, 11:05:51 pm »
I'm kind of 'anal' sometimes, and will over-do-it...

here, I wasn't happy until:

1) hour hand and minute hand was *not* going to satisfy me, I had to have a seconds hand
2) color? once i hit the "color picking" phase... I was going for one of those "old BIG BEN luminescent, real radium, old-timey clocks"
3) I had to get the mathematical angles of the hour hand "creeping" correct. (six degrees per minute, BTW)
4) Once i saw example DRAW stuff? and the TA thing? "rotating seconds LED"

PS - in screenshot? you can see, I can run as many CLOCKs as I like; I was always wanting to make one of those
"17 clocks like important businessmen in movies always have kind of clocks", with each clock in a 1-hour different time zone...

...you know, random city and countries printed on them? LMAO...

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: CLOCK.BAS
« Reply #2 on: November 06, 2021, 11:12:03 pm »
Hey I like what you did with the seconds, nice looking clock!
« Last Edit: November 06, 2021, 11:19:45 pm by bplus »

Offline Colonel_Panic

  • Newbie
  • Posts: 54
    • View Profile
Re: CLOCK.BAS
« Reply #3 on: November 06, 2021, 11:19:54 pm »
thanks guy.

PS - I always *did* wonder:

"now, WHY does the NAME come up on all but one of the CLOCKs I bring up, eh?"

then? one day? HELP manual, found on accident that's because I am not
"loop waiting until" the window is formed and reported back.
(I just learned in HELP to DO that a few days ago, only reason i know about it now)
if memory serves without checking, maybe it was the _SCREENEXISTS COMMAND?

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: CLOCK.BAS
« Reply #4 on: November 07, 2021, 05:01:33 am »
Such a cool looking clock! Nicely done!
Logic is the beginning of wisdom.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: CLOCK.BAS
« Reply #5 on: November 07, 2021, 04:10:31 pm »
Nice work, welcome to the forum, Colonel_Panic!

Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
Re: CLOCK.BAS
« Reply #6 on: November 08, 2021, 03:50:22 am »
Very nice clock !
Why not yes ?

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: CLOCK.BAS
« Reply #7 on: November 08, 2021, 06:09:00 pm »
Ran yours - always nice to see unique clocks.  Since you mentioned the airport type:
 
Code: QB64: [Select]
  1. _Title " World Clock"
  2. Dim p$(30), zo(30), t$(30) '                     place, zone, time
  3. Screen _NewImage(800, 600, 32)
  4. For i = 1 To 30: Read p$(i), zo(i): Next i
  5. d = 35 '                                         diameter of clocks
  6.     Cls: t$ = Time$
  7.     h = (Val(Mid$(t$, 1, 2)) + 7) Mod 24 '       GMT = my time + 7
  8.     m = Val(Mid$(t$, 4, 2))
  9.     For i = 1 To 30 '                            actual time for each place
  10.         th = h + Int(zo(i))
  11.         z! = Abs(zo(i)) - Abs(Int(zo(i)))
  12.         tm = m + z! * 60 * Sgn(zo(i))
  13.         If tm < Val("00") Then tm = tm + 60: th = th - 1
  14.         If tm > Val("59") Then tm = tm - 60: th = th + 1
  15.         th = (th + 24) Mod 24
  16.         th$ = Right$("0" + LTrim$(Str$(th)), 2)
  17.         tm$ = Right$("0" + LTrim$(Str$(tm)), 2)
  18.         t$(i) = th$ + tm$
  19.     Next i
  20.     p = 0 '                                      place index
  21.     For yi = 0 To 4
  22.         For xi = 0 To 5
  23.             xc = xi * _Width \ 6 + (_Width \ 6) * .5
  24.             yc = yi * _Height / 5.4 + 60
  25.             p = p + 1 '                          place index
  26.             _PrintString (xc - _PrintWidth(p$(p)) \ 2, yc + d + 4), p$(p)
  27.             Circle (xc, yc), d + 2, Green
  28.             If Val(Left$(t$(p), 2)) < 12 Then Paint (xc, yc), Green, Green ' am/pm
  29.             For a = 0 To 330 Step 30 '           clock tick marks
  30.                 x1 = xc + (d - 3) * Cos(_D2R(a))
  31.                 y1 = yc + (d - 3) * Sin(_D2R(a))
  32.                 Circle (x1, y1), 1, White '      ticks
  33.             Next a
  34.             th = Val(Mid$(t$(p), 1, 2)) '        hour
  35.             tm = Val(Mid$(t$(p), 3, 2)) '        minute
  36.             ra = _D2R(tm * 6 - 90) '             minute hand
  37.             x(0) = xc + (d - 8) * Cos(ra)
  38.             y(0) = yc + (d - 8) * Sin(ra)
  39.             ra = _D2R((th + tm / 60) * 30 - 90) 'hour hand
  40.             x(1) = xc + (d - 16) * Cos(ra)
  41.             y(1) = yc + (d - 16) * Sin(ra)
  42.             For zz = 0 To 1 '                    draw hands
  43.                 For zx = -1 To 1
  44.                     For zy = -1 To 1
  45.                         Line (xc + zx, yc + zy)-(x(zz), y(zz)), White
  46.                     Next zy
  47.                 Next zx
  48.             Next zz
  49.         Next xi
  50.     Next yi
  51.     Do: _Limit 10 '                              wait for new minute
  52.         x = 20 + Val(Right$(Time$, 2)) / 60 * (_Width - 40)
  53.         Line (20, _Height - 20)-(x, _Height - 21), Green, B
  54.         _Display
  55.         If Len(InKey$) Then System '             any key exits
  56.     Loop Until Left$(t$, 5) <> Left$(Time$, 5)
  57.  
  58. Data Amsterdam,1
  59. Data Beijing,8
  60. Data Berlin,1
  61. Data Brasilia,-3
  62. Data Cairo,2
  63. Data Chicago,-6
  64. Data Delhi,5.5
  65. Data Denver,-7
  66. Data Detroit,-5
  67. Data Edmonton,-7
  68. Data Gander,-3.5
  69. Data Hawaii,-10
  70. Data Hong Kong,8
  71. Data Houston,-6
  72. Data Istanbul,2
  73. Data London,0
  74. Data Los Angeles,-9
  75. Data Madrid,1
  76. Data Mexico City,-6
  77. Data Moscow,3
  78. Data New York,-5
  79. Data Paris,1
  80. Data Perth,8
  81. Data Phoenix,-8
  82. Data Rome,1
  83. Data Seoul,9
  84. Data Singapore,8
  85. Data Sydney,10
  86. Data Tehran,3.5
  87. Data Tokyo,9
  88.  
It works better if you plug it in.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: CLOCK.BAS
« Reply #8 on: November 08, 2021, 06:24:56 pm »
Nice look clock, @Colonel_Panic!  And welcome to the forum. 

Nice looking clocks too, @Richard Frost.

- Dav

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: CLOCK.BAS
« Reply #9 on: November 08, 2021, 07:18:05 pm »
Hi boys and girls
Welcome to Colonel_Panic

This is a pleasure that you coder of QB64 have done something with my half name

here your screenshot
 
Clock and Clocks.PNG


Waiting other your applications...
Programming isn't difficult, only it's  consuming time and coffee

Offline Colonel_Panic

  • Newbie
  • Posts: 54
    • View Profile
Re: CLOCK.BAS
« Reply #10 on: December 25, 2021, 12:36:47 pm »
to everyone: thanks for the warm welcome.
@frost: YES... you have the "airport clocks".

very attractive "airport clocks".

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: CLOCK.BAS
« Reply #11 on: December 25, 2021, 03:04:56 pm »
@Colonel_Panic My clock says it Christmas what are you doing here ;-))

Offline Colonel_Panic

  • Newbie
  • Posts: 54
    • View Profile
Re: CLOCK.BAS
« Reply #12 on: December 25, 2021, 04:28:04 pm »
@Colonel_Panic My clock says it Christmas what are you doing here ;-))

Its Christmas, I can do ANYTHING I WANT to do, right?

---I dont really "drink" drink...
---and I use my laptop the way most people use their PHONES, so...
---I dont want to go date some tinder roastie anyways

what more fun could i be having? I cant picture it.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: CLOCK.BAS
« Reply #13 on: December 25, 2021, 09:00:53 pm »
Ya! Merry Christmas!