-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBouncingBallModel.py
More file actions
65 lines (49 loc) · 1.26 KB
/
BouncingBallModel.py
File metadata and controls
65 lines (49 loc) · 1.26 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
import math
import BouncingBallView
objects = {}
left = 0.0
right = 0.0
bottom = 0.0
top = 0.0
pause = False
def addObjects(objName, position, time, velocity):
obj = {'position':position,'time':time,'velocity':velocity}
objects[objName] = obj
def setScreenBoundries(l,r,b,t):
global left,right,bottom,top
left = l
right = r
bottom = b
top = t
def setPause(p):
global pause
pause = p
def changeVelocity(obj, v, dir):
objects[obj]['velocity'][dir] = v
def updateObject(obj,t):
# set new time
objects[obj]['time'] = t
v = objects[obj]['velocity']
x = objects[obj]['position'][0]
y = objects[obj]['position'][1]
z = objects[obj]['position'][2]
#calculate new position based on velocity
if not pause:
x = x + v[0]
y = y + v[1]
z = z + v[2]
if x > right:
x = right
v[0] = -v[0]
elif x < left:
x = left
v[0] = -v[0]
if y > top:
y = top
v[1] = -v[1]
elif y < bottom:
y = bottom
v[1] = -v[1]
objects[obj]['position'] = [x,y,z]
return objects[obj]['position']