Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Project 1: My Bouncing Ball
- * @Author: Allen Thoe
- * @Date: 1/21/2020
- */
- //DECLARE VARIABLES--> Type name;
- float x, y, d;
- float Vx, Vy;
- void setup(){
- size(600,600);
- strokeWeight(4);
- x = 200;
- Vx = random(-5,5);
- Vy = random(-5,5);
- y = 300;
- d = 60;
- textSize(40);
- }
- void draw(){
- background(r,g,b);
- fill(0,195, 255);
- stroke(155, 0, 255);
- ellipse(x, y, d, d);
- moveBall(); //CALL the moveBall() function
- bounce();
- }
- //Function MoveBall will update the location of the ball
- void moveBall(){
- x = x + Vx;
- y = y + Vy;
- }
- void bounce(){
- //HITS LEFT OR RIGHT WALL
- if(x < 0 || x > width){
- Vx = -Vx;
- //r = random(255);
- //g = random(255);
- //b = random(255);
- }
- //HITS UP OR DOWN WALL
- if(y < 0 || y > height){
- Vy = -Vy;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment