VPython - example - A simple ball acceleration

本作品采用知识共享署名-非商业性使用-相同方式共享 3.0 Unported许可协议进行许可。允许非商业转载,但应注明作者及出处。


作者:liuyuan_jq

2011-04-10


#!/usr/bin/env python # -*- coding:utf-8 -*- from visual import * scene.autoscale = False #A floor is an instance of box object with attributes like length, height, width etc. floor = box(length=4, height=0.5, width=4, color=color.blue) # A ball is a spherical object with attributes like position,radius, color etc.. ball = sphere(pos=(0,4,0),radius=1, color=color.red) #Ball moves in the y axis ball.velocity = vector(0,-1,0) # small change in time dt = 0.01 while 1: #setting the rate of animation speed rate(100) # Change the position of ball based on the velocity on the y axis ball.pos = ball.pos + ball.velocity*dt if ball.y < 1: ball.velocity.y = -ball.velocity.y else: ball.velocity.y = ball.velocity.y - 9.8*dt

VPython - example - A simple ball acceleration