Skip to content

Instantly share code, notes, and snippets.

@davidblitz
Last active July 11, 2017 20:33
Show Gist options
  • Save davidblitz/601685ebabca9280a8ea1b8c2d20fbf4 to your computer and use it in GitHub Desktop.
Save davidblitz/601685ebabca9280a8ea1b8c2d20fbf4 to your computer and use it in GitHub Desktop.
Mandelbrot Fractal in Terminal with Zoom
int main() {
double z_factor = 2; //zoom factor
double center_x = -0.5; //x coordinate of zoom center
double center_y = 0; //y coordinate of zoom center
double width = 128;
double height = 40;
int k = 0;
double i, j, r, x, y = -height/2;
while(puts(""), y++ < height/2 + 1) {
for(x = 0; x++<width;) {
if(k == 10001) putchar(' ');
else putchar('.');
for(i=k=r=0;
j = r*r - i*i + x/(25*z_factor) + center_x - width/(2*25*z_factor), i = 2*r*i+y/(10*z_factor) + center_y, j*j + i*i <= 2.0 && k++<10000;
r = j);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment