09 April 2010

Coin toss fractal in Mathematica [edit]

Hello -

It's well-known but surprising that you can create beautiful images of fractals with a coin toss (okay, dice) and paper & pencil:


(Drawn by computer)
  • Label corners of a triangle {1, 2, 3}.
  • Draw a dot at a corner (or anywhere?)
  • While not tired:
  • - Generate random integer N = [1,3].
  • - Draw a dot halfway between the last dot and corner N.


Click for code



(Click to embiggen. It's pretty!)

[Edit - Thanks, Matthias! It works for squares, too, using the method he describes in the comments.]



(Matthias: Yeah, it works in 3-space, too:)

Gregg



6 comments:

Matthias said...

Apologies if you were being tongue-in-cheek about it not working for squares, but:

It works for triangles because each of the three sub-triangles at the corners is a scaled down version of the whole triangle -- that's what makes it fractal. When you move halfway to one of the corners, what you're actually doing is mapping a point in the whole triangle into one of the three sub-triangles at the corners, leaving a gap for the half-size triangle in the middle. And so on recursively.

It doesn't work for squares because when you map a square onto one of its four sub-quadrants, there's no gap in the middle, and you end up just filling the whole square.

Rather, the square equivalent is the Sierpinski carpet. In that case, you're mapping the whole square into one of the eight sub-squares around the edge, leaving a gap for the ninth central sub-square.

So if you changed the algorithm to randomly choose one of the four corners OR one of the four midpoints of the edges, and then moved the point 2/3 of the way there instead of halfway (because the sub-squares are 1/3 the size of the whole square), then I expect you'd get the Sierpinski carpet. Let me know if it works.

Matthias said...

On reading further down the wikipedia page, they pretty much spell out the algorithm I suggested. So, yeah.

G-Fav said...

Thanks, I didn't know that! In my Mathematica notebook, I wrote "naive extension to squares..." but it's not like I actually knew how to do it. I'll try it.

g

Matthias said...

Hm, closer, but still not quite right. It's only mapping to the four corner squares. Did you include the four midpoints along with the four corners?

Matthias said...

OK, that's totally awesome. Re 3-space: see here.

Chemical Suppliers said...

ChemicalsBuyersGuide.com is the world's largest directory of chemical producers and suppliers for global trade and the leading provider of online marketing services for importers and exporters. It is the place for buyers and sellers to find trade opportunities and promote their business online.
ChemicalsBuyersGuide.com is not a trading company but rather an online business platform, where you can search or post information to find potential business partners.