VPython - example - A simple ball acceleration

本文介绍了一个简单的Python程序,使用Visual库实现了一个在Y轴上运动并能模拟碰撞反弹效果的小球。通过不断更新小球的位置来展示其运动状态。

本作品采用知识共享署名-非商业性使用-相同方式共享 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

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值