Mandelbrot Fractal
by Stan Munson
Mandelbrot creates a complicated but beautiful fractal image.
When it is done, look away for a couple of seconds, then back at the large dark spot.
It may seem to grow a little bigger. It’s an optical illusion.
For another example of an optical illusion, see Hermann Grid.
Mandelbrot.lgo
TO CALC :COMPLEXREAL :COMPLEXIMG
(LOCAL "LAST_Z "AZ "BZ "AA "BB)
MAKE "LAST_Z 0
MAKE "AZ :COMPLEXREAL
MAKE "BZ :COMPLEXIMG
FOR [REP 1 250] [
MAKE "AA :AZ * :AZ
MAKE "BB :BZ * :BZ
IF :AA + :BB > 4 [
OUTPUT :REP + (:LN22 - (LN LN SQRT :AA + :BB)) / (LN 2)
]
MAKE "BZ 2 * :AZ * :BZ + :COMPLEXIMG
MAKE "AZ :AA - :BB + :COMPLEXREAL
]
OUTPUT 0
END
TO MANDELBROT :WIDTH :HEIGHT
LMAKE "START MILLISECONDS
DRAW HT
LMAKE "MAXX ROUND :WIDTH / 2
LMAKE "MINX -:MAXX
LMAKE "MAXY ROUND :HEIGHT / 2
LMAKE "MINY -:MAXY
PU SETXY LIST :MINX :MINY PD
STAMPRECT :WIDTH :HEIGHT
FOR (LIST "X :MINX :MAXX) [
FOR (LIST "Y :MINY :MAXY) [
; address turtle 0 directly to save time
PPROP 0 "PENCOLOR AGET :MANDEL.COLORS INT (CALC :CENTERX + :X / :SCALE :CENTERY + :Y / :SCALE)
(CPROP 0 "DOT LIST :X :Y)
]
]
(PR (MILLISECONDS - :START) / 1000 "|Seconds|)
END
TO MAIN
DRAW
PRINT "|Mandelbrot creates a complicated but beautiful fractal image. |
PRINT "|When it's done, look away for a couple of seconds then back |
PRINT "|at the large dark spot. It may seem to grow a little bigger.|
TYPE "|It's an optical illusion.|
MANDELBROT 400 400
END
MAIN
; Names
MAKE "WIDTH 100
MAKE "HEIGHT 100
MAKE "SCALE 100000
MAKE "CENTERX -0.41926
MAKE "CENTERY 0.58467
MAKE "MANDEL.COLORS {[0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [7 0 0] [14 0 0] [21 0 0] [28 0 0] [35 0 0] [43 0 0] [50 0 0] [57 0 0] [64 0 0] [71 0 0] [78 0 0] [85 0 0] [92 0 0] [99 0 0] [106 0 0] [113 0 0] [120 0 0] [128 0 0] [135 0 0] [142 0 0] [149 0 0] [156 0 0] [163 0 0] [170 0 0] [177 0 0] [184 0 0] [191 0 0] [198 0 0] [205 0 0] [213 0 0] [220 0 0] [227 0 0] [234 0 0] [241 0 0] [248 0 0] [255 0 0] [255 7 0] [255 14 0] [255 21 0] [255 28 0] [255 35 0] [255 43 0] [255 50 0] [255 57 0] [255 64 0] [255 71 0] [255 78 0] [255 85 0] [255 92 0] [255 99 0] [255 106 0] [255 113 0] [255 120 0] [255 128 0] [255 135 0] [255 142 0] [255 149 0] [255 156 0] [255 163 0] [255 170 0] [255 177 0] [255 184 0] [255 191 0] [255 198 0] [255 205 0] [255 213 0] [255 220 0] [255 227 0] [255 234 0] [255 241 0] [255 248 0] [255 255 0] [248 255 0] [241 255 0] [234 255 0] [227 255 0] [220 255 0] [213 255 0] [205 255 0] [198 255 0] [191 255 0] [184 255 0] [177 255 0] [170 255 0] [163 255 0] [156 255 0] [149 255 0] [142 255 0] [135 255 0] [128 255 0] [120 255 0] [113 255 0] [106 255 0] [99 255 0] [92 255 0] [85 255 0] [78 255 0] [71 255 0] [64 255 0] [57 255 0] [50 255 0] [42 255 0] [35 255 0] [28 255 0] [21 255 0] [14 255 0] [7 255 0] [0 255 0] [0 255 7] [0 255 14] [0 255 21] [0 255 28] [0 255 35] [0 255 43] [0 255 50] [0 255 57] [0 255 64] [0 255 71] [0 255 78] [0 255 85] [0 255 92] [0 255 99] [0 255 106] [0 255 113] [0 255 120] [0 255 128] [0 255 135] [0 255 142] [0 255 149] [0 255 156] [0 255 163] [0 255 170] [0 255 177] [0 255 184] [0 255 191] [0 255 198] [0 255 205] [0 255 213] [0 255 220] [0 255 227] [0 255 234] [0 255 241] [0 255 248] [0 255 255] [0 248 255] [0 241 255] [0 234 255] [0 227 255] [0 220 255] [0 213 255] [0 205 255] [0 198 255] [0 191 255] [0 184 255] [0 177 255] [0 170 255] [0 163 255] [0 156 255] [0 149 255] [0 142 255] [0 135 255] [0 128 255] [0 120 255] [0 113 255] [0 106 255] [0 99 255] [0 92 255] [0 85 255] [0 78 255] [0 71 255] [0 64 255] [0 57 255] [0 50 255] [0 42 255] [0 35 255] [0 28 255] [0 21 255] [0 14 255] [0 7 255] [0 0 255] [0 0 248] [0 0 241] [0 0 234] [0 0 227] [0 0 220] [0 0 213] [0 0 205] [0 0 198] [0 0 191] [0 0 184] [0 0 177] [0 0 170] [0 0 163] [0 0 156] [0 0 149] [0 0 142] [0 0 135] [0 0 128] [0 0 120] [0 0 113] [0 0 106] [0 0 99] [0 0 92] [0 0 85] [0 0 78] [0 0 71] [0 0 64] [0 0 57] [0 0 50] [0 0 42] [0 0 35] [0 0 28] [0 0 21] [0 0 14] [0 0 7] []}
MAKE "LN22 0.326634259978281
MAIN
Procedure | MAIN |
Description | Mandelbrot Fractal |
Level | Advanced |
Tags | Math |