Created
December 30, 2019 19:53
-
-
Save md2perpe/3bf29f90935c2eac722a73b14e7d22eb to your computer and use it in GitHub Desktop.
Mandelbrot
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> | |
#define R 50 | |
#define C 150 | |
#define K 50 | |
int main() | |
{ | |
int r, c; | |
for (r=0; r<R; r++) | |
{ | |
for (c=0; c<C; c++) | |
{ | |
double x = 0; | |
double y = 0; | |
double x0 = -2.5 + 4.0 * ((double)c)/C; | |
double y0 = -1.5 + 3.0 * ((double)r)/R; | |
int k; | |
for (k=0; k<K; k++) | |
{ | |
if (x*x + y*y > 2.0) | |
{ | |
printf(" "); | |
break; | |
} | |
double xnew = x*x - y*y + x0; | |
double ynew = 2*x*y + y0; | |
x = xnew; | |
y = ynew; | |
} | |
if (k == K) | |
printf("*"); | |
} | |
printf("\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment