I am trying to make a ball bounce with an exponential function just like gravity.
in
Programming Questions
•
1 year ago
Except after my first loop the ball goes off screen. here's my code:
int x=0;
int dir;
boolean flag=true;
void setup() {
background(0);
size(400, 400);
frameRate(10);
}
void draw() {
background(0);
fill(64, 63, 160);
ellipse(200, 50+pow(x, 2), 60, 60);
fill(22, 99, 8);
rect(-1, 345, 401, 55);//
x=x+dir;
if (50+pow(x, 2)<315 && flag) {
dir=1;
flag=false ;
}
if (50+pow(x, 2)>315) {
dir=-1;
}
if (50+pow(x, 2)<3)
flag=true;
if (50+pow(x, 2)>3)
flag=false;
}
Any suggestions
int x=0;
int dir;
boolean flag=true;
void setup() {
background(0);
size(400, 400);
frameRate(10);
}
void draw() {
background(0);
fill(64, 63, 160);
ellipse(200, 50+pow(x, 2), 60, 60);
fill(22, 99, 8);
rect(-1, 345, 401, 55);//
x=x+dir;
if (50+pow(x, 2)<315 && flag) {
dir=1;
flag=false ;
}
if (50+pow(x, 2)>315) {
dir=-1;
}
if (50+pow(x, 2)<3)
flag=true;
if (50+pow(x, 2)>3)
flag=false;
}
Any suggestions
2