-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulation.py
More file actions
50 lines (36 loc) · 1.2 KB
/
Copy pathsimulation.py
File metadata and controls
50 lines (36 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import pygame
from pygame.locals import *
from boid import Boid
from flock import Flock
from typing import List
class Simulator():
width: int
height: int
margin: int
def __init__(
self,
width: int = 500,
height: int = 500,
margin: int = 100
) -> None:
self.width = width
self.height = height
self.margin = margin
def run(self, flock: Flock) -> None:
pygame.init()
canvas = pygame.display.set_mode((self.width, self.height))
pygame.display.set_caption("Boid Simulation")
running = True
while running:
pygame.time.delay(30)
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_BACKSPACE:
running = False
elif event.type == QUIT:
running = False
canvas.fill((0, 0, 0))
flock.update(self.width, self.height, self.margin)
for boid in flock.boids:
pygame.draw.circle(canvas, boid.color, (boid.x_pos, boid.y_pos), (5))
pygame.display.update()