# Import the pygame library and initialise the game engine import pygame import numpy as np from verlet import Ball, Spring pygame.init() # Initialize Pygame SIZE = (800, 800) WHITE = (255, 255, 255) screen = pygame.display.set_mode(SIZE) pygame.display.set_caption("Patrick") running = True clock = pygame.time.Clock() def physics(): for ball in balls: ball.update() for spring in springs: spring.update() def draw(): for ball in balls: ball.render(screen) for spring in springs: spring.render(screen) def boost(): vector = springs[0].b.pos - springs[0].a.pos length = springs[0].compute_length() vector /= length norm = np.array([vector[1], -vector[0]]) balls[1].velocity += norm * .5 if __name__ == '__main__': balls = [Ball(0., 0., fixed=True), Ball(0., 100.), Ball(20., 120.), Ball(-20., 120.), Ball(0., 80.)] springs = [ Spring(balls[0], balls[1], length=100, k=3), Spring(balls[1], balls[2], k=5), Spring(balls[1], balls[3], k=5), 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) ] while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False screen.fill((0, 0, 0)) physics() boost() draw() pygame.display.flip() clock.tick(60) pygame.quit()