SketchBook

var rad = 200;
var xpos, ypos=200;

var xspeed = 2.8;
var yspeed = 2.2;

var xdirection = 10;
var ydirection = 200;

function setup() {
createCanvas(windowWidth,
windowHeight);
noStroke();
ellipseMode(RADIUS);

xpos = width / 2;
ypos = height / 2;
}

function draw() {
background(100, 100, 100);
fill(200, 100, 200);

xpos = xpos + xspeed * xdirection;
ypos = ypos + yspeed * ydirection;

if (xpos > width - rad || xpos < rad) {
xdirection *= -1;
}

if (ypos > height - rad || ypos < rad) {
ydirection *= -1;
}

ellipse(xpos, ypos, rad, rad);
}