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:,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


    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!


  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.



  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.


  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.


  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

  • 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


? 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

30 Nov, 2023 05:40 AM
29 Nov, 2023 01:33 PM
29 Nov, 2023 05:30 AM
28 Nov, 2023 10:03 PM
28 Nov, 2023 12:38 AM


27 Nov, 2023 04:40 AM
26 Nov, 2023 10:02 AM
22 Nov, 2023 09:33 AM
20 Nov, 2023 08:54 PM
17 Nov, 2023 01:43 AM
15 Nov, 2023 06:58 AM