Anarchy: good luck with that!

Some people have a hard time grasping that disorder can yield order, or that an impossibly stupid approach can yield beautiful results. Those people have clearly never heard of the Chaos Game. I bet you knew my earlier talk of fractals would get us here eventually.

Or perhaps you have heard of the Chaos Game, but you're just disappointed by the 10 year old Java applets around the web. For your amusement, I present what looks to be the first decent JavaScript version. Click in the drawing area to set your points, pick your decimal fraction to move, and let it go! Suggestions for improvements and/or bug reports are appreciated.

Note: my code attempts to use the canvas element to draw the dots. For browsers that don't support that, the code uses 1 pixel div elements. Having thousands of elements in the document for longer plots can potentially suck up a lot of resources. If you're going to let it run for longer than around 30 seconds, you're probably best served by using a browser with canvas support.

Update: the code has been modified since original publication as explained here

Comments

Suggestions

is it possible to make it bigger? is it possible to have a toggle-able grid so it's easier to set the points?
the grid would help with the placement of points. I try to get them arranged "just so"... and it's a little hard to line them up exactly.
I'd also like a function for clearing all the random points, but leaving all the user selected vertices
it'd also be neat to be able to clear the vertices while leaving the random point pattern... then being able to set new vertices and run it again. one could create composite patterns that way

Use the source

The JavaScript and HTML are pretty configurable if you wanted to put your own interface on top. Bigger is no problem, other than speed to fill it all in randomly. A grid I'm not sure I see much advantage in, though I could display the current coordinates fairly easily.

For the clearing options, I didn't want to clutter up the page with a ton of buttons. I could possibly make an "action" popup menu that had distinct "reset" and "clear" functions, along with presets for Sierpinski and other common fractals.

I'll look at making updates like that when I have some free time. Thanks for the feedback!