import { fmandelbrot, julia } from "./components/mandelbrot.js";
const colors = new Map();
const colorscale = d3
.scaleSequentialLog(d3.interpolateInferno)
.domain([1, MAX_ITER]);
for (let i = 1; i < MAX_ITER; i++) {
colors.set(i, colorscale(i));
}
colors.set(MAX_ITER, `rgb(0, 0, 0)`);
const brotCtx = document.querySelector("canvas#mcanv").getContext("2d");
const drawRow = (ctx, xscale, yscale, y = 0, rows = 80) => {
for (let i = 0; i < rows && y + i <= H; i++) {
for (let x = 0; x <= W; x++) {
const l = fmandelbrot([xscale(x), yscale(y + i)], MAX_ITER);
ctx.fillStyle = colors.get(l);
ctx.fillRect(x, y + i, 1, 1);
}
}
if (y < H) {
requestAnimationFrame(() => drawRow(ctx, xscale, yscale, y + rows, rows));
}
};
requestAnimationFrame(() => drawRow(brotCtx, state.xscale, state.yscale));