Author Topic: Optical Illusion  (Read 361 times)

Optical Illusion
« on: January 12, 2019, 04:21:19 PM »
Found interesting optical illusion on Internet, was curious if I could duplicate it.
Code: QB64 [Select]
  1. _TITLE "Do the dots in disk look like they are spinning?" ' B+ 2019-01-12
  2. 'try an optical illusion saw on Internet
  3.  
  4. CONST xmax = 600
  5. CONST ymax = 600
  6. SCREEN _NEWIMAGE(xmax, ymax, 32)
  7. _SCREENMOVE 300, 60
  8.  
  9. x0 = xmax / 2: y0 = ymax / 2: a24 = _PI(2 / 24): r = 240
  10.     IF loopcnt < 2 THEN stopit = 11
  11.     IF loopcnt = 2 THEN stopit = 0
  12.     IF loopcnt > 2 THEN
  13.         IF stopit < 11 THEN stopit = stopit + 1
  14.     END IF
  15.     FOR a = 0 TO _PI(2) STEP _PI / 180
  16.         COLOR _RGB32(128, 0, 0): fcirc x0, y0, 251
  17.         FOR i = 0 TO stopit
  18.             IF loopcnt > 1 THEN
  19.                 xs = x0 + r * COS(a24 * i)
  20.                 ys = y0 + r * SIN(a24 * i)
  21.                 xe = x0 + r * COS(a24 * i + _PI)
  22.                 ye = y0 + r * SIN(a24 * i + _PI)
  23.                 LINE (xs, ys)-(xe, ye), _RGB32(255, 255, 255)
  24.             END IF
  25.             x = x0 + COS(a + _PI(i / 12)) * r * COS(a24 * i)
  26.             y = y0 + COS(a + _PI(i / 12)) * r * SIN(a24 * i)
  27.             COLOR _RGB32(255, 255, 255)
  28.             fcirc x, y, 10
  29.         NEXT
  30.         _DISPLAY
  31.         _LIMIT 90
  32.     NEXT
  33.     loopcnt = loopcnt + 1
  34.  
  35. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  36. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  37.     DIM subRadius AS LONG, RadiusError AS LONG
  38.     DIM X AS LONG, Y AS LONG
  39.  
  40.     subRadius = ABS(R)
  41.     RadiusError = -subRadius
  42.     X = subRadius
  43.     Y = 0
  44.  
  45.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  46.  
  47.     ' Draw the middle span here so we don't draw it twice in the main loop,
  48.     ' which would be a problem with blending turned on.
  49.     LINE (CX - X, CY)-(CX + X, CY), , BF
  50.  
  51.     WHILE X > Y
  52.         RadiusError = RadiusError + Y * 2 + 1
  53.         IF RadiusError >= 0 THEN
  54.             IF X <> Y + 1 THEN
  55.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  56.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  57.             END IF
  58.             X = X - 1
  59.             RadiusError = RadiusError - X * 2
  60.         END IF
  61.         Y = Y + 1
  62.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  63.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  64.     WEND
  65.  
B = B + ...

Re: Optical Illusion
« Reply #1 on: January 12, 2019, 04:49:44 PM »
Again, this is just dots going back and forth on a line!
Code: QB64 [Select]
  1. _TITLE "Do the dots in disk look like they are spinning?" ' B+ 2019-01-12
  2. 'try an optical illusion saw on Internet
  3.  
  4. CONST xmax = 600
  5. CONST ymax = 600
  6. SCREEN _NEWIMAGE(xmax, ymax, 32)
  7. _SCREENMOVE 300, 60
  8.  
  9. x0 = xmax / 2: y0 = ymax / 2: a24 = _PI(2 / 24): r = 240
  10.     FOR a = 0 TO _PI(2) STEP _PI / 180
  11.         COLOR _RGB32(128, 0, 0): fcirc x0, y0, 251
  12.         FOR i = 0 TO 23
  13.             IF loopcnt > 4 THEN
  14.                 xs = x0 + r * COS(a24 * i)
  15.                 ys = y0 + r * SIN(a24 * i)
  16.                 xe = x0 + r * COS(a24 * i + _PI)
  17.                 ye = y0 + r * SIN(a24 * i + _PI)
  18.                 LINE (xs, ys)-(xe, ye), _RGB32(255, 255, 255)
  19.             END IF
  20.             x = x0 + COS(a + _PI(i / 6)) * r * COS(a24 * i)
  21.             y = y0 + COS(a + _PI(i / 6)) * r * SIN(a24 * i)
  22.             COLOR _RGB32(i * 10, (23 - i) * 10, 0)
  23.             fcirc x, y, 10
  24.         NEXT
  25.         _DISPLAY
  26.         _LIMIT 90
  27.     NEXT
  28.     loopcnt = loopcnt + 1
  29.  
  30. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  31. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  32.     DIM subRadius AS LONG, RadiusError AS LONG
  33.     DIM X AS LONG, Y AS LONG
  34.  
  35.     subRadius = ABS(R)
  36.     RadiusError = -subRadius
  37.     X = subRadius
  38.     Y = 0
  39.  
  40.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  41.  
  42.     ' Draw the middle span here so we don't draw it twice in the main loop,
  43.     ' which would be a problem with blending turned on.
  44.     LINE (CX - X, CY)-(CX + X, CY), , BF
  45.  
  46.     WHILE X > Y
  47.         RadiusError = RadiusError + Y * 2 + 1
  48.         IF RadiusError >= 0 THEN
  49.             IF X <> Y + 1 THEN
  50.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  51.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  52.             END IF
  53.             X = X - 1
  54.             RadiusError = RadiusError - X * 2
  55.         END IF
  56.         Y = Y + 1
  57.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  58.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  59.     WEND
  60.  
  61.  
