Having trouble with simple animation
in
Programming Questions
•
1 year ago
Could someone guide me to figure out my problem? What I am trying to do is have a ball drop randomly to fall down stairs. I have not included code so that the ball will 'bounce' from the stairs, I'm just trying to get it to move right now.
float gravity;
float dampen;
void setup () {
background(255);
size(1000,1000);
stairs(width/1000, height/10, 100,100);
//collide(); // ball hitting stairs and falling
//window(); staic background window
}
void draw () {
ball(width/random(500), height/20, -20,-20); // sets random location for ball drop in an effort for different outcomes
//sun(width*.3, height/3, 50,50); // attempt to have the sun rise in background
int x = 15;
int y = 15;
}
void ball (float x, float y, float w, float h) {
float moveX = 3.5;
float moveY = 4.5;
float gravity = 1.5;
float dampen = 2.5;
fill(255,0,0);
ellipse(x,y,w,h);
// may be cool to have a mouse drop of ball
x += moveX;
y += moveY;
moveX = gravity;
moveY = dampen;
}
void stairs(float x, float y, float w, float h) { // function stairs making stairs
//pushMatrix(); do not entirely understand matrix stack
fill(0); // black background
for (int i = 0; i < 10; i++) { // begin loop for stairs
// rectMode(CORNER);
rect(x,y,w,h); // paramaterized from function stairs which contain values
translate(w,h); // w and h come from values in stairs ();
}
//popMatrix(); matrix stack
}
1