Algorithms
Plasma Fractals
The generation of plasma fractals is discussed in the Types of Fractals section. Basically, the description you can find there is implemented in the algorithm below. The fractal is stored entirely in a 2-dimensional array and then the points from the array are plotted on the screen.
Constants used:
number_of_colors: number of colors available in the computer language you’re
using
size: size of the fractal; must be a power of 2
roughness: higher values make the fractal more fragmented
‘ randomly choose the rectangle’s corners
array(0, 0) = RND * number_of_colors
array(size, 0) = RND * number_of_colors
array(0, size) = RND * number_of_colors
array(size, size) = RND * number_of_colors
‘ go through the array, decreasing the interval size every time
FOR p = LOG(size) / LOG(2) TO 0 STEP -1
FOR x = 0 TO size STEP 2 ^ p
FOR y = 0 TO size STEP 2 ^ p
IF x MOD 2 ^ (p + 1) = 0 AND y MOD 2 ^ (p + 1) = 0 GOTO nxt
IF x MOD 2 ^ (p + 1) = 0 THEN
average = (array(x, y + 2 ^ p) + array(x, y - 2 ^ p)) / 2
color = average + roughness * (RND - .5)
array(x, y) = color: GOTO nxt
END IF
IF y MOD 2 ^ (p + 1) = 0 THEN
average = (array(x + 2 ^ p, y) + array(x - 2 ^ p, y)) / 2
color = average + roughness * (RND - .5)
array(x, y) = color: GOTO nxt
END IF
IF x MOD 2 ^ (p + 1) > 0 AND y MOD 2 ^ (p + 1) > 0 THEN
v1 = array(x + 2 ^ p, y + 2 ^ p)
v2 = array(x + 2 ^ p, x - 2 ^ p)
v3 = array(x - 2 ^ p, x + 2 ^ p)
v4 = array(x - 2 ^ p, y - 2 ^ p)
average = (v1 + v2 + v3 + v4) / 4
color = average + roughness * (RND - .5)
array(x, y) = color: GOTO nxt
END IF
nxt:
NEXT y
NEXT x
NEXT p
‘ go through the array, plotting the points
FOR x = 0 TO size
FOR y = 0 TO size
PSET (x, y), array(x, y)
NEXT y
NEXT x