xxxxxxxxxx
25
var rectX = -50;
function setup() {
createCanvas(400, 400);
}
function draw() {
background(0);
fill(200, 0, 100);
rect(rectX, 200, 50, 50);
// Move the rectangle
rectX+=4;
// When the rectangle reaches the edge of the canvas,
// move it back to the left
if (rectX > width){
rectX = -50; // -50 so it appears nicely
}
// For debugging
//console.log(rectX);
}