### Author Topic: Sierpinski Circled  (Read 764 times)

#### bplus

• Forum Resident
• Posts: 5004
• B+ Knot again!
##### Sierpinski Circled
« on: April 04, 2018, 05:46:12 PM »
A new twist on an old fractal! Sierpinski generalized beyond the triangle to any regular poly (though does not work well above 8 or 9) also made dynamic.

Code: QB64: [Select]
1. _TITLE "Sierepinski Circled by bplus 2018-04-04"
2. CONST xmax = 800
3. CONST ymax = 600
4. SCREEN _NEWIMAGE(xmax, ymax, 32)
5. _SCREENMOVE 360, 60
6. FOR n = 3 TO 8
7.     a = 0
8.     COLOR _RGBA((RND * 155 + 100) * INT(RND * 2), RND * 155 + 100, (RND * 155 + 100) * INT(RND * 2), 40)
9.     WHILE a < _PI(2) - _PI(1 / 360)
10.         a = a + _PI(1 / 360)
11.         levels = 9 - n + 3
12.         RecurringCircles xmax / 2, ymax / 2, ymax / 8, n, a, levels
13.         _LIMIT 200
14. SUB RecurringCircles (x, y, r, n, rao, level)
15.     fcirc x, y, r
16.     IF level > 0 THEN
17.         ra = _PI(2) / n
18.         FOR i = 0 TO n - 1
19.             x1 = x + 1.5 * r * COS(i * ra + rao + _PI(-.5))
20.             y1 = y + 1.5 * r * SIN(i * ra + rao + _PI(-.5))
21.             RecurringCircles x1, y1, r * .5, n, 2 * rao, level - 1
22.
23. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
24. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
26.
30.     Y = 0
31.
32.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
33.
34.     ' Draw the middle span here so we don't draw it twice in the main loop,
35.     ' which would be a problem with blending turned on.
36.     LINE (CX - X, CY)-(CX + X, CY), , BF
37.
38.     WHILE X > Y
40.         IF RadiusError >= 0 THEN
41.             IF X <> Y + 1 THEN
42.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
43.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
44.             X = X - 1
46.         Y = Y + 1
47.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
48.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
49.

The screen shots are stationary stills of final (or start) position.

« Last Edit: April 04, 2018, 05:54:42 PM by bplus »

#### STxAxTIC

• Library Staff
• Forum Resident
• Posts: 833
• Savage
##### Re: Sierpinski Circled
« Reply #1 on: April 04, 2018, 11:24:52 PM »
These are immensely satisfying to watch - didn't expect it to "snap" to a final result before ending. Nice nice!

#### _vince

• Seasoned Forum Regular
• Posts: 277
##### Re: Sierpinski Circled
« Reply #2 on: April 05, 2018, 12:22:55 AM »
Original concept? Really great

#### bplus

• Forum Resident
• Posts: 5004
• B+ Knot again!
##### Re: Sierpinski Circled
« Reply #3 on: April 05, 2018, 01:44:07 AM »
Original concept? Really great

Thanks guys!

The idea of doing Sierpinski Triangles with circles has been on the back burner of my mind for some time and this afternoon, I sat down and got it going. It was so easy that I generalized to any n and running through angle offsets was also easy. I think it a great application for alpha coloring.

Original? It is so simple an idea, I am probably not first to come up with it but I haven't seen code for anything like this.

#### _vince

• Seasoned Forum Regular
• Posts: 277
##### Re: Sierpinski Circled
« Reply #4 on: April 05, 2018, 10:58:25 AM »
made it into an animated gif

#### Richard Frost

• Forum Regular
• Posts: 158
• Needle nardle noo. - Peter Sellers
##### Re: Sierpinski Circled
« Reply #5 on: February 02, 2019, 09:56:51 PM »
Very pretty!

It could be titled "Snowflakes are Dancing", which is an old Isao Tomita electronic music album.
It's what I thought of when I first saw it.

Perhaps download that music and use it in the program, if that's legal where you live.
It works better if you plug it in.

#### bplus

• Forum Resident
• Posts: 5004
• B+ Knot again!
##### Re: Sierpinski Circled
« Reply #6 on: February 02, 2019, 11:15:59 PM »
Ah Music! :)

'paste into browser Alan Parsons Project Mammagamma from Eye in Sky Album

' or whatever...

Code: QB64: [Select]
1. _TITLE "Sierepinski Circled" ' by bplus 2018-04-04"
2. '2019-02-02 mod random
3.
4. CONST xmax = 740
5. CONST ymax = 740
6. SCREEN _NEWIMAGE(xmax, ymax, 32)
7.
8. 'paste into browser Alan Parson Project Mammagamma from Eye in Sky Album
10.
11. ' or whatever...
12.
13.     n = RND * 6 \ 1 + 3
14.     a = 0
15.     COLOR _RGBA((RND * 155 + 100) * INT(RND * 2), RND * 155 + 100, (RND * 155 + 100) * INT(RND * 2), 40)
16.     WHILE a < _PI(2) - _PI(1 / 360)
17.         a = a + _PI(1 / 360)
18.         levels = 9 - n + 3
19.         RecurringCircles xmax / 2, ymax / 2, ymax / 6, n, a, levels
20.         _LIMIT 60
21.
22. SUB RecurringCircles (x, y, r, n, rao, level)
23.     fcirc x, y, r
24.     IF level > 0 THEN
25.         ra = _PI(2) / n
26.         FOR i = 0 TO n - 1
27.             x1 = x + 1.5 * r * COS(i * ra + rao + _PI(-.5))
28.             y1 = y + 1.5 * r * SIN(i * ra + rao + _PI(-.5))
29.             RecurringCircles x1, y1, r * .5, n, 2 * rao, level - 1
30.
31. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
32. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
34.
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
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.             X = X - 1