Objects Practice Quiz

Question 1

Question 2

Question 3

Write the code to use a class called Illusion. The class is already defined for you. Your job is to create an instance of this class such that every time the mouse is pressed, the togglePause() command is called for your instance of the illusion. The illusion should be displayed each time the draw loop executes. Consider the (intentionally not commented) Illusion constructor to think through how to call the constructor properly.

You can write the code in this p5js web editor starter code tab.

This question cannot be auto-graded. If you do it correctly, you should get something similar to the following:

../_images/illusion.gif

Question 4

Write the code to make a class called Particle. When a new Particle is created, it should take in an x and y value for it’s initial location. When it is created, the Particle should set a size, dx, dy and color. The dx and dy values should be randomized. The Particle class should have two functions: update() and display(). The update() function should apply the Particles speed to it’s location, and the display() function should draw an appropriated colored circle on the screen at the Particle’s location.

You can write the code in this p5js web editor starter code tab.

This question cannot be auto-graded. If you do it correctly, you should get something similar to the following:

../_images/fireworks.gif

Extra for Experts

If you’d like an additional challenge, see if you can make the Particle’s slowly become more transparent. When they can no longer be seen, remove them from the array.

../_images/fireworks-expert.gif
Next Section - Sorting Practice Quiz