Concept
My concept is “Nervous Fireflies” that implements a Levy Flight. Most of the time, the firefly hovers in a small area (small steps), but occasionally it gets startled and zooms to a new location (a very large step).
To visualize this, I mapped the “step size” to the size of the circle. When it’s hovering, it is a tiny dot. When it zooms, it expands into a large burst of light.
Code Highlight
I am proud of this section because it creates the Lévy Flight behavior without using complicated math formulas. I simply used random(100) like rolling a 100-sided die. If I roll a 1 (a 1% chance), the firefly takes a huge jump. Otherwise, it takes a tiny step.
I was also proud of the trigonometry part which is particularly thematic in situations where you want to convert an angle into cartesian coordinates.
step() {
// CHOOSE DIRECTION
let angle = random(TWO_PI);
// CHOOSE DISTANCE (The Lévy Flight Logic)
// Pick a random number between 0 and 100
let r = random(100);
// 2% chance of a BIG jump
if (r < 2) {
this.currentStepSize = random(50, 150);
}
// 98% chance of a small step
else {
this.currentStepSize = random(2, 5);
}
// MOVE
// convert angle/distance into X and Y
let xStep = cos(angle) * this.currentStepSize;
let yStep = sin(angle) * this.currentStepSize;
this.x += xStep;
this.y += yStep;
Reflection & Future Improvements
I realized that “random” doesn’t have to mean “even.” By checking if random(100) < 2, I was able to create a behavior that feels much more organic and alive than just moving randomly every frame.
For the future, I could implement:
Mouse Interaction: I want to make the firefly scared of the mouse, so if the mouse gets too close, it forces a “big jump” immediately.
Interaction Between Fireflies: Right now, the fireflies behave in isolation. It would be cool to have fireflies interact with one another using object to object communication.