The Mandelbrot set
To demonstrate how to use web workers to do some real processing we will create an application that draws Mandelbrot fractals . Drawing a Mandelbrot is pretty intensive and takes a lot of processing power. If you don't run it in a separate thread, the application will become unresponsive while it's drawing.
Drawing a Mandelbrot is a relatively simple process. We will use the escape time algorithm . For each pixel in the image we will determine how many iterations it takes to reach a critical escape condition. The number of iterations determines the color of the pixel. If we don't reach the escape condition within a maximum number of iterations, it is considered to be inside the Mandelbrot set and we color it black.
For more information about this algorithm and the Mandelbrot set see the Wikipedia page: