Edit : Here is the starter code https://editor.p5js.org/CS105F2020/sketches/6YTEGummr 1) Use an 800 by 800 canvas with a
Question:
Edit : Here is the starter code https://editor.p5js.org/CS105F2020/sketches/6YTEGummr
1) Use an 800 by 800 canvas with a light gray background “background(220);”. 2) You must have the following functions: • initialization(); // initializes arrays and variables. It has no parameters • drawCars(); // as the name implies, it draws all of the cars. // drawCars() has no parameters • drawStats(); // it draws the text at the bottom of the canvas. // drawStats() has no parameters • averageCarSpeed() // it returns the average car speed. It has no parameters • fastestCarIndex() // it returns the index of the fastest car. // fastestCarIndex()It has no parameters • slowestCarIndex() // it returns the index of the slowest car // slowestCarIndex() has no parameters 3) The game starts as follows: • 5 circles start on the right-hand side of the canvas. Each circle represents a car. • The cars (i.e. circles) move from right to left. The size of the cars (i.e. circles) various depending on the number of cars (when there are 9 cars then the cars are small, when there are 2 cars the cars are large). Each car has its own speed which is randomly set to be between 1 and 3 pixels per frame. • Arrays are used to store the following: i. The X location of each car ii. The Y location of each car iii. The speed of each car • Each car has a number displayed. The numbers go from 1 to 9. 4) Text is displayed near the bottom of the canvas as follows. • The number of the fastest car. • The speed of the fastest car. • The number of the slowest car. • The speed of the slowest car. • The average speed of all cars on the canvas. 5) [ 3 ] The user can press the UP_ARROW or DOWN_ARROW to increase or decrease the number of cars. • UP_ARROW increases the number of cars by 1. DOWN_ARROW decreases the number of cars by 1. • The minimum number of cars is 2 and the maximum is 9. (hint: remember the “constrain” function)
Make sure to Comment your code appropriately with // to explain the code . Avoid superfluous comments. Make sure that there are no variables that are declared or assigned, but not used. Any do not use the scale, rotate or translate functions in code.