xxxxxxxxxx
37
let x = 200;
let y = 200;
let extraCanvas;
function setup() {
createCanvas(400, 400);
extraCanvas = createGraphics(400, 400);
extraCanvas.clear();
background(0);
}
function draw() {
// No trails!
background(0);
x += random(-10, 10);
y += random(-10, 10);
if(x < 0 || x > width) x = 200;
if(y < 0 || y > height) y = 200;
// trails
if (mouseIsPressed) {
extraCanvas.fill(255, 150);
extraCanvas.noStroke();
extraCanvas.ellipse(mouseX, mouseY, 60, 60);
}
image(extraCanvas, 0, 0);
fill(255, 0, 220);
stroke(255, 200, 200);
strokeWeight(2);
rectMode(CENTER);
rect(min(max(0,x), width), min(max(0,y), width), 20, 20);
}