效果演示:

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

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
  }
}

 

相关文章:

  • 2021-12-20
  • 2021-09-07
  • 2021-12-12
  • 2022-12-23
  • 2021-10-15
  • 2021-05-18
  • 2019-09-02
  • 2021-10-17
猜你喜欢
  • 2021-11-10
  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
  • 2021-06-23
  • 2021-10-04
  • 2022-12-23
相关资源
相似解决方案