Debian Codegraph @

examples/tvtk/visual/bounce.py

raw symbols SCIP
1 #!/usr/bin/env python
2 """A simple example demonstrating the creation of actors and animating
3 the in a scene using visual modeule."""
4 # Author: Raashid Baig <[email protected]>
5 # License: BSD Style.
6
7 from tvtk.tools.visual import box, sphere, vector, iterate, show
8
9 def main():
10 # Creating parameters for box size
11 side = 4.0
12 thk = 0.3
13 s2 = 2*side - thk
14 s3 = 2*side + thk
15 # Creating the 6 walls
16 wallR = box( pos = (side, 0, 0), size = (thk, s3, s2), color = (1, 0, 0))
17 wallL = box( pos = (-side, 0, 0), size = (thk, s3, s2), color = (1, 0, 0))
18 wallB = box( pos = (0, -side, 0), size = (s3, thk, s3), color = (0, 0, 1))
19 wallT = box( pos = (0, side, 0), size = (s3, thk, s3), color = (0, 0, 1))
20 wallBK = box( pos = (0, 0, -side), size = (s2, s2, thk), color = (0.7,0.7,0.7))
21 # Creating the ball
22 ball = sphere(radius = 0.4, color = (0, 1, 0))
23 ball.vector = vector(-0.15, -0.23, 0.27)
24
25 side = side -thk*0.5 - ball.radius
26
27 ball.t = 0.0
28 ball.dt = 0.5
29
30 def anim():
31 #Creating the animation function which will be called at
32 #uniform timeperiod through the iterate function
33 ball.t = ball.t + ball.dt
34 ball.pos = ball.pos + ball.vector*ball.dt
35 if not (side > ball.x > -side):
36 ball.vector.x = -ball.vector.x
37 if not (side > ball.y > -side):
38 ball.vector.y = -ball.vector.y
39 if not (side > ball.z > -side):
40 ball.vector.z = -ball.vector.z
41
42 a = iterate(20, anim)
43 show()
44 return a
45
46 if __name__ == '__main__':
47 main()