class Leader { int posX, posY; float vecX, vecY; Leader() { posX = int(random(width,height)); posY = int(random(width,height)); vecX = .5; vecY = .5; } void updatePosition(int xpos,int ypos) { //add some noise to the direction vector vecX = constrain( vecX + random( -1,1), -6, 6); vecY = constrain( vecY + random( -1,1), -6, 6); //if we're going to go off the screen, adjust the motion vector. if ((posX + vecX >= xpos) || (posX + vecX <= xpos-100)) vecX = -vecX; if ((posY + vecY >= ypos) || (posY + vecY <= ypos-100)) vecY = -vecY; //update position posX += vecX; posY += vecY; } void draw() { fill(255, 0,0); ellipse(posX, posY, 2, 2); } int getPositionX() {return posX;} int getPositionY() {return posY;} }