-
Notifications
You must be signed in to change notification settings - Fork 1
/
profileVerletBox.py
76 lines (58 loc) · 2 KB
/
profileVerletBox.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import pygame
import random
import math
import time
from Lib2D import Vector2D
from VerletIntegration import Integration, Particle, Constraint, Prefabs
import cProfile
import pstats
# 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), pygame.DOUBLEBUF)
pygame.event.set_allowed([pygame.QUIT, pygame.KEYDOWN, pygame.KEYUP])
screen.set_alpha(None)
done = False
clock = pygame.time.Clock()
verlet = Integration({
'iterations': 3,
'stageMinVect': Vector2D(10, 10),
'stageMaxVect': Vector2D(CANVAS_WIDTH - 10, CANVAS_HEIGHT - 10),
'gravity': Vector2D(0, 0.05)
})
objectID = 0
for x in range(0, 4):
for y in range(0, 4):
Prefabs.Box(
verlet,
50 + x * 70, # Math.random() * (CANVAS_WIDTH - 400) + 200,
50 + y * 60, # Math.random() * (CANVAS_HEIGHT - 400) + 200,
random.randint(30, 80),
random.randint(30, 80),
random.randint(0, 360),
True,
1,
objectID)
objectID += 1
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))
profile = cProfile.Profile()
profile.enable()
profile.runcall(verlet.runTimeStep, "verlet")
done = True
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)
ps = pstats.Stats(profile)
ps.print_stats()