Skip to content

Instantly share code, notes, and snippets.

@a3f
Last active August 29, 2015 14:26
Show Gist options
  • Save a3f/7738c2086b6a636cfd75 to your computer and use it in GitHub Desktop.
Save a3f/7738c2086b6a636cfd75 to your computer and use it in GitHub Desktop.
#include <windows.h>
#include <conio.h>
#include <stdlib.h>
char *title = "Mandelbrot Set";
#define SIZE 600
#define ITERS 25
int main()
{
int x, y, i;
double zx, zy, cx, cy, tmp;
HWND hwnd;
HDC hdc;
system("cls");
SetConsoleTitle(title);
hwnd = FindWindow(NULL, title);
hdc = GetDC(hwnd);
/***/
for (y = 1; y < SIZE; y++)
for (x = 1; x < SIZE; x++)
{
zx = cx = -2+2.5*x/SIZE;
zy = cy = -1.25+2.5*y/SIZE;
for (i = 0; i < ITERS; i++)
{
tmp = zx * zx - zy * zy + cx;
zy = 2.0 * zx * zy + cy;
zx = tmp;
if (zx*zx + zy*zy > 4) break;
}
i = 250 - 250/ITERS*i;
SetPixel(hdc, x, y, RGB(i,i,i));
}
/***/
ReleaseDC(hwnd, hdc);
DeleteDC(hdc);
_getch();
return(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment