Python的3D引擎
 
 
VPython(Visual Python)是一個方便的工具可以幫你完成這項工作。
下載位置 (Windows 版本For python 2.4)。
 
下面是一個簡單的範例:
 

from visual import *

 

floor = box (pos=(0,0,0), length=4, height=0.5, width=4, color=color.blue)

ball = sphere (pos=(0,4,0), radius=1, color=color.red)

ball.velocity = vector(0,-1,0)

dt = 0.01

 

while 1:

rate (100)

ball.pos = ball.pos + ball.velocity*dt

if ball.y < ball.radius:

ball.velocity.y = -ball.velocity.y

else:

ball.velocity.y = ball.velocity.y - 9.8*dt

 
 
上面這個範例執行之後會有一個紅色的球,跟一塊藍色的地板,而紅色的球會在藍色的地板上不停的跳動。
arrow
arrow
    全站熱搜

    CJY0503 發表在 痞客邦 留言(0) 人氣()