WP2WS – W02 – Firefly (Force)

For this week’s assignment, we have learned basic knowledge about forces and practiced them.

Code

Inspiration

Since I decided to code about fireflies, I did some researches on it. Different from the gravitational attraction we have practiced in class, fireflies have a tiny mass and move relatively random, won’t be attracted by each other (cause the lighted fireflies are all males). They will sometimes gather to form a large scale to attract females. From the documentary, you can find a small light you can use, but make sure not to use a blue-tinged light. A keychain LED flashlight is a perfect choice. 

Technical

The two forces I am applying to the fireflies particles are the attraction between particles and the torchlight (user’s mouse), and the wind slightly blowing up from the ground. 

Difficulty & Progress

The first difficulty is that since I want to create attraction between the particles and the mouse position, the mouse position has to be assigned when calling the function. Therefore, the object of the function inside the class needs to be defined as a vector input for it to work.

The second is about acceleration. As mentioned above, how fireflies fly & get attracted in my mind is different from how planets rotate and attracted. I don’t want gravitational attraction – which means I want the insects to keep their original velocity or even slow down when approaching the mouse. At first, I thought limiting the velocity in update() would work, but it later turned out that all the particles will stick together due to the slowness.

all the particles sticking together

To solve this situation, I increased the velocity limitation, also added the applyWind() to add some upward movements to the particles, which is inspired by the street lamp out of the school back gate (If you have observed them you will find the insects keep flying randomly some distance above the lamp). 

Then I started to think about accelerations. I finally realized that acceleration is a vector, its number won’t be negative. Thus I changed it into an avoid function, trying to imitate that insects are avoiding the light because of its heat.

For the visual effect, I felt like pure yellow circles are too dull so I referred to the stars blinking effect, where the circle’s scale will change according to the time. I also apply this to the flashlight (mouse) later to achieve a better consistency. The reference is shown below.

Reference

https://editor.p5js.org/slow_izzm/sketches/AzyByxCgt

https://editor.p5js.org/wvnl/sketches/5wnuHAXKd

Leave a Reply

Your email address will not be published. Required fields are marked *