Sierpinsky node?

Julian Gosper's Avatar

Julian Gosper

17 Feb, 2022 01:52 AM

Hey beautiful brains,
I had this sudden urge to try and make a Sierpinsky fractal node that generates essentially:
https://mathigon.org/course/fractals/sierpinski#:~:text=The%20Sierpinski%20triangle%20is%20a,removed%20from%20its%20remaining%20area.&text=It%20can%20be%20created%20by,triangles%20out%20of%20its%20center.

Where you can feed it an integer for #generations of using a resample node subdividing points on a polygon (triangle) node.
Each generation effectively subdividing each line with a new point which then becomes coordinates for a new polygon (triangle)...

I failed.
Any advice greatly appreciated!
Nodebox file attached... (sad)

  1. Support Staff 1 Posted by john on 17 Feb, 2022 06:28 AM

    john's Avatar

    Julian,

    Thanks for this fun challenge and for having the courage to post your valiant attempt.

    The reason you had so much trouble is that Nodebox doesn't do recursion. It's an odd and frustrating lapse we have to live with. But in software, where there's a will there's almost always a way.

    You can do recursion manually by creating a subnetwork that takes in one triangle and spits out three subtriangles. You can then simply chain together as many of these as you want. See attached screenshot and demo file.

    The demo goes nine levels deep by simply chaining together nine Sierpinkski nodes. The result is a Sierpinski triangle with 19,683 subtriangles. If you want to go deeper, just add more Sierpinski nodes.

    If you really want a parameter driven solution that lets you simply set a depth you can do that too, though it's a bit of hack. You need to chain together enough Sierpinski nodes to achieve a maximum depth - which will have to be fairly low (as you get north of about 100,000 subtriangles, NodeBox will slow to a crawl). You can then feed lines from each possible depth into some switch nodes, use a depth parameter to choose the depth, and wrap the whole thing in a bigger subnetwork.

    You could do that, but I doubt it would be worth the bother. It's quite easy to chain these subnetworks together by hand (just copy paste to get more).

    Great question! Keep them coming!

    Happy Nodeboxing!

    John

  2. Support Staff 2 Posted by john on 17 Feb, 2022 06:52 AM

    john's Avatar

    And here, just for fun, is what happens if you colorize those 19,683 subtriangles in hues ranging from red to violet. This shows the order in which the subtriangles get drawn.

    Pretty!

    John

  3. 3 Posted by Julian Gosper on 17 Feb, 2022 07:35 AM

    Julian Gosper's Avatar

    Fantastic John! That explains it!
    BTW - could you share that cool colour nodebox???

  4. Support Staff 4 Posted by john on 17 Feb, 2022 08:31 AM

    john's Avatar

    And here, for even more fun, is the triangle animated.

    Incidentally, to do this animation I did end up making a parameterized version of the Sierpinski node. Code available upon request.

    John

  5. Support Staff 5 Posted by john on 17 Feb, 2022 08:35 AM

    john's Avatar

    Hey Julian,

    Just saw your note above. I guess you did request the code. So here it is (attached).

    Perhaps you could take this basic concept and attack some other cool fractals.

    John

  6. Support Staff 6 Posted by john on 17 Feb, 2022 08:37 AM

    john's Avatar

    Oops. Forgot to attach the animation. Here it is.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Already uploaded files

  • sierpinski_original.ndbx.zip 1.92 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

31 Jan, 2023 11:29 PM
28 Jan, 2023 10:39 AM
26 Jan, 2023 01:30 AM
26 Jan, 2023 01:24 AM
26 Jan, 2023 12:48 AM

 

20 Jan, 2023 02:32 PM
13 Jan, 2023 09:54 PM
11 Jan, 2023 10:32 AM
09 Jan, 2023 11:45 AM
28 Dec, 2022 11:19 PM
27 Dec, 2022 06:57 AM