Program bounce line processing java
Program bounce line processing java
float y=250;
float speed=3;
float gravity=0.1;
float Xspeed=0;
float Yspeed=0;
float XYspeed;
float XYangle;
boolean time = true;
void setup() {
size(500, 500);
stroke(255, 255, 255);
}
int line1;
float line1angle=asin(-height*0.4/width);
int line2;
void draw() {
background(0);
//option(10, 10);
line(0, height/2, width, height*0.9);
line1 = round((height*0.4/width)*(x)+height/2);
//line(0, height, width, height/2);
circle(x, y, 10);
if (time == true) {
y=y-Yspeed;
Yspeed=Yspeed-gravity;
x=x-Xspeed;
}
if (y > line1-10) {
Xspeed = (XYspeed*sin(line1angle + XYangle));
Yspeed = (XYspeed*cos(line1angle + XYangle));
}
if (y <= 0) {
Yspeed = -Yspeed;
y = 0;
}
if (x <= 0 || x >= width) {
Xspeed = -Xspeed;
x = constrain(x, 0, width);
}
}