Follow the instructions to make bouncing balls galore.
1. Write code to define 4 parallel arrays to store info for unlimited balls (right now we do not know the size).
The names of the parallel arrays are :
a) xPos
b) yPos
c) xSpeed
d) ySpeed
e) ballColors
2. Inside void setup() do the following:
a) Code a for-loop that runs 5 times. Inside the loop body write code to call addBall with random values for the first 2 parameters and color white as the value for 3 rd parameter.
3. Inside void mousePressed () :
a) Call addBall once with mouseX , mouseY as values to first 2 parameters and a random color as the 3 rdparameter
4. Inside void draw() :
a) Using a for-loop, make sure to draw all the balls with the information in the arrays xPos, yPos, xSpeed, ySpeed, ballColors.
Extremely similar to the code in [login to view URL] (found in my box folder inside the folder 02_10_array_del_2D_array_intro/boucing_ball) .
In that program we handle move one ball with info in the variables..
Here the info about all balls are inside the parallel arrays.
[login to view URL] a function addBall with following features :
a) It does not return any value
b) Takes in the following parameters:
i. X co-ordinate of the ball
ii. Y co-ordinate of the ball
iii. Color of the ball
c) Goal : to make changes to the following arrays:
i. Append the first parameter to the xPos .
ii. Append the second parameter to the yPos .
iii. Append a random value between 2 and 5 to the xSpeed array.
iv. Append a random value between 3 and 7 to the ySpeed array.
v. Append the third parameter to the ballColors array.
HINT : In step 1, you would have created array with the option that size and element info is unknown (middle branch in the slide titled “How to define arrays”).
So make sure to use the function append to add values to the arrays (check the slides to see how).
Watch the video for how it should like when it opens up and how your code should behave when mouse is pressed.
Hi there, I do JS. I went through the video of the bouncing ball and your requirements. I would like to do this project if given the opportunity. Let me know if you are interested so I can have further details.
I am an experienced programmmer and i have programmedd using javascript for a long time. I have gone through your task and I am glad it merges my skills and i would like to help you. Hire me and we can discuss details in the chat box.
This should be a difficult but fun project, I am confident that I can build it for you, we just need to align some details as to where is this simulation going to run, is it in a browser or desktop environment?