B = B + ...

Offline Pete

  • Cuz I sez so, varmint!
Re: Optical Illusion
« Reply #2 on: January 12, 2019, 05:53:25 PM »
Oh I get it now, bplus isn't a grade, it stands for balls plus! It's some kind of cognitive  illusion!

Well that was cool! I could follow the straight line movement just find but as soon as you lose focus, bam, they appear to be traveling in a circle.

Nice recreation!

Pete


Offline johnno56

  • Live long and prosper.
Re: Optical Illusion
« Reply #3 on: January 13, 2019, 08:30:41 AM »
Both are very clever. Discs travelling in a straight line, but due to the timing, appear to travel in circles. Nicely done!

I only have one question. Do they come in blue? lol

J
Logic is the beginning of wisdom.

Offline FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: Optical Illusion
« Reply #4 on: January 13, 2019, 08:54:15 AM »
I too had seen this online a good while back and tried writing it but the math involved just flew over my head and I gave up before I closed my first DO LOOP.

Great job, bplus! Really fun to watch - I like the "trick explained" mode in the first program.

Re: Optical Illusion
« Reply #5 on: January 13, 2019, 09:55:33 AM »
Yes, lovely.

Offline Pete

  • Cuz I sez so, varmint!
Re: Optical Illusion
« Reply #6 on: January 13, 2019, 12:06:47 PM »
Both are very clever. Discs travelling in a straight line, but due to the timing, appear to travel in circles. Nicely done!

I only have one question. Do they come in blue? lol

J

LOL! Silly question. Mark lives in Canada, so of course his balls come in blue!

Pete :D

Re: Optical Illusion
« Reply #7 on: January 13, 2019, 01:44:44 PM »
Thanks guys!

Blue balls? Here are some magic ones:
Code: QB64 [Select]
  1. _TITLE "Magic Blue Balls?" ' OI #4 Blue Balls.bas B+ 2019-01-13
  2. 'try another optical illusion saw on Internet
  3.  
  4. CONST xmax = 1100
  5. CONST ymax = 700
  6. SCREEN _NEWIMAGE(xmax, ymax, 32)
  7.  
  8. COLOR _RGBA32(255, 255, 255, 100), _RGB32(0, 0, 80)
  9. FOR i = 40 TO 1040 STEP 50
  10.     LINE (i, 0)-(i + 10, ymax), , BF
  11.     LINE (0, i)-(xmax, i + 10), , BF
  12. COLOR _RGB32(255, 255, 255)
  13. FOR y = 45 TO 645 STEP 50
  14.     FOR x = 45 TO 1045 STEP 50
  15.         fcirc x, y, 8
  16.     NEXT
  17. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  18. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  19.     DIM subRadius AS LONG, RadiusError AS LONG
  20.     DIM X AS LONG, Y AS LONG
  21.  
  22.     subRadius = ABS(R)
  23.     RadiusError = -subRadius
  24.     X = subRadius
  25.     Y = 0
  26.  
  27.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  28.  
  29.     ' Draw the middle span here so we don't draw it twice in the main loop,
  30.     ' which would be a problem with blending turned on.
  31.     LINE (CX - X, CY)-(CX + X, CY), , BF
  32.  
  33.     WHILE X > Y
  34.         RadiusError = RadiusError + Y * 2 + 1
  35.         IF RadiusError >= 0 THEN
  36.             IF X <> Y + 1 THEN
  37.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  38.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  39.             END IF
  40.             X = X - 1
  41.             RadiusError = RadiusError - X * 2
  42.         END IF
  43.         Y = Y + 1
  44.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  45.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  46.     WEND
  47.  
  48.  
