Goo Explosion is an interactive demo page that uses HTML/CSS/JS and the Matter.js library to model physically appealing gooey explosions.
-
Cursor Mode:
- When the mouse moves, a chain of “blobs” is created and smoothed by linear interpolation (Lerp), which gives the illusion of a tail.
- If the cursor remains still for a certain amount of time, the goo begins to accumulate entropy.
-
Goo Escape Mode:
- Phase 1: Shaking
A few blobs want to get out, trying to escape the gravity of their parent and start vibrating. - Phase 2: Explosion
The blobs realize they can’t do it alone, so they call on others from theexplosionAmountto start a REVOLT!!! Entropy has peaked, and the blobs fly off in all directions. - Phase 3: Gathering
Once they’ve had their fun, the parent’s gravity calls them all back home! - Phase 4: Pause
Finally, everyone is back together. The blobs need a moment to reflect!
- Phase 1: Shaking
-
Matter.js Physics Engine:
- Gravity in
world.gravityis turned off (x=0, y=0) so that the blobs float in a two-dimensional plane. - Air friction (frictionAir) controls how quickly the blobs slow down during explosion and gathering.
- applyForce: during the explosion, each blob receives a random force vector depending on
explosionIntensity. - Bodies.circle: each blob is represented as a small circular body in the engine. The property
isSensor: trueallows them not to collide physically and cancel collisions. - World.add and World.remove: add/remove blobs when the explosion starts or ends.
- Gravity in
-
Mathematical Details:
- Linear Interpolation (Lerp) is used for smooth movement of blobs and transitions between different states (idle → mouse movement → shaking).
- Shaker-Style Shaking: the coordinates of each blob are distorted by sinusoidal functions (
Math.sin) within a radius that grows during Phase 1. - Cursor Attraction (
cursorAttraction): the force is inversely proportional to the square of the distance from the cursor, multiplied by thecursorForceMultipliercoefficient. - Inter-particle Attraction (
particleAttraction), if enabled, is calculated similarly – inversely proportional to the square of the distance between pairs of nearby blobs.
-
SVG Goo Filter:
- The page includes a
<filter id="goo">containingfeGaussianBlur(blur) andfeColorMatrix. It is applied to the block of elements (<span>) to create a sticky, blending blob/ink effect.
- The page includes a
The page has a control block (panels “Basic Settings,” “Phase Parameters,” “Physics Parameters”). Each slider updates the corresponding variable in real time:
Basic Settings
-
Number of Regular Blobs – how many blobs follow the cursor in cursor mode to create the tail effect.
-
Explosion Blob Count – how many blobs are created during the explosion to fill the space.
-
Width – the diameter of the cursor and blobs in the tail during cursor mode.
-
Tail – how elongated the chain is; the greater the value, the more stretched out and less dense the tail appears.
-
Timeout – the number of milliseconds the cursor must remain still before triggering the blob explosion.
-
Cursor Attraction – the coefficient of force that pulls the blobs back to the cursor during the gathering phase.
-
Inter-particle Attraction – the coefficient of force by which blobs attract each other.
-
Explosion Intensity – how strongly the blobs fly apart during the explosion.
-
Minimum/Maximum Blob Size – defines the size range for new blobs appearing in the explosion (each one is randomly chosen between the minimum and maximum).
-
Phase 1 Duration – how long the shaking lasts before the explosion occurs.
-
Phase 2 Duration – how much time is allocated for the explosion, i.e., how long the blobs keep flying apart.
-
Phase 4 Duration – how long the pause after the gathering lasts before the blobs become the cursor again.
-
Assembly Threshold – the size of the area around the cursor into which blobs are gathered.
-
Cursor Force Multiplier – the “gravity” strength of the cursor (an invisible force that pulls the blobs back).
-
Inter-particle Force Multiplier – the attraction strength between particles themselves.
-
Damping – “air resistance”: the higher it is, the faster the blobs slow down and come to a stop.
- Open
index.htmlin your browser. - Adjust the sliders and move your mouse to see the effects.
- If the cursor remains still for longer than
idleTimeoutmilliseconds, it triggers the blob explosion. - If you decide to evade the blobs by moving the cursor, you’ll see inertial dances and fluid-mixing effects.
- Once you’re done experimenting, click any mouse button, and the tail cursor will appear again.
Have fun experimenting with the goo explosion!
- Inter-particle Attraction – with a large number of blobs, this can be computationally heavy (O(n^2) when iterating over all pairs). It can be optimized using Matter.js spatial structures or by limiting neighbors.
- Make it possible to load an SVG cursor.
- Various Shaking Modes – adjust the amplitude/frequency of the sine wave.
- Blob Colors and Styles – when embedding in a dark-themed site, the cursor might not be visible. Color and border customization might help.
Feel free to open Issues with suggestions or bug reports.
The project and the Matter.js library are freely available for use and modification for any purpose, provided a link to the source is included. They are distributed under the MIT license.
