首页 > 其他 > 详细

简单的重力模拟:在Processing中做一个弹跳的球

时间:2020-10-26 21:21:59      阅读:84      评论:0      收藏:0      [点我收藏+]

效果演示:

技术分享图片

Processing 代码:

// simple emulation of gravity

float x;
float y;    // y(t)
float speed = 0;
float g = 0.1;  // gravity

void setup(){
  size(640, 480);
  x = width/2;
  y = height/2;  // start from half height
}

void draw(){
  // draw the ball
  background(255);
  fill(0);
  noStroke();
  ellipse(x,y,10,10);
  
  // move and accelerate
  y += speed;
  speed += g;
  
  // bounce back up
  if(y>height){
    speed *= -0.95;  // add resistance to each bounce
    y = height;      // make sure that the ball can bounce back up
  }
}

 

简单的重力模拟:在Processing中做一个弹跳的球

原文:https://www.cnblogs.com/xxfcz/p/13881374.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!