Fractals have always fascinated me. They're just so neat! So much from so little... for instance, if you are running a modern browser, you should see a nifty fractal background on this very page. What makes it really cool is that it was produced with nothing but javascript - and the equation to do so is really quite short.

The way fractals work is actually really simple - every dot on a screen has three numbers that describe it. First, there is the X value: the distance from the left "wall". The second value is the Y value, or the distance from the top "wall" (on a screen, anyway). And finally, there is the color. What a fractal generator does is take a value of X and Y and make up a color using them. It feeds the two values - X and Y - into an equation. then it takes that value, and feeds it through again - as many times as it takes to make the answer "really big", whatever value "really big" was set to. The number of times it takes to get "really big" dictates the color; in the background fractal, the longer it takes to get to "really big", the closer to black it gets. Say, for instance, the fractal generator feeds in 100 and 120. It puts those numbers through its equation, and ends up with the answer of, say, 15. That's not really big, so it puts it through again, and gets 105. Still not big enough, it keeps feeding it through. The more times it feeds it through, the higher the count on C gets, and eventually, if it never gets big, it gives up and calls it black. If, however, it worked the very first time, it would be white; somewhere between those two would be all the various shades of gray.

The value when it gives up is the iteration limit; hypothetically, it could keep running the equation forever, but that would waste a lot of time. Instead, it has a number that is the cutoff - if it takes more than (say) 100 times to get the answer, give up and say it'll never happen.

The fractal here is called a Mandelbrot set; you can change what equations are used, here:

Color scheme:
Smooth Colors:

The "Multibrot" selections multiply the answer by itself 3, or 4, or 8 times, to get those other interesting shapes. The Julia set is related to the Mandelbrot set, but it uses a constant complex number. The choice of complex number results in a fairly large variety of shapes - some used in this are the Dendrite, Siegel Disk, Douady's Rabbit and San Marco. The Sine and Cosine functions modify the Julia equation with a bit of trigonometry, resulting in much larger functions. Go ahead and experiment!

I borrowed this code from Nihilogic, though I've modified it with a bit of jQuery to be a little bigger and more portable.