class Particle: def __init__(self, position, velocity=(0, 0), acceleration=(0, 0)): self.position = position self.velocity = velocity self.acceleration = acceleration self.history = [] def update(self): self.history.append(self) new_velocity = (self.velocity[0] + self.acceleration[0], self.velocity[1] + self.acceleration[1]) new_position = (self.position[0] + new_velocity[0], self.position[1] + new_velocity[1]) return Particle(new_position, new_velocity, self.acceleration) def undo(self): if self.history: return self.history.pop() return self