A89: i need math and programming help!!
[Prev][Next][Index][Thread]
A89: i need math and programming help!!
alright, below is a segment of code from a mandelbrot generator.
can anyone explain to me how this code segment relates to the mandelbrot
fractal equation
z = z^2 + c
?? i am trying to understand this code so i can revise it for a julia set,
which is related to the mandelbrot fractal. can anyone help me out?
--- Begin Code ---
void mandel(int nx, int ny, /* screen size */
long double xmin, long double xmax, /* min and max on x axis */
long double ymin, long double ymax, /* min and max on y axis */
unsigned maxiter)
{
short ix, iy;
unsigned iter;
long double cx, cy;
long double x, y, x2, y2, temp;
char s[80];
sprintf(s, "%8.7Lg L=%8.7Lg %8.7Lg L=%8.7Lg N <%d",
xmin, xmax - xmin,
ymin, ymax - ymin,
maxiter);
setcolor(MC);
outtextxy(100, ny - 10, s);
for(iy = 0; iy < ny - 12; iy++)
{
if(kbhit())
return;
cy = ymin + iy * (ymax - ymin) / (ny - 1);
setfillstyle(SOLID_FILL, MC);
bar(1, ny - 10, 70, ny);
setcolor(0);
sprintf(s, "%8.7Lg", cy);
outtextxy(1, ny - 8, s);
for(ix = 0; ix < nx; ix++)
{
cx = xmin + ix * (xmax - xmin) / (nx - 1);
x = y = x2 = y2 = 0.0;
iter = 0;
while(iter < maxiter && (x2 + y2) < 4.0 /* 10000.0 ??? */ )
{
temp = x2 - y2 + cx;
y = 2 * x * y + cy;
x = temp;
x2 = x * x;
y2 = y * y;
iter++;
}
putpixel(ix, iy, iter);
}
}
}
--- End Code ---
/brian
The path to enlightenment is /usr/ports/x11-wm/englightenment