Skip to content

Commit bf22800

Browse files
committed
some improvements to the Mandelbrot Set example
1 parent c4fc93a commit bf22800

File tree

1 file changed

+5
-4
lines changed
  • content/examples/Topics/Fractals and L-Systems/Mandelbrot

1 file changed

+5
-4
lines changed

content/examples/Topics/Fractals and L-Systems/Mandelbrot/Mandelbrot.pde

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ background(255);
1313
// A different range will allow us to "zoom" in or out on the fractal
1414

1515
// It all starts with the width, try higher or lower values
16-
float w = 5;
16+
float w = 4;
1717
float h = (w * height) / width;
1818

1919
// Start at negative half the width and height
@@ -54,7 +54,7 @@ for (int j = 0; j < height; j++) {
5454
a = aa - bb + x;
5555
b = twoab + y;
5656
// Infinty in our finite world is simple, let's just consider it 16
57-
if (aa + bb > 16.0) {
57+
if (dist(aa, bb, 0, 0) > 4.0) {
5858
break; // Bail
5959
}
6060
n++;
@@ -66,10 +66,11 @@ for (int j = 0; j < height; j++) {
6666
pixels[i+j*width] = color(0);
6767
} else {
6868
// Gosh, we could make fancy colors here if we wanted
69-
pixels[i+j*width] = color(n*16 % 255);
69+
float norm = map(n, 0, maxiterations, 0, 1);
70+
pixels[i+j*width] = color(map(sqrt(norm), 0, 1, 0, 255));
7071
}
7172
x += dx;
7273
}
7374
y += dy;
7475
}
75-
updatePixels();
76+
updatePixels();

0 commit comments

Comments
 (0)