Triangle Fractal

Chip described a way to create a fractal. I paraphrase: Start with an equalateral triangle. Find the current point by picking a vertex at random. Put a mark at the current point (the vertex you just picked). Change the current point by picking a vertex at random and making the current point the midway point between the old point and the current point. Put a mark there and repeat. Do that about 50,000 times and see what you get. Or paste this code into a workbook and run SheetTriangle. Make sure you run it from Excel and not the VBE – it’s cooler to watch than just see the end result.

I started doing this with shapes instead of colored cells. It didn’t look quite as good and I’d end up with 10,000 shapes on a sheet, which can’t be too stable. I changed to coloring cells and upped the iterations to 50,000, which is roughly 256 x 227. I don’t know if 50k is too many or too few, but it definitely gives you a good idea. The 227 is what I calculated the height in cells to be to make the legs of the triangle 256. You don’t need an equalateral triangle, though, it’s just the way it was first presented to me. I also heard that the randomness isn’t necessary, but I couldn’t make it work otherwise. I’m sure it’s possible, I’m just not up to it.

I asked Chip to whom credit was due, and he said he came up with it himself. I’m not too shocked, he’s a pretty smart guy. I think 1,000 monkeys on a 1,000 typewriters would have a better chance coming up with this than me. Some guy named Sierpinski beat him to it by about 90 years, albeit via a different method.

8 thoughts on “Triangle Fractal

  1. Fractals are beautiful aren’t they?

    I really like animated fractals too, like zooming into a mandelbrot.

    The method you describe is pretty much how my fractal landscape generator works.

    After I created the formula page, I noticed how big the workbook got – about 2MB. Being wary of large downloads, I decided to create the formula page on workbook open.
    A fractal generator generator.

    Rob

  2. Although black and white is what sierpinski saw, it is more colourfull to whatch it with:

    Sub PlacePointWsh(ByVal NewX As Long, ByVal NewY As Long, ByRef wsh As Worksheet)

    wsh.Cells(NewY, NewX).Interior.Color = Choose(Int(7 * Rnd + 1), _
    vbBlack, vbRed, vbBlue, vbGreen, vbYellow, vbMagenta, vbWhite)

    End Sub

  3. here’s my code for generating random numbers using simple arithmetic and no random function:

    the center column (as far as I can tell) can not be expressed by a mathematical formula…

  4. sorry … that did not come across right …

    If n1 > 0 And n1 0 And n2 0 And n3 < 5 Then n3 = 1 Else n3 = 0

    replace the 7th line of code with the 3 lines above …

  5. hmm … still did not come across right …

    sorry … need to look into how to post a section of code …

  6. Enclose the code in pre tags and it won’t eat the less than signs. I took a stab at editing your first comment, but I’m not sure I got it right.


Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published.