class Follower { int posX, posY; float vecX, vecY; float easing = .0008; Follower() { //init position and direction posX = int(random(0, width)); posY = int(random(0, height)); vecX = random(-2, 2); vecY = random(-2, 2); } void updatePosition(Leader l) { //add some noise vecX +=random( -1,1); vecY +=random( -1,1); //aim at the leader, but don't accelerate too much vecX += (l.getPositionX() - posX) * easing; vecX = constrain(vecX, -random(1,5), random(1,5)); vecY += (l.getPositionY() - posY) * easing; vecY = constrain(vecY, -random(1,5), random(1,5)); //this max of magnitude 3 is why they all move exactly the same. //update position posX += vecX; posY += vecY; } void draw() { fill(255,25, 0); ellipse(posX, posY, 4, 4); } }