Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save PhoenixGameDevelopment/c02c59c2ef1cd3fe58a473e73ca91b72 to your computer and use it in GitHub Desktop.
Save PhoenixGameDevelopment/c02c59c2ef1cd3fe58a473e73ca91b72 to your computer and use it in GitHub Desktop.
Simple AI-Generated Program to Display the Mandlebrot set
using System.Drawing;
using System.Windows.Forms;
class Mandelbrot : Form
{
const int MaxIterations = 1000;
const double Zoom = 300;
public Mandelbrot()
{
Text = "Mandelbrot Set";
ClientSize = new Size(800, 600);
DoubleBuffered = true;
Paint += (sender, e) =>
{
for (int y = 0; y < Height; y++)
{
for (int x = 0; x < Width; x++)
{
double zx = 0, zy = 0;
double cx = (x - Width / 2) / Zoom;
double cy = (y - Height / 2) / Zoom;
int iter = MaxIterations;
while (zx * zx + zy * zy < 4 && iter > 0)
{
double tmp = zx * zx - zy * zy + cx;
zy = 2 * zx * zy + cy;
zx = tmp;
iter--;
}
Color c = iter == 0 ? Color.Black : Color.FromArgb(
iter % 8 * 32,
iter % 16 * 16,
iter % 32 * 8);
e.Graphics.FillRectangle(new SolidBrush(c), x, y, 1, 1);
}
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment