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
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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
initialization drawCars drawStats averageCarSpeed fastestCarIndex slowestCarIndex var carX array tha...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started