Back
| Home
Mandelbrot
Fractal
This is an advanced Game-Editor Drawing Demo - meaning only the C-scripts are
provided and you should already know the mechanics of starting a canvas actor,
adding scripts, etc. If you are not at this level, please see the Let's
DRAW! Basic Drawing Tutorial.

MANDELBROT
FRACTAL
//
Simple Mandelbrot Fractal
// Based on C code by Karthik Narayanaswami
//
http://www.metlin.org/graphics/fractals.html
int
sx=320;
int sy=240;
double xmin=-2;
double xmax=1.25;
double ymin=-1.25;
double
ymax=1.25;
int maxiter=96;
double
old_x;
double fx,fy;
int m;
double
dx=(xmax-xmin)/sx;
double dy=(ymax-ymin)/sy;
int
px;
int py=0;
double x;
double y=ymin;
while
(py<sy) {
px=0;
x=xmin;
py++;
while (px<sx) {
px++;
fx=0;
fy=0;
m=0;
do
{
old_x=fx;
fx=fx*fx-fy*fy+x;
fy=2*old_x*fy+y;
m++;
} while
(((fx*fx+fy*fy)<4) && (m<maxiter));
setpen(m,m,m,0,1);
putpixel(px,py);
x+=dx;
}
y+=dy;
}
Fractals
The
frontier where Art and Science meet.

See our new game site