Open ghost opened 6 years ago
float x = 100; float y = 0;
float speed = 0; float gravity = 0.1;
void setup(){ size(200, 40); }
void draw(){ background(255);
fill(0); rectMode(CENTER); ellipse(x, y, 10, 20);
y = y + speed; speed = speed + gravity;
if( y > height ){ speed = speed * -0.3;//energy of motion lose. //after collision, the reverse speed will slow.
y = height;
}
}
But in https://github.com/shiffman/LearningProcessing/tree/master/chp09_arrays/example_09_11_array_append it won't, even changed the -0.95 to -0.6.
At some conditions, the ball won't finally 'stopped', actually it won't, I mean I can see it still shaking at the bottom of the window. Is that because of the precision of float? I have tried debugged it, only to find that it won't shaking if the speed is around +-0.0x