Bouncing Ball Assignment
- danielgrinchenko
- Sep 15, 2020
- 1 min read
I had to code a bouncing ball. My goal was to make it so that every time the ball hit the wall it would randomly change speed and it would randomly change color. I started by declaring all of my variables. I declared position variables to change the positions of the x and y coordinates. I declared r,g,b values to make it so they randomly change and randomly assign a color to the ball after every bounce. I then added speed variables to make it so the ball bounces differently every time. They would also randomly change after every bounce. I then proceeded into my main code. I made a conditional for both of my position variables. I set the bounds so the ball doesn't bounce of the screen and I put another conditional to help randomly change the speed. I ran into a error where my ball gets stuck on the edge. I tried to fix it using an acceleration variable but it did not end up working. Lastly, I drew my ball and gave it random color values.
Link to my code: https://editor.p5js.org/Grinchenko/sketches/cpmlyHpXz
Comments