E6: Arrayed (due February 18)
On this page:
Instructions
This exercise helps you practice refactoring your code to simplify functionality.
Please complete the following:
- Continuing from the file built in the code tutorial on arrays you will be creating a revised
updateStars()function to allow it to directly change how the stars are drawn using arguments provided with the function. - Read through the documentation on functions in p5.js, pay attention to how you can provide a function with input (aka. arguments) to pass values along to inside the function.
- Comment out the original
updateStars()function and create a newupdateStarsN(star_number)function that will take the number of the star from the array to update. - Simplify the original
updateStars()function in the newupdateStarsN()function using thestar_numberargument/variable to select which star is being updated. For example if calling on the variable in theupdateStarsN()function we would likely use something likestars[star_number[0] = ...] - Change the use of
updateStars()to the newupdateStarsN()function within thedraw()function to update the movement of each of the stars. - Run the sketch using the play symbol to ensure the output is as you expect.
- Save the sketch to your computer.
Submission
Once done please submit a ZIP of your exercise to Canvas before class on February 18.
You are allowed to use this exercise as part of your projects if useful.
Grading rubric
This code exercise is worth 1% (1 point) of your final grade for completing the exercise steps.
Exercise rules
Please note the rules for exercises in this course:
- AI use is not permitted for code exercises. These are your opportunity to practice some of the basics we will need to progress through the course.
- You can use other online resources, course materials, and lab-mates for support. This being said, others are not allowed to do your work for you. Also, if you are drawing from online resources, course materials, or peers, you must cite it.
- Cite any knowledge that is not yours in a comment in the code. The internet is a huge repository of information and you are welcome to use it, but you must let us know when something does not originate from your own knowledge.
- If work has been copied without citation the exercise grade will be zero. Please make sure to include comments indicating where you had assistance or learned.