基于 Daniel Shiffman 为 Processing 创建的 Mandelbrot 集例子,对 Mandelbrot 集进行了色彩丰富的渲染。
function setup() {
createCanvas(710, 400);
pixelDensity(1);
describe('Colorful rendering of the Mandelbrot set.');
background(0);
// Establish a range of values on the complex plane
// Different width values change the zoom level
let w = 4;
let h = (w * height) / width;
// Start at negative half the width and height
let xMin = -w / 2;
let yMin = -h / 2;
// Access the pixels[] array
loadPixels();
// Set the maximum number of iterations for each point on the complex plane
let maxIterations = 100;
// x goes from xMin to xMax
let xMax = xMin + w;
// y goes from yMin to yMax
let yMax = yMin + h;
// Calculate amount we increment x,y for each pixel
Mandelbrot 集 by p5.js Contributors and the Processing Foundation is licensed under CC BY-NC-SA 4.0.