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

01 Oct, 2024 07:59 AM
30 Sep, 2024 11:37 PM
30 Sep, 2024 11:11 AM
30 Sep, 2024 02:37 AM
28 Sep, 2024 10:33 AM

 

26 Sep, 2024 06:41 AM
24 Sep, 2024 12:32 AM
24 Sep, 2024 12:27 AM
13 Sep, 2024 12:07 AM
12 Sep, 2024 11:54 PM
07 Sep, 2024 05:16 AM