### Author Topic: Optical Illusion  (Read 361 times)

#### bplus

##### 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.     FOR a = 0 TO _PI(2) STEP _PI / 180
15.         COLOR _RGB32(128, 0, 0): fcirc x0, y0, 251
16.         FOR i = 0 TO stopit
17.             IF loopcnt > 1 THEN
18.                 xs = x0 + r * COS(a24 * i)
19.                 ys = y0 + r * SIN(a24 * i)
20.                 xe = x0 + r * COS(a24 * i + _PI)
21.                 ye = y0 + r * SIN(a24 * i + _PI)
22.                 LINE (xs, ys)-(xe, ye), _RGB32(255, 255, 255)
23.             x = x0 + COS(a + _PI(i / 12)) * r * COS(a24 * i)
24.             y = y0 + COS(a + _PI(i / 12)) * r * SIN(a24 * i)
25.             COLOR _RGB32(255, 255, 255)
26.             fcirc x, y, 10
27.         _LIMIT 90
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)
33.
37.     Y = 0
38.
39.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
40.
41.     ' Draw the middle span here so we don't draw it twice in the main loop,
42.     ' which would be a problem with blending turned on.
43.     LINE (CX - X, CY)-(CX + X, CY), , BF
44.
45.     WHILE X > Y
47.         IF RadiusError >= 0 THEN
48.             IF X <> Y + 1 THEN
49.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
50.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
51.             X = X - 1
53.         Y = Y + 1
54.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
55.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
56.
B = B + ...

#### bplus

##### 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.             x = x0 + COS(a + _PI(i / 6)) * r * COS(a24 * i)
20.             y = y0 + COS(a + _PI(i / 6)) * r * SIN(a24 * i)
21.             COLOR _RGB32(i * 10, (23 - i) * 10, 0)
22.             fcirc x, y, 10
23.         _LIMIT 90
24.     loopcnt = loopcnt + 1
25.
26. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
27. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
29.
33.     Y = 0
34.
35.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
36.
37.     ' Draw the middle span here so we don't draw it twice in the main loop,
38.     ' which would be a problem with blending turned on.
39.     LINE (CX - X, CY)-(CX + X, CY), , BF
40.
41.     WHILE X > Y
43.         IF RadiusError >= 0 THEN
44.             IF X <> Y + 1 THEN
45.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
46.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
47.             X = X - 1
49.         Y = Y + 1
50.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
51.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
52.
53.
B = B + ...

#### 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

#### 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.

#### FellippeHeitor

• QB64 Developer
• LET IT = BE
##### 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.

#### Qwerkey

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

#### 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

#### bplus

##### 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. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
17. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
19.
23.     Y = 0
24.
25.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
26.
27.     ' Draw the middle span here so we don't draw it twice in the main loop,
28.     ' which would be a problem with blending turned on.
29.     LINE (CX - X, CY)-(CX + X, CY), , BF
30.
31.     WHILE X > Y
33.         IF RadiusError >= 0 THEN
34.             IF X <> Y + 1 THEN
35.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
36.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
37.             X = X - 1
39.         Y = Y + 1
40.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
41.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
42.
43.
B = B + ...

#### bplus

##### 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.     d = 0
26.     FOR r = 1 TO 5
27.         d = d + 5
28.         rr = r * (30 + d)
29.         CIRCLE (cx, cy), rr, _RGB32(255, 255, 255)
30.
31. SUB box (xCenter, yCenter, rAngle, side)
32.     p45 = _PI(.25)
33.     p135 = 3 * p45
34.     stside = .5 * side * SQR(2)
35.     x1 = xCenter + stside * COS(rAngle + p45)
36.     y1 = yCenter + stside * SIN(rAngle + p45)
37.     x2 = xCenter + stside * COS(rAngle + p135)
38.     y2 = yCenter + stside * SIN(rAngle + p135)
39.     x3 = xCenter + stside * COS(rAngle - p135)
40.     y3 = yCenter + stside * SIN(rAngle - p135)
41.     x4 = xCenter + stside * COS(rAngle - p45)
42.     y4 = yCenter + stside * SIN(rAngle - p45)
43.     LINE (x1, y1)-(x2, y2)
44.     LINE (x2, y2)-(x3, y3)
45.     LINE (x3, y3)-(x4, y4)
46.     LINE (x4, y4)-(x1, y1)
47.
48.
B = B + ...

#### 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

#### bplus

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

#### 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

#### 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.