← all demos · chapter 06

Sparks — the four-line physics

A particle system is "spawn lots of small things and let simple rules move them." The rules here are four lines: move by velocity, add gravity, lose life, draw at alpha = life/maxLife. Press Run, then click the canvas to burst.

Click anywhere on the canvas for more bursts. Every game engine's particle panel is a form that fills in these same numbers.

Try tweaking: GRAVITY to −340 (sparks fall up) · particle count 48 → 200 · speed range to rand(10, 60) for a soft puff · lifetime to 4 seconds for slow embers. One number each — and each one is a different effect with a different name in someone's tutorial.

In Godot: the same values set on CPUParticles2D, entirely in code — download sparks.gd from the Godot project. In Unity: a Particle System with Burst emission + gravity modifier — the inspector fields map one-to-one to these constants. In Unreal: Niagara burst emitter, same story. Chapter 06 names the mapping.