Author Topic: Optical Illusion Clock  (Read 3633 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Optical Illusion Clock
« on: January 22, 2022, 07:38:43 pm »
I used old code I had from my older analog clocks and added another hand to it which is 1/60 of a second and changed the colors. I also added an optical illusion design that also has a bit of moving color. The clock gongs the hour every hour too. The _Limit command is at 400 so the fast hand will have a smoother animation. Tell me what you think.

Code: QB64: [Select]
  1. _Title "Optical Illusion Clock"
  2. Screen _NewImage(350, 350, 32)
  3. i = _NewImage(350, 350, 32)
  4. ' ----------------------------------------
  5. ' Draw clock here and use  _DEST i and _DEST 0
  6. Circle (175, 175), 170, _RGB32(255, 255, 255)
  7.  
  8. For ls = 1 To 60
  9.     ss = (60 - ls) * 6 + 180
  10.     x = Int(Sin(ss / 180 * 3.141592) * 75) + 175
  11.     y = Int(Cos(ss / 180 * 3.141592) * 75) + 175
  12.     Line (x, y)-(x * 1.5, y * 1.5), _RGB32(255, 255, 255)
  13. Next ls
  14.  
  15. '-----------------------------------------
  16.  
  17.  
  18.     _Limit 400
  19.     hours = Timer \ 3600
  20.     minutes = Timer \ 60 - hours * 60
  21.     seconds = (Timer - hours * 3600 - minutes * 60)
  22.     qseconds = (seconds * 60)
  23.     ho$ = Left$(Time$, 2): hou = Val(ho$)
  24.     min$ = Mid$(Time$, 4, 2): minu = Val(min$)
  25.     seco$ = Right$(Time$, 2): secon = Val(seco$)
  26.     '1/60 of a second.
  27.     qs = (60 - qseconds) * 6 + 180
  28.     x = Int(Sin(qs / 180 * 3.141592) * 125) + 175
  29.     y = Int(Cos(qs / 180 * 3.141592) * 125) + 175
  30.     For b = -5 To 5 Step .5
  31.         Line (175 + b, 175)-(x, y), _RGB32(255, 255, 255)
  32.         Line (175, 175 + b)-(x, y), _RGB32(255, 255, 255)
  33.     Next b
  34.     x2 = Int(Sin(qs / 180 * 3.141592) * 170) + 175
  35.     y2 = Int(Cos(qs / 180 * 3.141592) * 170) + 175
  36.     For sz = .1 To 5 Step .1
  37.         Circle (x2, y2), sz, _RGB32(255, 255, 255)
  38.     Next sz
  39.     x2 = Int(Sin(qs / 180 * 3.141592) * 75) + 175
  40.     y2 = Int(Cos(qs / 180 * 3.141592) * 75) + 175
  41.     Line (x2, y2)-(x2 * 1.5, y2 * 1.5), _RGB32(127, 255, 127)
  42.     'Seconds
  43.     s = (60 - seconds) * 6 + 180
  44.     x = Int(Sin(s / 180 * 3.141592) * 125) + 175
  45.     y = Int(Cos(s / 180 * 3.141592) * 125) + 175
  46.     For b = -5 To 5 Step .5
  47.         Line (175 + b, 175)-(x, y), _RGB32(0, 255, 255)
  48.         Line (175, 175 + b)-(x, y), _RGB32(0, 255, 255)
  49.     Next b
  50.     x = Int(Sin(s / 180 * 3.141592) * 170) + 175
  51.     y = Int(Cos(s / 180 * 3.141592) * 170) + 175
  52.     For sz = .1 To 5 Step .1
  53.         Circle (x, y), sz, _RGB32(0, 255, 255)
  54.     Next sz
  55.     'Minutes
  56.     m = 180 - minutes * 6
  57.     xx = Int(Sin(m / 180 * 3.141592) * 120) + 175
  58.     yy = Int(Cos(m / 180 * 3.141592) * 120) + 175
  59.     For b = -5 To 5 Step .5
  60.         Line (175 + b, 175)-(xx, yy), _RGB32(127, 255, 127)
  61.         Line (175, 175 + b)-(xx, yy), _RGB32(127, 255, 127)
  62.     Next b
  63.     xx = Int(Sin(m / 180 * 3.141592) * 170) + 175
  64.     yy = Int(Cos(m / 180 * 3.141592) * 170) + 175
  65.     For sz = .1 To 5 Step .1
  66.         Circle (xx, yy), sz, _RGB32(127, 255, 127)
  67.     Next sz
  68.     'Hours
  69.     h = 360 - hours * 30 + 180
  70.     xxx = Int(Sin(h / 180 * 3.141592) * 50) + 175
  71.     yyy = Int(Cos(h / 180 * 3.141592) * 50) + 175
  72.     For b = -5 To 5 Step .5
  73.         Line (175 + b, 175)-(xxx, yyy), _RGB32(255, 122, 0)
  74.         Line (175, 175 + b)-(xxx, yyy), _RGB32(255, 122, 0)
  75.     Next b
  76.     xxx = Int(Sin(h / 180 * 3.141592) * 170) + 175
  77.     yyy = Int(Cos(h / 180 * 3.141592) * 170) + 175
  78.     For sz = .1 To 5 Step .1
  79.         Circle (xxx, yyy), sz, _RGB32(255, 122, 0)
  80.     Next sz
  81.  
  82.     For sz = .1 To 5
  83.         Circle (175, 175), sz, _RGB32(255, 255, 127)
  84.     Next sz
  85.  
  86.     'Chimes
  87.     If minu = 0 And secon = 0 Then
  88.         hour2 = hou
  89.         If hour2 > 12 Then hour2 = hour2 - 12
  90.         If hour2 = 0 Then hour2 = 12
  91.         For chimes = 1 To hour2
  92.             ttt = 0
  93.             Do
  94.                 'queue some sound
  95.                 Do While _SndRawLen < 0.1 'you may wish to adjust this
  96.                     sample = Sin(ttt * 340 * Atn(1) * 8) '340Hz sine wave (ttt * 440 * 2p)
  97.                     sample = sample * Exp(-ttt * 3) 'fade out eliminates clicks after sound
  98.                     _SndRaw sample
  99.                     ttt = ttt + 1 / _SndRate 'sound card sample frequency determines time
  100.                 Loop
  101.                 'do other stuff, but it may interrupt sound
  102.             Loop While ttt < 2 'play for 2 seconds
  103.             Do While _SndRawLen > 0 'Finish any left over queued sound!
  104.             Loop
  105.         Next chimes
  106.     End If
  107.     two:
  108.     _Display
  109.     Cls
  110.     _PutImage (0, 0)-(350, 350), i
  111.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Optical Illusion Clock
« Reply #1 on: January 22, 2022, 09:28:24 pm »
Hey Ken, well you know I had to give this a try ;-))
Code: QB64: [Select]
  1. _Title "Optical Illusion Clock" ' b+ make over 2022-01-22
  2. Screen _NewImage(350, 350, 32)
  3. Dim ticksX(59), ticksY(59)
  4. For i = 0 To 59
  5.     ticksX(i) = 175 + 170 * Cos(i * _Pi(2 / 60))
  6.     ticksY(i) = 175 + 170 * Sin(i * _Pi(2 / 60))
  7.     Cls
  8.     hours = Timer \ 3600
  9.     minutes = Timer \ 60 - hours * 60
  10.     seconds = (Timer - hours * 3600 - minutes * 60)
  11.  
  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.  
  16.     'Hours
  17.     h = 360 - hours * 30 + 180
  18.     radius = 15
  19.     colr~& = _RGB32(200, 0, 0)
  20.     x = Int(Sin(h / 180 * 3.141592) * 80) + 175
  21.     y = Int(Cos(h / 180 * 3.141592) * 80) + 175
  22.     GoSub drawStuff
  23.     _Font 16
  24.     Color &HFFFFFFFF
  25.     _PrintString (x - 8, y - 7), Mid$(Time$, 1, 2)
  26.  
  27.  
  28.     'Minutes
  29.     m = 180 - minutes * 6
  30.     colr~& = _RGB32(0, 128, 0)
  31.     radius = 14
  32.     x = Int(Sin(m / 180 * 3.141592) * 125) + 175
  33.     y = Int(Cos(m / 180 * 3.141592) * 125) + 175
  34.     GoSub drawStuff
  35.     _Font 16
  36.     Color &HFFFFFFFF
  37.     _PrintString (x - 8, y - 7), Mid$(Time$, 4, 2)
  38.  
  39.  
  40.     'Seconds
  41.     s = (60 - seconds) * 6 + 180
  42.     colr~& = _RGB32(0, 0, 128)
  43.     radius = 12
  44.     x = Int(Sin(s / 180 * 3.141592) * 160) + 175
  45.     y = Int(Cos(s / 180 * 3.141592) * 160) + 175
  46.     GoSub drawStuff
  47.     _Font 8
  48.     Color &HFFFFFFFF
  49.     _PrintString (x - 6, y - 4), Mid$(Time$, 7, 2)
  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.     _Display
  73.     _Limit 60
  74. drawStuff:
  75. For i = 0 To 59
  76.     Line (ticksX(i), ticksY(i))-(x, y), colr~&
  77. For sz = .1 To radius Step .2
  78.     Circle (x, y), sz, colr~&
  79. Next sz
  80.  
  81.  
  82.  
  83.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Optical Illusion Clock
