No Description

RigidMass.py 785B

    import math G = 6.67408E-11 class RigidMass: def __init__(self, mass, vx, vy, x, y, tick): self.mass = mass self.vx = vx self.vy = vy self.x = x self.y = y self.dvx, self.dvy = 0, 0 self.tick = tick #tick length, in seconds def gravity(self, p): #p is other particle v = -G * p.mass / self.distance_squared(p) * self.tick #print(self.distance_squared(p)) #self.v = v #debugging dx = self.x - p.x dy = self.y - p.y hyp = math.sqrt(dx**2 + dy**2) self.dvx += v * (dx) / hyp self.dvy += v * (dy) / hyp def process_tick(self): self.vx += self.dvx self.vy += self.dvy self.dvx, self.dvy = 0, 0 self.x += self.vx * self.tick self.y += self.vy * self.tick def distance_squared(self, p): return abs((self.x - p.x)**2 + (self.y - p.y)**2)