Skip to content

Instantly share code, notes, and snippets.

@camilajenny
Created September 7, 2025 19:56
Show Gist options
  • Save camilajenny/843f9bff8e4eb2991e155868a8819049 to your computer and use it in GitHub Desktop.
Save camilajenny/843f9bff8e4eb2991e155868a8819049 to your computer and use it in GitHub Desktop.
Mandelbrot image for Processing
int maxIter = 100; // maximum iterations
float zoom = 200; // zoom level
float offsetX = 0; // horizontal shift
float offsetY = 0; // vertical shift
void setup() {
size(800, 800);
loadPixels();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
// Map pixel to complex plane
float a = map(x, 0, width, -2.5, 1) + offsetX;
float b = map(y, 0, height, -1.5, 1.5) + offsetY;
float ca = a;
float cb = b;
int n = 0;
while (n < maxIter) {
float aa = a * a - b * b;
float bb = 2 * a * b;
a = aa + ca;
b = bb + cb;
if (abs(a + b) > 16) {
break;
}
n++;
}
// Map iteration count to color
float bright = map(n, 0, maxIter, 0, 255);
if (n == maxIter) bright = 0;
color col = color(bright, bright * 0.5, 255 - bright);
pixels[x + y * width] = col;
}
}
updatePixels();
}
void draw() {
// Nothing needed here, static image
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment