-
Notifications
You must be signed in to change notification settings - Fork 1
/
verletRopes.py
57 lines (42 loc) · 1.58 KB
/
verletRopes.py
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
51
52
53
54
55
56
57
import pygame
import random
import time
from Lib2D import Vector2D
from VerletIntegration import Integration, Particle, Constraint, Prefabs
# Settings #############################################################
# put any adjustable settings here that would be interesting to tinker with.
FPS = 30
CANVAS_WIDTH = 1024
CANVAS_HEIGHT = 768
GRAVITY_DAMPENING = 0.001
##########################################################################
pygame.init()
screen = pygame.display.set_mode((CANVAS_WIDTH, CANVAS_HEIGHT))
done = False
clock = pygame.time.Clock()
verlet = Integration({
'iterations': 1,
'stageMinVect': Vector2D(0, 0),
'stageMaxVect': Vector2D(CANVAS_WIDTH, CANVAS_HEIGHT),
'gravity': Vector2D(0, 0.05)
})
for i in range(0, 200):
Prefabs.Rope(verlet,
375 + (random.randint(0, CANVAS_WIDTH - 750)),
225 + (random.randint(0, CANVAS_HEIGHT - 450)),
random.randint(0, 25) + 5,
random.randint(0, 3) + 4,
1,
True)
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
# millis = int(round(time.time() * 1000))
screen.fill((0, 0, 0))
verlet.runTimeStep()
for constraint in verlet.constraints:
pygame.draw.line(screen, (0, 255, 0), (constraint.ends.startParticle.vector.x, constraint.ends.startParticle.vector.y), (constraint.ends.endParticle.vector.x, constraint.ends.endParticle.vector.y))
pygame.display.flip()
# print(int(round(time.time() * 1000)) - millis)
clock.tick(FPS)