0% found this document useful (0 votes)
13 views2 pages

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)
13 views2 pages

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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy