xxxxxxxxxx
22
var position = 0;
var speed = 2;
function setup() {
createCanvas(400, 400);
background(200);
}
function draw() {
background(200);
var redValue = map(position, 0, width, 0, 255);
fill(redValue, 100, 100);
ellipse(position, height/2, 50, 50);
position = position + speed;
if (position > width) {
speed = -2;
} else if (position < 0) {
speed = 2;
}
}