Author Topic: Clock (next one from hunderd...)  (Read 3783 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Clock (next one from hunderd...)
« on: December 31, 2021, 02:09:46 pm »
This is how a child comes in and says: Daddy, what do you want to paint? And can you make it move? So I say - paint hands and numbers....

Here is the result, this time with an external file. I didn't fix anything, even though some of the numbers were rotated, I left it as it was.

Happy New Year!

Code: QB64: [Select]
  1. Title "Kids clock"
  2. Dim Shared nrs(14) As Long
  3. 'DataCreate "hrsml.txt", "h00h.gif"
  4. LoadSubImages
  5. Screen NewImage(1024, 768, 32)
  6. Cls , RGB32(133)
  7. CX = 500: CY = 350: A = -_Pi / 2 + _Pi(2) / 12
  8. Circle (535, 419), 340, _RGB32(200)
  9. Paint (535, 419), _RGB32(250), _RGB32(200)
  10. For t = 0 To 11
  11.     Xv = CX + Cos(A) * 250
  12.     Yv = CY + Sin(A) * 250
  13.     A = A + _Pi(2) / 12
  14.     PutImage (Xv, Yv), nrs(t)
  15.  
  16. PCopy Display, 1
  17.     k& = KeyDown(27)
  18.     PCopy 1, Display
  19.     Mode = 1
  20.     Select Case Mode '                                   mode: 0 for standard STEPs mode, 1 for smooth steps.
  21.         Case 0
  22.             Hrs = Int(Timer / 3600)
  23.             If Hrs > 12 Then Hrs = Hrs - 12
  24.             Min = Int((Timer / 3600 - Hrs) * 60)
  25.             Secs = Int(Timer - (Hrs * 3600 + Min * 60))
  26.         Case 1
  27.             Hrs = Timer / 3600
  28.             Min = (Hrs - (Int(Timer / 3600))) * 60
  29.             Secs = Timer - (Int(Hrs) * 3600 + Int(Min) * 60)
  30.     End Select
  31.  
  32.     For HrsSel = 1 To 3
  33.         Select Case HrsSel
  34.             Case 1 'hours
  35.                 Asecs = _Pi(2) / 12 * Hrs - _Pi / 2
  36.                 iW = 45: iH = 144: Handle = 13: L1 = 170
  37.  
  38.             Case 2 'minutes
  39.                 Asecs = _Pi(2) / 60 * Min - _Pi / 2
  40.                 iW = 54: iH = 145: Handle = 14: L1 = 222
  41.  
  42.             Case 3 'seconds
  43.                 Asecs = _Pi(2) / 60 * Secs - _Pi / 2
  44.                 iW = 61: iH = 143: Handle = 12: L1 = 200
  45.         End Select
  46.  
  47.         X1 = 535 + Cos(Asecs - .09) * L1
  48.         X2 = 535 + Cos(Asecs + .09) * L1
  49.         Y1 = 419 + Sin(Asecs - .09) * L1
  50.         Y2 = 419 + Sin(Asecs + .09) * L1
  51.  
  52.         X3 = 535 + Cos(Asecs - .6) * -20
  53.         X4 = 535 + Cos(Asecs + .6) * -20
  54.         Y3 = 419 + Sin(Asecs - .6) * -20
  55.         Y4 = 419 + Sin(Asecs + .6) * -20
  56.  
  57.         MapTriangle (0, 0)-(iW, iH)-(0, iH), nrs(Handle) To(X1, Y1)-(X3, Y3)-(X4, Y4)
  58.         MapTriangle (iW, 0)-(0, 0)-(iW, iH), nrs(Handle) To(X2, Y2)-(X1, Y1)-(X3, Y3)
  59.     Next HrsSel
  60.     Display
  61.     Limit 20
  62.  
  63. Sub DataCreate (OutputFile As String, InputFile As String) 'this sub is not need for run, but is used between developing this program. This sub create DATA values for us.
  64.     img = LoadImage(InputFile$, 32)
  65.     img2 = CopyImage(img, 32)
  66.  
  67.     ff = FreeFile
  68.     Open OutputFile$ For Output As #ff
  69.     Screen img
  70.     Do Until k&
  71.         k& = KeyDown(27)
  72.         While _MouseInput: Wend
  73.         MX = MouseX: MY = MouseY
  74.         MB1 = MouseButton(1)
  75.         MB2 = MouseButton(2)
  76.         If MB1 Then
  77.             Do Until MB1 = 0
  78.                 PutImage , img2
  79.                 Line (MX, MY)-(MouseX, MouseY), &HFF000000, B
  80.                 While MouseInput: Wend
  81.                 MB1 = MouseButton(1)
  82.                 Limit 15
  83.             Loop
  84.             wMX = MX: wMY = MY: wMx2 = _MouseX: wMy2 = _MouseY
  85.         End If
  86.         If MB2 Then
  87.             If wMx2 Then
  88.                 r$ = Str$(wMX) + ", " + Str$(wMY) + ", " + Str$(wMx2) + ", " + Str$(wMy2)
  89.                 Print #ff, r$
  90.                 wMx2 = 0
  91.             End If
  92.         End If
  93.     Loop
  94.  
  95. Sub LoadSubImages
  96.     img = LoadImage("H00H.gif", 32)
  97.     For lsi = 0 To 14
  98.         Read x1, y1, x2, y2, i
  99.         wdth = x2 - x1: hght = y2 - y1
  100.         nrs(i) = _NewImage(wdth, hght, 32)
  101.         PutImage , img, nrs(i), (x1, y1)-(x2, y2)
  102.         SetAlpha 0, _RGB32(255) To _RGB32(200), nrs(i)
  103.     Next
  104.     FreeImage img
  105.  
  106.     Data 0,4,62,148,12
  107.     Data 69,5,115,150,13
  108.     Data 118,7,172,153,14
  109.     Data 182,9,226,140,8
  110.     Data 226,10,310,134,9
  111.     Data 320,10,430,144,10
  112.     Data 435,11,522,132,11
  113.     Data 1,177,59,270,0
  114.     Data 64,171,130,260,1
  115.     Data 143,170,204,267,2
  116.     Data 211,168,280,269,3
  117.     Data 282,168,330,265,4
  118.     Data 332,167,401,272,5
  119.     Data 402,156,469,274,6
  120.     Data 474,157,518,265,7
  121.  

H00H.gif
* H00H.gif (Filesize: 33.64 KB, Dimensions: 528x276, Views: 215)

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Clock (next one from hunderd...)
« Reply #1 on: January 01, 2022, 02:35:43 am »
Mighty cute.  Is it waterproof?
It works better if you plug it in.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Clock (next one from hunderd...)
« Reply #2 on: January 01, 2022, 07:50:47 am »
They are Waterproof Once. :) Like everything. The drawing is done with markers. Have Nice New Year!



:)


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Clock (next one from hunderd...)
« Reply #3 on: January 01, 2022, 11:02:11 am »
Well I can imagine what it is supposed to look like but this forum won't let me save the image correctly, you need to attach the file I think:

Here is what I see:
 
kids clock.PNG

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Clock (next one from hunderd...)
« Reply #4 on: January 01, 2022, 11:31:57 am »
Oh another dah! moment, just click the picture! (I tried a Save Image from right click on it).

Here we go!
 
image_2022-01-01_113152.png