p5(sketch => {
let x = 200;
let y = 200;
let extraCanvas;
sketch.setup = function() {
sketch.createCanvas(width, 400);
extraCanvas = sketch.createGraphics(width, 400);
extraCanvas.clear();
};
sketch.draw = function() {
sketch.background(0, 10);
x += sketch.random(-5, 5);
y += sketch.random(-5, 5);
if (sketch.mouseIsPressed) {
extraCanvas.fill(255, 200);
extraCanvas.noStroke();
extraCanvas.circle(sketch.mouseX, sketch.mouseY, 50);
}
sketch.image(extraCanvas, 0, 0);
sketch.fill(255, 0, 0);
sketch.noStroke();
sketch.rectMode(sketch.CENTER);
sketch.rect(x, y, 40, 40);
};
})