Ball[] balls; Vect2D[] vels; PFont font; void setup() { size(800, 450); frameRate(30); // load fonts font = createFont("myfont.ttf", 10); smooth(); noStroke(); balls = new Ball[100]; vels = new Vect2D[100]; for (int i = 0; i < 100; i++) { float x = random(0, width); float y = random(0, height); float r = random(5, 40); balls[i] = new Ball(x, y, r, "Label Here"); float vx = random(-0.2, 0.2); float yx = random(-0.2, 0.2); vels[i] = new Vect2D(vx, yx); } } void draw() { background(#333333); for (int i = 0; i < 100; i++) { fill(#777777, 170); noStroke(); balls[i].x += vels[i].vx; balls[i].y += vels[i].vy; ellipse(balls[i].x, balls[i].y, balls[i].r*2, balls[i].r*2); // text label fill(255); textAlign(CENTER); textFont(font); textSize(balls[i].r * 0.4); text(balls[i].artist, balls[i].x, balls[i].y); checkBoundaryCollision(balls[i], vels[i]); } // fps display textAlign(LEFT); textSize(12); fill(255); text("fps: " + frameRate, 10,14); } void checkBoundaryCollision(Ball ball, Vect2D vel){ if (ball.x > width-ball.r){ ball.x = width-ball.r; vel.vx *= -1; } else if (ball.x < ball.r){ ball.x = ball.r; vel.vx *= -1; } else if (ball.y > height-ball.r){ ball.y = height-ball.r; vel.vy *= -1; } else if (ball.y < ball.r){ ball.y = ball.r; vel.vy *= -1; } } class Ball { float x, y, r; String artist; // default constructor Ball() { } Ball(float x, float y, float r, String artist) { this.x = x; this.y = y; this.r = r; this.artist = artist; } } class Vect2D{ float vx, vy; // default constructor Vect2D() { } Vect2D(float vx, float vy) { this.vx = vx; this.vy = vy; } }