Alle Aufgaben inklusive Hausaufgaben

This commit is contained in:
wittmannzl103469 committed 2026-11-04 21:09:28 +01:00
1 parent 782b1850a3
commit d3389992aa
18 files changed
+5 -59

No files matched your search

@@ -0,0 +1,28 @@
class Particle:
MAX_HISTORY = 5 # maximal so viele Undos möglich
def __init__(self, position, velocity=(0, 0), acceleration=(0, 0), history=()):
self.position = position
self.velocity = velocity
self.acceleration = acceleration
self.history = list(history)
def update(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])
# Vorversion (self) an die neue History anhängen, alte Liste bleibt unverändert
new_history = (self.history + [self])[-Particle.MAX_HISTORY:]
return Particle(new_position, new_velocity, self.acceleration, new_history)
def undo(self):
if not self.history:
return self # nichts mehr zum Zurückgehen
return self.history[-1] # Vorversion (hat ihre eigene History)
def __repr__(self):
return f"Particle(pos={self.position}, vel={self.velocity})"