Question: I have a few questions regarding a computer science project using p 5 . js coding website. 1 . how can i code for an

I have a few questions regarding a computer science project using p5.js coding website.
1. how can i code for an image to become smaller as the mouse is pressed closer to the y-axis midline?
my goal: i want to do stars in the sky. each time the mouse is pressed, 5-10 stars are drawn (it is also a requirement to use the 'random' function, so i want the amount of stars drawn to be random.
"The size of the added objects should depend linearly upon the distance from the mouse click and the horizon. That is, an object that is twice as far from the horizon should be drawn twice as big, and this means that the drawn size shrinks to near zero size as objects approach the horizon."
on the bottom half, id like to do little bundles of blades of grass, 3-5 blades when mouse is pressed. same as above, as it approaches the horizon, it decreases in size.
2. the next requirement is when key 'r' is pressed, the (in my case) stars and blades of grass disappear and the original background remains. is there a shorter way to do this rather than copying and pasting the entire function setup() under function keyPressed?
I have a few questions regarding a computer

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!