Skip to content

Instantly share code, notes, and snippets.

@a3f
Last active August 29, 2015 14:26
Show Gist options
  • Save a3f/3cfc2621111ef0d45295 to your computer and use it in GitHub Desktop.
Save a3f/3cfc2621111ef0d45295 to your computer and use it in GitHub Desktop.
#include <windows.h>
#include <conio.h>
#include <stdlib.h>
#include <complex.h>
#include <math.h>
const char *title = "Mandelbrot Set";
#define SIZE 600
#define ITERS 25
int main(void)
{
system("cls");
SetConsoleTitle(title);
HWND hwnd = FindWindow(NULL, title); // Get the HWND
HDC hdc = GetDC(hwnd); // Get the DC from that HWND
/***/
for (int y = 1; y < SIZE; y++)
for (int x = 1; x < SIZE; x++)
{
complex double c = -2 + 2.5*x/SIZE +I*(-1.25 + 2.5*y/SIZE);
complex double z = c;
int i;
for (i = 0; i < ITERS && cabs(z) < 4.0; i++)
z = z*z + c;
i = 250 - 250/ITERS*i;
SetPixel(hdc, x, y, RGB(i,i,i));
}
/***/
ReleaseDC(hwnd, hdc); // Release the DC
DeleteDC(hdc); // Delete the DC
_getch();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment