小球匀速横向弹跳
input:
//processing在运动的基础上,实现小球碰壁弹跳的条件
float circleX;
float xspeed = 3.863;
void setup(){
size(640,360);
circleX = 0;
}
void draw(){
background(30);
fill(100);
stroke(255);
ellipse(circleX,height/2,32,32);
circleX = circleX + xspeed;
if (circleX > width){
xspeed = -3.863;
}
if (circleX < 0){
xspeed = 3.863;
}
//使用匀速来回弹跳xspeed = -xspeed;
}
output:xspeed = -xspeed效果等同
processing小球横向弹跳
小球变速横向弹跳
input:
//processing在运动的基础上,实现小球碰壁弹跳的条件
float circleX;
float xspeed = 3.863;
void setup(){
size(640,360);
circleX = 0;
}
void draw(){
background(30);
fill(100);
stroke(255);
ellipse(circleX,height/2,32,32);
circleX = circleX + xspeed;
if (circleX > width || circleX < 0){
//TURN AROUND,弹跳运动
xspeed = xspeed * -0.8; //此为减速运动,或使用加速来回弹跳xspeed = xspeed * -1.1;
}
}
output:
processing减速弹跳运动