first commit
This commit is contained in:
commit
9615165024
21 files changed
+404
No files matched your search
@@ -0,0 +1,31 @@
|
||||
class Particle:
|
||||
def __init__(self, position, velocity=(0, 0), acceleration=(0, 0),old_version=None):
|
||||
self.position = position
|
||||
self.velocity = velocity
|
||||
self.acceleration = acceleration
|
||||
self.old_version = []
|
||||
|
||||
def update(self):
|
||||
self.old_version.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, self.old_version)
|
||||
|
||||
def undo(self):
|
||||
|
||||
return self.old_version.pop()
|
||||
|
||||
|
||||
p = Particle((0, 0), (1, 1), (1,1))
|
||||
|
||||
|
||||
new_p = p.update()
|
||||
old_p = p.undo()
|
||||
newnew_p = new_p.update()
|
||||
oldnew_p = new_p.undo()
|
||||
|
||||
print(new_p.position, new_p.velocity, new_p.acceleration, new_p.old_version)
|
||||
Reference in new issue
Block a user