class Ball { PVector pos; PVector vel; float rad; Ball entangle; boolean phaser; int dark; final float BALL_SIZE = 10; Ball(float X, float Y) { pos = new PVector(X, Y); vel = new PVector(); rad = BALL_SIZE; entangle = null; phaser = false; dark = 0; } //Check for the edges and bounce back so everything stays inside void WallCheck(float offset) { if( (0 - offset > pos.x) || (width + offset < pos.x)){ vel.x = -vel.x; pos.x = constrain(pos.x, 0, width); } if((0 - offset > pos.y) || (height + offset < pos.y)){ vel.y = -vel.y; pos.y = constrain(pos.y, 0, height); } } void Update() { WallCheck(30); pos.add(vel); } void Display() { // Check to make sure we have a full chain. if(entangle != null && entangle.entangle != null && entangle.entangle.entangle != null) { stroke(dark, 20); bezier(pos, entangle.pos, entangle.entangle.pos, entangle.entangle.entangle.pos); dark--; if (dark < 0) dark = 0; } } //Lock two balls together void Entangle(Ball B) { entangle = B; dark = 255; } //For if we need to kick a ball randomly (such as starting out) void Spur() { vel.add(new PVector(random(-.5, .5), random(-.5, .5))); } }