top of page

Bouncing Ball Assignment

  • colleenguirand1
  • Nov 2, 2021
  • 1 min read

In this project, I was able to make a ball bounce from any area of a canvas using variables for the X & Y axis.


First, both variables for when the ball moves left/right (X) and up/down (right) were created along with their speeds. This was done before on start to make the program recognize that information must be read first because if not, it will dismiss it.


Second, variables X&Y were set to 300 because in the beginning of the program, the ball needs to meet in the middle of the screen. If the canvas is 600, then the ball meets at 300. I assigned the speed for both X&Y at random, but made sure they weren't the same.


After, in order to have the ball change color when user starts project, I RGB to random at 255. In the loop section the ellipse was granted a fill of (r,g,b) and I used the variables ballX and ballY to fill in the values of the ellipse.


Then, to make the ball bounce from the right side to the left side of the canvas, I made an if statement saying if ballX is greater than 600(size of canvas) - 25(half of ellipse) then set speedX equal to -speedX which makes the ball bounce off the corner of canvas. The same logic was applied to Y.


https://editor.p5js.org/cguiran1/sketches/4CAJ8sR5E

 
 
 

Recent Posts

See All
Final Exam Project

Originally, I was planning on creating a doodle jump game where the player presses the space key to make an object jump from platform to...

 
 
 
Final Project Idea

For my final project, I have two game ideas as to what I want to create. The first one was going to be a platform game, where there are...

 
 
 
Algorithmic Bias Reading Respone

Where do we see examples of algorithmic bias around us? ​ - AI has been seen used in job applications, police departments and with our...

 
 
 

Comentários


Post: Blog2_Post
  • Facebook
  • Twitter
  • LinkedIn

©2021 by Colleen's Blog. Proudly created with Wix.com

bottom of page