calculateMandelbrotSet = gpu.createKernel(function(zoomCenter, zoomSize, maxIterations) {
let x = [0, 0];
let c = [
zoomCenter[0] + ((this.thread.x / this.output.x) * 4 - 2) * (zoomSize / 4),
zoomCenter[1] + ((this.thread.y / this.output.y) * 4 - 2) * (zoomSize / 4)
];
let escaped = false;
let iterations = 0;
for (let i = 0; i < maxIterations; i++) {
iterations = i;
x = f(x, c);
if (vectorLength(x) > 2) {
escaped = true;
break;
}
}
if (escaped) {
const pixel = palette(iterations / maxIterations, [0, 0, 0], [.59, .55, .75], [.1, .2, .3], [.75, .75, .75]);
this.color(pixel[0], pixel[1], pixel[2], 1);
} else {
this.color(.85, .99, 1, 1);
}
})
.setGraphical(true)
.setOutput([800, 800]);