A trivial piece of programming fun for a Sunday afternoon

Associate
Joined
5 Jun 2004
Posts
515
Location
Cambridge
Having just read Inquisitor's post about his program that draws the Mandelbrot set it reminded about fractal geometry and all that jazz. I also remembered about a trivial little exercise that you can do which draws a cool fractal pattern (albeit not as cool as a Mandelbrot or Julia set, but still cool).

It's so simple that you can do it in pretty much any programming language as long as it has basic image processing functionality.

Anyway, here's how you do it:

  1. Draw three points in order to create a triangle. Plot a fourth point somewhere inside the centre of this triangle. This fourth point (P4) is now the 'starting point'.

    step16uk.png


  2. Randomly select one of the points that forms the triangle (in this case P3). Plot the mid point between the starting point (P4) and the randomly chosen point (P3). This new point, P5 is now your new starting point.

    step27cn.png


  3. Chose another random point that forms the triangle and repeat.

    step31qu.png

That's it! You'll probably need to do quite a few iterations depending on the size of the triangle. For me it took about a thousand iterations for the pattern to become clear, that's with a triangle that filled a 1000x1000 canvas.

Anyway, I hope this makes at least a small amount of sense.

Have fun! :)
 
Back
Top Bottom