« Reply #2 on: January 22, 2022, 10:39:55 pm »
Here is more interesting optical illusion:
Code: QB64: [Select]
  1. _Title "Optical Illusion Clock" ' b+ make over 2022-01-22
  2. Screen _NewImage(350, 350, 32)
  3. _ScreenMove 400, 200
  4.  
  5. grid& = _NewImage(_Width - 1, _Height - 1, 32)
  6. _Dest grid&
  7. Color &HFFFFFF00
  8. side = 170 * Sqr(2)
  9. sided2 = side / 2
  10. drawGrid _Width / 2 - sided2, _Height / 2 - sided2, side / 60, side / 60, 60, 60
  11. Dim ticksX(59), ticksY(59)
  12. For i = 0 To 59
  13.     ticksX(i) = 175 + 170 * Cos(i * _Pi(2 / 60))
  14.     ticksY(i) = 175 + 170 * Sin(i * _Pi(2 / 60))
  15.     Cls
  16.     a = a + _Pi(2 / 3600)
  17.     b = b + _Pi(2 / 3599)
  18.     RotoZoom3 _Width / 2, _Height / 2, grid&, 1, 1, -a
  19.     RotoZoom3 _Width / 2, _Height / 2, grid&, 1, 1, b
  20.     hours = Timer \ 3600
  21.     minutes = Timer \ 60 - hours * 60
  22.     seconds = (Timer - hours * 3600 - minutes * 60)
  23.  
  24.     ' for chimes
  25.     ho$ = Left$(Time$, 2): hou = Val(ho$)
  26.     min$ = Mid$(Time$, 4, 2): minu = Val(min$)
  27.     seco$ = Right$(Time$, 2): secon = Val(seco$)
  28.  
  29.     'Hours
  30.     h = 360 - hours * 30 + 180
  31.     radius = 15
  32.     colr~& = _RGB32(160, 0, 0)
  33.     x = Int(Sin(h / 180 * 3.141592) * 80) + 175
  34.     y = Int(Cos(h / 180 * 3.141592) * 80) + 175
  35.     GoSub drawStuff
  36.     _Font 16
  37.     Color &HFFFFFFFF
  38.     _PrintString (x - 8, y - 7), Mid$(Time$, 1, 2)
  39.  
  40.  
  41.     'Minutes
  42.     m = 180 - minutes * 6
  43.     colr~& = _RGB32(0, 128, 0)
  44.     radius = 14
  45.     x = Int(Sin(m / 180 * 3.141592) * 125) + 175
  46.     y = Int(Cos(m / 180 * 3.141592) * 125) + 175
  47.     GoSub drawStuff
  48.     _Font 16
  49.     Color &HFFFFFFFF
  50.     _PrintString (x - 8, y - 7), Mid$(Time$, 4, 2)
  51.  
  52.  
  53.     'Seconds
  54.     s = (60 - seconds) * 6 + 180
  55.     colr~& = _RGB32(0, 0, 128)
  56.     radius = 12
  57.     x = Int(Sin(s / 180 * 3.141592) * 160) + 175
  58.     y = Int(Cos(s / 180 * 3.141592) * 160) + 175
  59.     GoSub drawStuff
  60.     _Font 8
  61.     Color &HFFFFFFFF
  62.     _PrintString (x - 6, y - 4), Mid$(Time$, 7, 2)
  63.  
  64.     'Chimes
  65.     If minu = 0 And secon = 0 Then
  66.         hour2 = hou
  67.         If hour2 > 12 Then hour2 = hour2 - 12
  68.         If hour2 = 0 Then hour2 = 12
  69.         For chimes = 1 To hour2
  70.             ttt = 0
  71.             Do
  72.                 'queue some sound
  73.                 Do While _SndRawLen < 0.1 'you may wish to adjust this
  74.                     sample = Sin(ttt * 340 * Atn(1) * 8) '340Hz sine wave (ttt * 440 * 2p)
  75.                     sample = sample * Exp(-ttt * 3) 'fade out eliminates clicks after sound
  76.                     _SndRaw sample
  77.                     ttt = ttt + 1 / _SndRate 'sound card sample frequency determines time
  78.                 Loop
  79.                 'do other stuff, but it may interrupt sound
  80.             Loop While ttt < 2 'play for 2 seconds
  81.             Do While _SndRawLen > 0 'Finish any left over queued sound!
  82.             Loop
  83.         Next chimes
  84.     End If
  85.     _Display
  86.     _Limit 60
  87. drawStuff:
  88. For sz = .1 To radius Step .2
  89.     Circle (x, y), sz, colr~&
  90. Next sz
  91.  
  92. Sub drawGrid (x, y, xs, ys, xn, yn) ' top left x, y, x side, y side, number of x, nmber of y
  93.     Dim As Long i, dx, dy
  94.     dx = xs * xn: dy = ys * yn
  95.     For i = 0 To xn
  96.         Line (x + xs * i, y)-(x + xs * i, y + dy)
  97.     Next
  98.     For i = 0 To yn
  99.         Line (x, y + ys * i)-(x + dx, y + ys * i)
  100.     Next
  101.  
  102. Sub RotoZoom3 (X As Long, Y As Long, Image As Long, xScale As Single, yScale As Single, radianRotation As Single) ' 0 at end means no scaling of x or y
  103.     Dim px(3) As Single: Dim py(3) As Single
  104.     Dim W&, H&, sinr!, cosr!, i&, x2&, y2&
  105.     W& = _Width(Image&): H& = _Height(Image&)
  106.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  107.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  108.     sinr! = Sin(-radianRotation): cosr! = Cos(-radianRotation)
  109.     For i& = 0 To 3
  110.         x2& = xScale * (px(i&) * cosr! + sinr! * py(i&)) + X: y2& = yScale * (py(i&) * cosr! - px(i&) * sinr!) + Y
  111.         px(i&) = x2&: py(i&) = y2&
  112.     Next
  113.     _MapTriangle _Seamless(0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image To(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  114.     _MapTriangle _Seamless(0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image To(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  115.  
  116.  

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Optical Illusion Clock
« Reply #3 on: January 23, 2022, 06:57:07 pm »
LOL Great ones B+! I found that cone illusion on accident actually messing with loops and math. lol