function draw(p) {
let inversed = false;
return () => {
const img = mutable image;
if (img.width == 1 || img.height == 1) {
return;
}
if (inversed === false) {
img.loadPixels();
for (let y = 0; y < img.height; y++) {
for (let x = 0; x < img.width; x++) {
const c = img.get(x, y);
const r = 255 - p.red(c);
const g = 255 - p.green(c);
const b = 255 - p.blue(c);
let nc = p.color(r, g, b);
img.set(x, y, nc);
}
}
img.updatePixels();
inversed = true;
}
p.image(img, 0, 0);
};
}