xxxxxxxxxx
27
// Code that describes the starting position of a shape that will move
let x = 50;
let y= 50;
// Code to create a 400x400 canvas
function setup() {
createCanvas(400, 400);
// Code to draw a gray background
background(220);
}
// Code to draw the shape
function draw() {
rect(x, y, 50, 50);
// Code that describes mouse interaction
if(mouseX > x && mouseX < x + 50) {
x = mouseX;
}
// Code that changes the position of the shape over time
x++;
}