Collision

The first step is to see if a value is over a line. in this case a ball will bounce off the wall.
float ballx = 200;
float bally = 200;
float speed = 2.0;

void setup(){
size (400, 400);
}

void draw() {
background(100);
smooth();
ballx += speed;
if (ballx > width) {
speed = speed * -1;
}
ellipse (ballx, bally, 20, 20);
}


Collisions between a ball and a rect get a bit trickier.
int boxX = 200;
int boxY = 200;
int boxwidth = 100;
int boxheight = 50;
int ballsize = 30;

void setup(){
size (400, 400);
}

void draw() {
smooth();
background(100);
if (((mouseX > boxX - ballsize/2) && (mouseX < boxX + boxwidth + ballsize/2)) && ((mouseY > boxY - ballsize/2) && (mouseY < boxY + boxheight + ballsize/2))){
fill(250, 0, 0);
}
else{
fill(250, 250, 250);
}
rect (boxX, boxY, boxwidth, boxheight);
ellipse (mouseX, mouseY, ballsize, ballsize);
}


If two circles are colliding, we can use dist() to calculate the distance between the two circles.
int ballx = 180;
int bally = 210;
int ballsize2 = 60;
int ballsize = 30;

void setup(){
size (400, 400);
}
void draw() {
smooth();
float distance = dist( ballx, bally, mouseX, mouseY);
if (distance > ballsize/2 + ballsize2/2){
background(250, 0, 0);
}
else
{
background(0, 250, 0);
}
ellipse (mouseX, mouseY, ballsize, ballsize);
ellipse (ballx, bally, ballsize2, ballsize2);
}