B = B + ...

Re: Optical Illusion
« Reply #8 on: January 13, 2019, 03:42:19 PM »
Blue ball buster:
Code: QB64 [Select]
  1. _TITLE "Crazy Squares in Concentric Circles" ' OI #3 crazy sqrs on concentric circles.bas B+ 2019-01-13
  2. 'try another optical illusion saw on Internet
  3.  
  4. CONST xmax = 700
  5. CONST ymax = 700
  6. SCREEN _NEWIMAGE(xmax, ymax, 32)
  7.  
  8. side = 20: cx = xmax / 2: cy = ymax / 2
  9.     COLOR , _RGB32(60, 60, 100): CLS
  10.     nstars = 1: starN = 1: d = 0
  11.     FOR r = 1 TO 5
  12.         d = d + 5
  13.         rr = r * (30 + d)
  14.         IF r MOD 2 THEN a = _PI(1 / 12) ELSE a = _PI(-1 / 12)
  15.         circ = 2 * _PI * rr
  16.         n = INT(circ / (1.2 * side))
  17.         IF n MOD 2 THEN n = n - 1
  18.         FOR i = 1 TO n
  19.             x = cx + rr * COS(i * 2 * _PI / n)
  20.             y = cy + rr * SIN(i * 2 * _PI / n)
  21.             starN = starN + 1
  22.             IF starN MOD 2 THEN COLOR _RGB32(0, 0, 255) ELSE COLOR _RGB(0, 0, 60)
  23.             box x, y, i * 2 * _PI / n + a, side
  24.             PAINT (x, y)
  25.         NEXT
  26.     NEXT
  27.     _DELAY 3
  28.     d = 0
  29.     FOR r = 1 TO 5
  30.         d = d + 5
  31.         rr = r * (30 + d)
  32.         CIRCLE (cx, cy), rr, _RGB32(255, 255, 255)
  33.     NEXT
  34.     _DELAY 1
  35.  
  36. SUB box (xCenter, yCenter, rAngle, side)
  37.     p45 = _PI(.25)
  38.     p135 = 3 * p45
  39.     stside = .5 * side * SQR(2)
  40.     x1 = xCenter + stside * COS(rAngle + p45)
  41.     y1 = yCenter + stside * SIN(rAngle + p45)
  42.     x2 = xCenter + stside * COS(rAngle + p135)
  43.     y2 = yCenter + stside * SIN(rAngle + p135)
  44.     x3 = xCenter + stside * COS(rAngle - p135)
  45.     y3 = yCenter + stside * SIN(rAngle - p135)
  46.     x4 = xCenter + stside * COS(rAngle - p45)
  47.     y4 = yCenter + stside * SIN(rAngle - p45)
  48.     LINE (x1, y1)-(x2, y2)
  49.     LINE (x2, y2)-(x3, y3)
  50.     LINE (x3, y3)-(x4, y4)
  51.     LINE (x4, y4)-(x1, y1)
  52.  
  53.  
B = B + ...

Offline Pete

  • Cuz I sez so, varmint!
Re: Optical Illusion
« Reply #9 on: January 13, 2019, 03:51:07 PM »
Have you considered therapy? Under the Canadian system, some other poor schmuck will pay for it.

I knew they were circles right off the bat but it does look like a spiral when the squares are slanted. This stuff probably comes to us from an alternate universe. One where QB64 does not exist, and the Bill there needs something to keep himself occupied. I'm just saying...

Pete 

Re: Optical Illusion
« Reply #10 on: January 13, 2019, 05:10:19 PM »
\_ ? _/  Canada?  Is across the lake from me.
    |
   /\
  \  |
B = B + ...

Offline Pete

  • Cuz I sez so, varmint!
Re: Optical Illusion
« Reply #11 on: January 13, 2019, 05:54:47 PM »
That just means you live on the east or west bank of said lake... in Canada!

Pete

You can time some of the fools all the people, and time all of the fools some of the people, but you can't time all of the fools all of the people -FreeBASIC

Offline johnno56

  • Live long and prosper.
Re: Optical Illusion
« Reply #12 on: January 14, 2019, 07:33:30 AM »
Perfect! Everything is blue... the optic nerves are shot... but at least everything is blue...

J
Logic is the beginning of wisdom.