Ball ball1; Ball ball2; void setup(){ size(400,400); smooth(); ball1=new Ball(64); ball2=new Ball(32); } void draw(){ background(255); ball1.move(); ball2.move(); if (ball1.intersect (ball2)){ ball1.highlight(); ball2.highlight(); } ball1.display(); ball2.display(); } class Ball{ float r; float x,y; float xspeed, yspeed; color c = color(100,50); Ball(float tempR){ r=tempR; x=random(width); y=(height); xspeed=random(-5,5); yspeed=random(-5,5); } void move(){ x += xspeed; y += yspeed; if (x>width || x<0){ xspeed *= -1; } if (y>height || y<0){ yspeed *= -1; } } void highlight(){ c=color(0,150); } void display(){ stroke(0); fill(c); ellipse(x,y,r*2,r*2); c=color(100,50); } boolean intersect(Ball b){ float distance = dist(x,y,b.x,b.y); if (distance < r + b.r){ return true; }else{ return false; } } }