Created
June 15, 2020 06:33
-
-
Save choas/2f4876f5392980ef742a46dde3ba9901 to your computer and use it in GitHub Desktop.
Mandelbrot Set calculation with complex.h
This file contains 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
#include <stdio.h> | |
#include <complex.h> | |
int main(void) | |
{ | |
double xl = -2.0; | |
double xu = 0.5; | |
double yl = -1.1; | |
double yu = 1.1; | |
int reps = 20; | |
int width = 40; | |
int height = 25; | |
double xinc = (xu - xl) / width; | |
double yinc = (yu - yl) / height; | |
for (int j = 0; j < height; j++) | |
{ | |
for (int i = 0; i < width; i++) | |
{ | |
double nreal = xl + i * xinc; | |
double nimg = yl + j * yinc; | |
double complex c = nreal + nimg * I; | |
double complex z = 0 + 0 * I; | |
char out = ' '; | |
for (int k = 1; k <= reps; k++) | |
{ | |
z = cpow(z, 2) + c; | |
if (cabs(z) > 2.0) | |
{ | |
out = 'A' + (k / 2); | |
break; | |
} | |
} | |
printf("%c", out); | |
} | |
printf("\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment