Created
September 28, 2019 19:11
-
-
Save WhiteBlackGoose/f9cdea7b267681a55c89bab5afe6eadb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Point: | |
def __init__(self, coords, mass=1.0, q=1.0 speed=None, **properties): | |
self.coords = coords | |
if speed is None: | |
self.speed = Vector(*[0 for i in range(len(coords))]) | |
else: | |
self.speed = speed | |
self.acc = Vector(*[0 for i in range(len(coords))]) | |
self.mass = mass | |
self.__params__ = ["coords", "speed", "acc", "q"] + list(properties.keys()) | |
self.q = q | |
for prop in properties: | |
setattr(self, prop, properties[prop]) | |
def move(self, dt): | |
self.coords = self.coords + self.speed * dt | |
def accelerate(self, dt): | |
self.speed = self.speed + self.acc * dt | |
def accinc(self, force): | |
self.acc = self.acc + force / self.mass | |
def clean_acc(self): | |
self.acc = self.acc * 0 | |
def __str__(self): | |
r = ["Point {"] | |
for p in self.__params__: | |
r.append(" " + p + " = " + str(getattr(self, p))) | |
r += ["}"] | |
return "\n".join(r) | |
def _ipython_display_(self): | |
print(str(self)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment