Skip to content

Instantly share code, notes, and snippets.

@md2perpe
Created December 30, 2019 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save md2perpe/3bf29f90935c2eac722a73b14e7d22eb to your computer and use it in GitHub Desktop.
Save md2perpe/3bf29f90935c2eac722a73b14e7d22eb to your computer and use it in GitHub Desktop.
Mandelbrot
#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