diff --git a/README.md b/README.md index c1b968e..a53de9b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# patrick_wheels +# Driven coupled parametric oscillators -Simulating Patrick's wheels \ No newline at end of file +Settling a discussion from the pub. diff --git a/demo.webm b/demo.webm new file mode 100644 index 0000000..21ea63f Binary files /dev/null and b/demo.webm differ diff --git a/main.py b/main.py index 215a8c7..31a9752 100644 --- a/main.py +++ b/main.py @@ -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() diff --git a/verlet.py b/verlet.py index 73c554b..4485d22 100644 --- a/verlet.py +++ b/verlet.py @@ -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 - -