boolean negXVelocity = false; boolean negYVelocity = false; Ball myBall; Ball myBall2; void setup() { size(500,500); background(0); myBall=new Ball(10,10,random(30),1); myBall2=new Ball(10,10,random(20),20); } void draw() { background(0); myBall.drawBall(); myBall.move(); myBall2.drawBall(); myBall2.move(); //a "vector" (really a point) to store the mouse location and screen center location Vector2D mouseLoc = new Vector2D(myBall.getX(), myBall.getX()); Vector2D centerLoc = new Vector2D(myBall2.getX(), myBall2.getY()); //aha, a real vector to store the displacement between the mouse and center Vector2D v = Vector2D.sub(mouseLoc,centerLoc); //call a function to render a vector at a location (we might use this later for debugging in other programs) drawVector(v,centerLoc,1.0f); } void drawVector(Vector2D v, Vector2D loc, float scayl) { push(); float arrowsize = 10; //translate to location to render vector translate(loc.getX(),loc.getY()); stroke(255); noFill(); //call vector heading function to get direction (note that pointing up is a heading of 0) and rotate rotate(v.heading()); //calculate length of vector & scale it to be bigger or smaller if necessary float len = v.magnitude()*scayl; //draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction) line(0,0,len,0); // line(len,0,len-arrowsize,+arrowsize/2); // line(len,0,len-arrowsize,-arrowsize/2); // pop(); }