pixels = {
function f (px, py) {
function assert (b, e) {if (!b) throw new Error (e)}
assert (px < width, `px ${px} >= width ${width}`)
assert (py < height, `px ${px} >= height ${height}`)
const xto1 = px / width
const x0 = -2.5 + xto1 * 3.5
const yto1 = py / height
const y0 = -1 + yto1 * 2
let x = 0.0, y = 0.0, it, escapeTime = 256
for (it = 0; it < escapeTime; ++it) {
if (x*x + y*y > 2*2) break
const xtemp = x*x - y*y + x0
y = 2*x*y + y0
x = xtemp}
const colors = 256
const color = Math.floor (it * colors / escapeTime)
return color}
window.mandelbrot = f
let pixels = [], colored = 0
for (let y = 0; y < height; ++y) for (let x = 0; x < width; ++x) {
const color = f (x, y)
pixels.push (color)
if (color != 0) ++colored}
window.pixels = pixels
return md`Calculated ${pixels.length} pixels, ${colored} of them with color.`}