Friday, August 20, 2010

Fractals folding out new lands

In keeping with my apparent intense dislike of doing anything constructive (like say my work or my masters), here is another fractal image. This one a bit different from the others in that it is mathematically much simpler and its construction is animated. This is called (at least by me) a divided line fractal (not to be confused with a cantor set). It is very similar to the Koch Curve but with an element of randomness that creates intricate and varied shapes that come to resemble islands or coastlines. This similarity between coast lines and fractals was one of the earliest observations by BenoƮt Mandelbrot, resulting in his well known paper "How Long Is the Coast of Britain?". Similar techniques are used for artificial world creation in computer simulations and games.

The fractal itself is simple to construct. Start with an initial state of two vertical lines, one from the top to the bottom and the other from the bottom to the top of the frame. The for each line take the mid point and move it to a random location around where it was, creating two new line segments. Repeat this step until all the line segments are really small.

In this implementation every time a line segment is broken up the triangle that is created is filled with a translucent yellow. The resulting shape is then filled black. I like to think of the effect as looking like the world is slowly being unfolded, or fanned out from a really simple shape to complete outline

To draw a new shape hit the "Redraw" button. Once again this is done using the HTML5 canvas so you will need a decent browser (Chrome,Safari,Firefox,Opera) to get it to work. It also probably work work through an aggregator like Google reader or buzz since I think they disable scripting, so you will have to visit my original blog page to see it work.

1 comment:

Jason said...

Nice one dude - showed some of the kids and tutors at the Python course we ran this weekend and they were suitably impressed!