//set up the class class Ball { float xpos; //will be the x pos float ypos; //will be the y pos int rad; //will be the radius float xincr; float yincr; float siner = 1.0; float sinAmt = 1.0; //The constructor inits all these properties passed from the new Ball(int x, int y, int r, int speed) { this.xpos = x; this.ypos = y; this.rad = r; if(speed == 0) { speed = speed + 1; } this.xincr = speed; this.yincr = speed; } //this is a method inside the ball class //the method is a member of the ball class void plot() { strokeWeight(2); stroke(125,255); ellipse(xpos,ypos,rad,rad); } //this method increments the x value void move() { //add some sin/cos action to give it a bit of wobble siner = siner+sinAmt; sinAmt ++; //add an increment to x xpos = xpos + xincr+(sin(siner)*5.0); ypos = ypos + yincr+(cos(siner)*5.0); //if it is greater than the right or less that the left if((xpos >= width) || (xpos <= 0)) { //reverse gear xincr = -xincr; attractRepel(); // change the particle attraction/repulsion in main script } //do the up and down version if((ypos >= height) || (ypos <= 0)) { //reverse gear yincr = -yincr; attractRepel(); // change the particle attraction/repulsion in main script } } }