VPython 一个相当傻瓜的3D软件包

代码

first

```   1 from visual import *
2
4 ball.trail = curve(color=ball.color)
5 wallR = box(pos=(6,0,0),size=(0.2,12,12),color=color.green)
6 wallL = box(pos=(-6,0,0),size=(0.2,12,12),color=color.green)
7 wallT = box(pos=(0,6,0),size=(12,0.2,12),color=color.orange)
8 wallB = box(pos=(0,-6,0),size=(12,0.2,12),color=color.orange)
9 wallBa = box(pos=(0,0,-6),size=(12,12,0.2),color=color.cyan)
10 dt = 0.05
11 ball.velocity = vector(2,5,-1)
12 while True:
13         rate(100)
14         ball.pos = ball.pos+ball.velocity*dt
15         if ball.x>wallR.x:
16                 ball.velocity.x *= -1
17         if ball.x<wallL.x:
18                 ball.velocity.x *= -1
19         if ball.y>wallT.y:
20                 ball.velocity.y *=-1
21         if ball.y<wallB.y:
22                 ball.velocity.y *=-1
23         if ball.z<wallBa.z:
24                 ball.velocity.z *= -1
25         if ball.z>6:
26                 ball.velocity.z *= -1
27         ball.trail.append(pos=ball.pos)
```

发布您的代码

• 谢谢分享使用VPython编写的3D小程序

讨论区

VPython (last edited 2009-12-25 07:09:44 by localhost)