Size: 1238
Comment: VPython: 一个超级傻瓜的3D软件包
|
← Revision 3 as of 2009-12-25 07:09:44 ⇥
Size: 1327
Comment: converted to 1.6 markup
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
[[TableOfContents]] | <<TableOfContents>> |
Line 4: | Line 4: |
[http://www.vpython.org/ 官方网站] | [[http://www.vpython.org/|官方网站]] |
Line 7: | Line 7: |
直接照着他的[http://www.vpython.org/VPython_Intro.pdf Tutorial]一步一步写下来的。-- by ["huangyi"] | 直接照着他的[[http://www.vpython.org/VPython_Intro.pdf|Tutorial]]一步一步写下来的。-- by [[huangyi]] |
Line 37: | Line 37: |
attachment:temp.gif | {{attachment:temp.gif}} |
Line 41: | Line 41: |
* 推荐一个视频教程: http://vpython.erikthompson.com/ -- by [[Feather]] |
VPython 一个相当傻瓜的3D软件包
简介
代码
first
直接照着他的Tutorial一步一步写下来的。-- by huangyi
1 from visual import *
2
3 ball = sphere(pos=(-5,0,0),radius=0.5,color=color.red)
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小程序
讨论区
推荐一个视频教程: http://vpython.erikthompson.com/ -- by Feather