Created
December 1, 2012 09:25
-
-
Save tuttlem/4181270 to your computer and use it in GitHub Desktop.
Mandelbrot - frame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void mandelbrot_frame(double zoom, int max_iter, int xofs, int yofs) { | |
double zx = 0, zy = 0, cx = 0, cy = 0; | |
/* enumerate all of the rows */ | |
for (int y = 0; y < 200; y ++) { | |
/* enumerate all of the columns */ | |
for (int x = 0; x < 320; x ++) { | |
/* initialize step variables */ | |
zx = zy = 0; | |
cx = (x - xofs) / zoom; | |
cy = (y - yofs) / zoom; | |
int iter = max_iter; | |
/* calculate the iterations at this particular point */ | |
while (zx * zx + zy * zy < 4 && iter > 0) { | |
double tmp = zx * zx - zy * zy + cx; | |
zy = 2.0 * zx * zy + cy; | |
zx = tmp; | |
iter --; | |
} | |
/* plot the applicable pixel */ | |
video[x + (y * 320)] = (unsigned char) iter & 0xff; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment