### Working, job done

master
parent
commit
648c993360
4 changed files with 22 additions and 8 deletions
1. +2
-2
2. BIN
demo.webm
3. +17
-2
main.py
4. +3
-4
verlet.py

#### + 2 - 2 README.mdView File

 @@ -1,3 +1,3 @@ # patrick_wheels # Driven coupled parametric oscillators Simulating Patrick's wheels Settling a discussion from the pub.

#### + 17 - 2 main.pyView File

 @@ -12,6 +12,8 @@ pygame.display.set_caption("Patrick") running = True clock = pygame.time.Clock() data = [] def physics(): for ball in balls: @@ -36,13 +38,22 @@ def boost(): norm = np.array([vector[1], -vector[0]]) balls[1].velocity += norm * .5 def modulate(): x = pygame.mouse.get_pos()[0] fraction = x / SIZE[0] springs[-1].k = fraction*3 + 0.05 springs[-2].k = fraction*3 + 0.05 pygame.draw.rect(screen, (30, 30, 30), (0, 0, x, SIZE[1])) if __name__ == '__main__': balls = [Ball(0., 0., fixed=True), Ball(0., 100.), Ball(20., 120.), Ball(-20., 120.), Ball(0., 80.)] Ball(0., 80.), Ball(40., 100.), Ball(-40., 100.)] springs = [ Spring(balls[0], balls[1], length=100, k=3), Spring(balls[1], balls[2], k=5), @@ -50,7 +61,9 @@ if __name__ == '__main__': Spring(balls[2], balls[3], k=5), Spring(balls[1], balls[4], k=5), Spring(balls[2], balls[4], k=5), Spring(balls[3], balls[4], k=5) Spring(balls[3], balls[4], k=5), Spring(balls[3], balls[5], k=.1, color=(255, 0, 0)), Spring(balls[2], balls[6], k=.1, color=(255, 0, 0)) ] while running: @@ -60,7 +73,9 @@ if __name__ == '__main__': screen.fill((0, 0, 0)) physics() physics() boost() modulate() draw() pygame.display.flip()

#### + 3 - 4 verlet.pyView File

 @@ -45,17 +45,18 @@ class Ball(object): class Spring(object): def __init__(self, a, b, length=None, k=0.3): def __init__(self, a, b, length=None, k=0.3, color=WHITE): self.a = a self.b = b self.k = k self.length = self.compute_length() if length is None else length self.color = color print(self.length) def render(self, screen): x1, y1 = self.a.pos + CENTER x2, y2 = self.b.pos + CENTER pygame.draw.line(screen, WHITE, [x1, y1], [x2, y2]) pygame.draw.line(screen, self.color, [x1, y1], [x2, y2]) def compute_length(self): x1, y1 = self.a.pos + CENTER @@ -69,5 +70,3 @@ class Spring(object): stretch = (current_length - self.length) / self.length self.a.velocity += stretch * delta * self.k self.b.velocity -= stretch * delta * self.k