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

相关文章:

  • 2021-11-27
  • 2022-01-25
  • 2021-08-10
  • 2021-12-02
  • 2022-12-23
  • 2021-06-17
  • 2021-10-07
猜你喜欢
  • 2021-11-23
  • 2022-01-01
  • 2021-05-03
  • 2021-10-22
  • 2021-09-24
  • 2022-01-27
相关资源
相似解决方案