-
Notifications
You must be signed in to change notification settings - Fork 1
/
pendulum.py
71 lines (66 loc) · 1.7 KB
/
pendulum.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
tickrate = 13
ballsize = 0.07
speed = 1
#Modules
from visual import *
from math import *
#PHYSICS PARAMETERS
hinge = (0,0,0)
bpos = (1,-3,0)
g = vector(0,-9.8,0)
fac = 0.00001
g = g*fac
#Scene alignment
scene.center = (0,-1.5,0)
scene.fullscreen = 1
scene.scale = (0.4,0.4,0.4)
class framestop:
def __init__(self,frames):
self.frames = frames
self.frame = 0
def tick(self):
self.frame += 1
if self.frame == self.frames:
self.frame = 0
return 1
return 0
#Cleanup
removal = []
init = 0
#Timeline control
while 1:
if init == 0:
#Visual objects
ball = sphere(pos=(bpos),radius=ballsize)
ball.L = vector(0,0,0)
string = curve(pos=[ball.pos,hinge])
init = 1
if scene.mouse.clicked == 1:
c = scene.mouse.getclick()
init = 0
removal.append(ball)
removal.append(string)
#Main loop
vlist = []
stopper = framestop(tickrate)
while 1:
rate(60)
if ball.pos[0]<-1 or ball.pos[0]>1:
print len(vlist)
for e in vlist:
e.visible = 0
vlist = []
#if stopper.tick():
#vlist.append(copy.copy(ball))
r = ball.pos-hinge
ball.L += cross(r,g)*speed
ball.rotate(angle=(mag(ball.L)*speed), axis=ball.L,origin=hinge)
string.pos=[ball.pos,hinge]
if scene.mouse.clicked == 1:
c = scene.mouse.getclick()
for e in vlist:
e.visible = 0
vlist = []
for e in removal:
e.visible = 0
break