0% found this document useful (0 votes)
7 views

Program bounce line processing java

The document contains a Processing sketch that simulates a bouncing ball affected by gravity. It defines variables for position, speed, and gravity, and includes a draw function that updates the ball's position and handles collisions with the boundaries and a line. The code also includes commented-out sections for a user interface option that is not currently active.

Uploaded by

cheesegreat47
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Program bounce line processing java

The document contains a Processing sketch that simulates a bouncing ball affected by gravity. It defines variables for position, speed, and gravity, and includes a draw function that updates the ball's position and handles collisions with the boundaries and a line. The code also includes commented-out sections for a user interface option that is not currently active.

Uploaded by

cheesegreat47
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

float x=250;

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 option(int a, int b) {


fill (255, 255, 255);
square(a, b, 10);
text("Time", a+15, b+10);
if (mousePressed() && mouseX >= a && mouseX <= a+10 && mouseY >= a && mouseY <=
a+10) {
fill (100, 100, 100);
square(a, b, 10);
}
}*/

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

XYspeed = sqrt(pow(Xspeed, 2) + pow(Yspeed, 2));


XYangle = asin(Xspeed/XYspeed);

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

You might also like