Hacker News new | ask | show | jobs
by daneel_w 1642 days ago
The method presented by the author is the only method I've ever known. It was both simple enough for me to understand as a kid, and fast enough that I could plot the results within a minute using HiSoft BASIC on my Amiga 500.

Just to add the curiosum, the method as it was explained to me as a kid: "Plot a pixel on any corner of the triangle. Pick a new corner on random and plot a pixel halfway between there and where your last pixel was, then just repeat."

2 comments

> The method presented by the author is the only method I've ever known.

The recursive implementation always seemed more intuitive for me.

Could you please share it? I'm not familiar with it.
1. Draw a triangle.

2. Draw 3 triangles within that triangle.

3. For each new triangle, execute step 2 and then 3.

Ah, of course! Thank you.
There are an astonishing number of ways to generate the Sierpinski triangle:

1. The Chaos Game, as described in this post.

2. Other ways of rendering the IFS; for example, iterating over the possibility tree of transforming a single point 10 times and plotting the 59049 leaves, or searching over the tree of inverse transformations from a given pixel to some depth like 6 and coloring the pixel with the length of the longest chain that doesn't blow up. It's a very well behaved IFS, so even methods that have trouble with some IFSs will do fine.

3. Coloring the odd numbers in Pascal's Triangle, aka Yang Hui's Triangle or the triangle from मेरु प्रस्तार.

4. As a generalization, plotting histories of an astonishingly wide range of 1-D cellular automata, starting with a single "live" cell. For example, the totalistic rule where a cell is live iff exactly 1 of itself and its neighbors were alive (rule 14). About a third of the 256 2-state neighborhood-3 CAs like this are some deformation of the Triangle IIRC.

5. A surprisingly large variety of L-systems also generate the Triangle. In http://canonical.org/~kragen/laserboot/cut-6 I used, I think, F = !F!-F-!F!, where ! swaps left and right. An interesting thing about this curve in particular is that it avoids self-intersections, which is what makes it somewhat suitable for laser cutting.

6. And of course you can start with a solid triangle, cut a hole in its middle to make a triforce, and then recursively do the same for each of the resulting three remaining triangles.

7. For use as a calendar, http://canonical.org/~kragen/sw/dev3/siercal I generated a tour of the triangle with a non-L-system method, just subdividing the triangle recursively.

8. It's also interesting to note that the state space of the Towers of Hanoi puzzle has the shape of the Sierpinski Triangle. So a suitable 2D graph layout algorithm (all edges equal length, maximizing total distance from the center) applied to the state space graph ought to generate it. This is a little handwavy, though.

9. I'd forgotten this, but as John D. Cook points out in https://www.johndcook.com/blog/2019/11/26/fractal-via-bit-tw..., the pixels where the bitwise AND of the X and Y coordinates is zero form a distorted Sierpinski Triangle.

10. Cook points out in https://www.johndcook.com/blog/2019/10/19/binary-surprise/ that the numbers of sides in the regular n-gons constructible with compass and straightedge, when written down in binary, also form the Sierpinski Triangle.

It's not rule 14. https://en.wikipedia.org/wiki/Elementary_cellular_automaton shows Sierpinski triangles for rules 18, 22, 26, 60, 82, and 90, but only shows the one-cell results for rules <100. https://plato.stanford.edu/entries/cellular-automata/supplem... has a full list, adding 102, 126, 129, 146, 153, 154, 161, 165, 167, 181, 182, 195, 210, and 218, for a total of 20, which is a lot less than a third of 256. (A few more can be coaxed into Sierpinski-triangle behavior with different starting conditions, IIRC.) Rule 22 is the one I was thinking of.