Skip to content

Instantly share code, notes, and snippets.

@cosinekitty
Created February 25, 2020 01:22
Show Gist options
  • Save cosinekitty/2e3acc5b83c0c8596254897ed8233b9f to your computer and use it in GitHub Desktop.
Save cosinekitty/2e3acc5b83c0c8596254897ed8233b9f to your computer and use it in GitHub Desktop.
C++ implementation of the Mandelbrot Set function
static int Mandelbrot(double cr, double ci, int limit)
{
int count = 0;
double zr = 0.0;
double zi = 0.0;
double zr2 = 0.0;
double zi2 = 0.0;
while ((count < limit) && (zr2 + zi2 < 4.001))
{
double tzi = 2.0*zr*zi + ci;
zr = zr2 - zi2 + cr;
zi = tzi;
zr2 = zr*zr;
zi2 = zi*zi;
++count;
}
return count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment