axi0motion

Particles

Balls fall, bounce and collide in a scene computed in WebAssembly.

  • element
  • webassembly
  • physics
  • balls
  • playful
  • since 0.1

Background Studio: tune it below, then copy the code

Your system asks for reduced motion: the demo shows its final state and nothing moves.

Live demo

Particles example

Controls

70
7
1
0.55
1

Code

It follows the controls above: change an option and the code changes with it.

<link rel="stylesheet" href="/axi0/motion/motion.css?v=6">
<script src="/axi0/motion/motion.js?v=10" defer></script>

<axi0-particles cover count="70" seed="7"></axi0-particles>

The wrappers: Particles.tsx (React, TypeScript) and Particles.vue (Vue). Both render the same attributes as the HTML; the loader does the rest.

Options

AttributeDefaultWhat it does
count70how many balls
seed7the same seed always gives the same scene
gravity11 is about 1,400 pixels per second squared
bounce0.55how much speed a bounce keeps
size1ball size factor (radius 6 to 16 pixels at 1)
colors#f6a04d,#ff6b8b,#8a7dff,#3ad0c1comma separated
coverfalsefill the nearest positioned parent, behind its content

Accessibility

The simulation steps only while the element is on screen and the tab visible, in fixed 1/120 s steps. Reduced motion: the scene settles at once (900 steps in WebAssembly) and is drawn once, still. A page with a strict script-src needs 'wasm-unsafe-eval' for this effect only.

Size

particles.js is 1.3 KB gzip. A page loads the loader (2.7 KB) and core.js (1.4 KB) once, whatever it uses.