# Raster Scan

Robert P. Munafo, 2008 Mar 14.

The terms "raster scan" and grid scan refer to the most straightforward method of applying an operation to a set of items arranged in a rectangular grid. It is used whenever there are no considerations for speed optimization, interdependancy between elements, order of computation, or sundry other factors. In the case of the Mandelbrot Set, this means we're plotting all the points in the image with no regard for how they might be similar to nearby points, which means it will be relatively slow — but it's a simple approach and easy to implement. See Orbit Detection for one simple speed improvement, and Optimizations for pointers to several more.

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.

From the Mandelbrot Set Glossary and Encyclopedia, by Robert Munafo, (c) 1987-2022. Mu-ency index

This page was written in the "embarrassingly readable" markup language RHTF, and was last updated on 2008 Mar 15. s.27