def step(self): """Randomly move up, down, left, right or stay in one place.""" choice = random() if choice < 0.4: self.x += 1 elif choice < 0.6: self.x -= 1 elif choice < 0.8: self.y += 1 else: self.y -= 1 self.x = p.constrain(self.x, 0, width-1); self.y = p.constrain(self.y, 0, height-1);
def attract(self, m): force = p.PVector.sub(self.location, m.location) d = force.mag() d = p.constrain(d,5.,25.) force.normalize() strength = G*(self.mass*m.mass)/(d**2) force.mult(strength) return force