InfoBox "Calculating... Wait..." SetBrushColor 0 DrawRect 0,0,640,200 RANDOMIZE roughness = 82 ' roughness: higher values make the fractal more fragmented number_of_colors = 128 ' number of colors available size = 128 ' size: size of the fractal; must be a power of 2 dim array(size,size) as integer ' 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 p = LOG(size) / LOG(2) while p >= 0 x = 0 while x <= size y = 0 while y<= size IF Not (x % 2 ^ (p + 1) = 0 AND y % 2 ^ (p + 1) = 0) then IF x % 2 ^ (p + 1) = 0 THEN average = (array(x, y + 2 ^ p) + array(x, y - 2 ^ p)) / 2 color = average + roughness * (RND() - 0.5) array(x, y) = color ELSEIF y % 2 ^ (p + 1) = 0 THEN average = (array(x + 2 ^ p, y) + array(x - 2 ^ p, y)) / 2 color = average + roughness * (RND() - 0.5) array(x, y) = color ELSEIF x % 2 ^ (p + 1) > 0 AND y % 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 - 0.5) array(x, y) = color END IF End if y = y+2^p wend ' y x = x+2^p wend ' x p = p - 1 wend 'p ' go through the array, plotting the points z = 0 while z<3 x = 0 while x <= size*2 y = 0 while y <=size*2 c = array(x/2, y/2) c = 127 + c SetBrushColor Rgb(c,c/2,c/2) SetPenColor Rgb(c,c/2,c/2) DrawRect z*2*size+x-1,y-1,z*2*size+x+1,y+1 y = y + 2 wend x=x+2 wend z = z+1 wend SetPenColor 0 DrawText "Press any key to exit", 450,185 while not readkey wend