| Raster Scan |
Robert P. Munafo, 2008 Mar 14.
Here is pseudo-code for a raster-scan Mandelbrot program:
program mandelbrot-rs-1 comment "mandelbrot set, using a single raster scan." declare x, y : integer declare r, i : real declare z : complex for x = 1 to grid_width increment_by 1 do for y = 1 to grid_height increment_by 1 do let r = XtoRealCoord(x) let i = YtoImagCoord(y) let z.r = r let z.i = i let count = escapeiterations(z, max_iterations) let color = mycolormapping(count) plotpoint(x, y, color) if userintervention() then exit for(x) end if end for(y) end for(x)The functions XtoRealCoord and YtoImagCoord convert the grid coordinates x and y to real and imaginary components r and i.
The algorithm for EscapeIterations is described on the _Escape Iterations_ page.
The function MyColorMapping has to pick a color number based on the number of iterations from EscapeIterations. We're assuming that colors are specified with a single integer value. If the number of colors is less than max_iterations then you have to do something to handle that.
The PlotPoint routine draws a dot on the screen of the specified color at the specified x and y coordinates. This will depend on what type of operating system and graphics environment your program is running in.
The UserIntervention function checks the keyboard or the mouse to see if the user wants to abort the drawing process.
See Algorithms for more about drawing the Mandelbrot Set.
This work is licensed under a
Creative Commons Attribution 2.5 License
.