← Axyvio Lab

Control particles with your hand

The experiment from the Axyvio video. A webcam and a few lines of JavaScript track your hand, and a cloud of glowing particles follows your finger. Try it right here, then build your own in about 5 minutes.

🔒 Everything runs in your browser. The camera image never leaves your device and nothing is uploaded.

Build it yourself

1
What you need

A laptop or computer with a webcam, a modern browser (Chrome, Edge or Firefox) and any text editor. Notepad works, but the free Visual Studio Code is nicer. No installation, no account, no API key.

2
Create the file

Make a new folder, for example hand-particles, and inside it a file named index.html. Copy the whole code below into it and save.

index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Hand-controlled particles · Axyvio Lab</title>
  <style>
    html, body { margin: 0; height: 100%; overflow: hidden; background: #05060a; font-family: system-ui, sans-serif; }
    canvas { position: fixed; inset: 0; width: 100%; height: 100%; }
    video { display: none; }
    #start {
      position: fixed; inset: 0; margin: auto; width: fit-content; height: fit-content;
      padding: 14px 30px; border: 0; border-radius: 999px; cursor: pointer;
      font-size: 18px; font-weight: 600; color: #05060a; background: #5ad1ff;
      box-shadow: 0 0 40px rgba(90, 209, 255, 0.55);
    }
    #start:disabled { opacity: 0.7; cursor: wait; }
    #status { position: fixed; left: 0; right: 0; bottom: 16px; padding: 0 16px; text-align: center; color: #8fb8ff; font-size: 14px; }
  </style>
</head>
<body>
  <canvas id="scene"></canvas>
  <video id="camera" playsinline muted></video>
  <button id="start">Start camera</button>
  <div id="status">Your camera stays on your device. Nothing is uploaded.</div>

  <script type="module">
    import { FilesetResolver, HandLandmarker } from 'https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@1.1.0/vision_bundle.mjs';

    // ---- Settings: play with these! ----
    const PARTICLE_COUNT = 1200; // more = denser cloud (use less on slow laptops)
    const HUE = 195;             // colour: 0 red, 120 green, 195 cyan, 280 purple
    const PULL = 0.0009;         // how strongly the particles chase your finger
    const SWIRL = 0.6;           // how much they orbit around it
    const FRICTION = 0.94;       // lower = particles calm down faster
    const BURST = 18;            // how hard a pinch throws them away

    const canvas = document.getElementById('scene');
    const ctx = canvas.getContext('2d');
    const video = document.getElementById('camera');
    const status = document.getElementById('status');
    const startButton = document.getElementById('start');

    let width = 0;
    let height = 0;
    function resize() {
      width = canvas.width = window.innerWidth * devicePixelRatio;
      height = canvas.height = window.innerHeight * devicePixelRatio;
    }
    window.addEventListener('resize', resize);
    resize();

    // Every particle has a position (x, y) and a speed (vx, vy)
    const particles = Array.from({ length: PARTICLE_COUNT }, () => ({
      x: Math.random() * width,
      y: Math.random() * height,
      vx: 0,
      vy: 0,
      size: (0.6 + Math.random() * 1.6) * devicePixelRatio,
    }));

    let handLandmarker = null;
    let landmarks = null;   // the 21 points the AI finds on your hand
    let target = null;      // where your index fingertip is on screen
    let wasPinching = false;
    let lastVideoTime = -1;

    // The camera image is mirrored, so moving your hand right moves the particles right
    const toScreenX = (x) => (1 - x) * width;

    async function start() {
      startButton.disabled = true;
      startButton.textContent = 'Loading…';
      try {
        const vision = await FilesetResolver.forVisionTasks('https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@1.1.0/wasm');
        handLandmarker = await HandLandmarker.createFromOptions(vision, {
          baseOptions: {
            modelAssetPath: 'https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task',
            delegate: 'GPU',
          },
          runningMode: 'VIDEO',
          numHands: 1,
        });
        video.srcObject = await navigator.mediaDevices.getUserMedia({ video: { width: 640, height: 480 } });
        await video.play();
        startButton.remove();
        status.textContent = 'Wave your hand. Pinch your thumb and index finger to make it burst!';
      } catch (error) {
        startButton.disabled = false;
        startButton.textContent = 'Start camera';
        status.textContent = 'Could not start: ' + error.message;
      }
    }
    startButton.addEventListener('click', start);

    function trackHand() {
      if (!handLandmarker || video.readyState < 2 || video.currentTime === lastVideoTime) return;
      lastVideoTime = video.currentTime;
      const result = handLandmarker.detectForVideo(video, performance.now());
      landmarks = result.landmarks[0] ?? null;
      if (!landmarks) {
        target = null;
        wasPinching = false;
        return;
      }
      const thumbTip = landmarks[4];
      const indexTip = landmarks[8];
      target = { x: toScreenX(indexTip.x), y: indexTip.y * height };

      // Pinch = thumb and index fingertips almost touching. Burst once when the pinch starts.
      const pinching = Math.hypot(indexTip.x - thumbTip.x, indexTip.y - thumbTip.y) < 0.05;
      if (pinching && !wasPinching) {
        for (const p of particles) {
          const angle = Math.random() * Math.PI * 2;
          p.vx += Math.cos(angle) * BURST * Math.random() * devicePixelRatio;
          p.vy += Math.sin(angle) * BURST * Math.random() * devicePixelRatio;
        }
      }
      wasPinching = pinching;
    }

    function update() {
      // No hand: the particles drift slowly towards the middle of the screen
      const tx = target ? target.x : width / 2;
      const ty = target ? target.y : height / 2;
      const pull = target ? PULL : PULL * 0.15;
      for (const p of particles) {
        const dx = tx - p.x;
        const dy = ty - p.y;
        // Pull towards the finger, plus a sideways push that makes them orbit around it
        p.vx += dx * pull - dy * pull * SWIRL;
        p.vy += dy * pull + dx * pull * SWIRL;
        p.vx *= FRICTION;
        p.vy *= FRICTION;
        p.x += p.vx;
        p.y += p.vy;
      }
    }

    function draw() {
      // A see-through dark layer instead of clearing gives the particles soft trails
      ctx.fillStyle = 'rgba(5, 6, 10, 0.25)';
      ctx.fillRect(0, 0, width, height);

      ctx.globalCompositeOperation = 'lighter'; // overlapping particles glow brighter
      for (const p of particles) {
        const speed = Math.min(Math.hypot(p.vx, p.vy) / (12 * devicePixelRatio), 1);
        ctx.fillStyle = 'hsla(' + (HUE + speed * 40) + ', 100%, ' + (55 + speed * 25) + '%, 0.8)';
        ctx.beginPath();
        ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
        ctx.fill();
      }
      ctx.globalCompositeOperation = 'source-over';

      // Show the 21 points the AI found, so you can see what it "sees"
      if (landmarks) {
        ctx.fillStyle = 'rgba(255, 255, 255, 0.75)';
        for (const point of landmarks) {
          ctx.beginPath();
          ctx.arc(toScreenX(point.x), point.y * height, 3 * devicePixelRatio, 0, Math.PI * 2);
          ctx.fill();
        }
      }
    }

    function loop() {
      trackHand();
      update();
      draw();
      requestAnimationFrame(loop);
    }
    loop();
  </script>
</body>
</html>
3
Open it

Pick whichever is easier for you:

Option A · Just double-click (easiest)

Double-click index.html so it opens in Chrome or Edge. That's it. If it opens in another browser, right-click the file and choose "Open with" Chrome.

Option B · A tiny local server

For Safari or Firefox, or if the camera does not start with option A. Browsers only allow the camera on secure pages, and localhost always counts as one. Open a terminal in your folder and run one of these:

Mac / Linux (Python)
python3 -m http.server 8000
Windows (Python)
py -m http.server 8000
or with Node.js
npx serve .

Then open this address in your browser (with Node.js, use the address it prints):

browser address
http://localhost:8000

Using VS Code? The free Live Server extension does the same with one click on "Go Live".

4
Wave your hand

Click Start camera, allow the camera, and hold your hand 30–60 cm from it in good light. The particles follow your index fingertip. Pinch your thumb and index finger together to make them burst!

How it works

1. The camera sees your hand. Every video frame goes to MediaPipe, a free AI model from Google that runs inside your browser.

2. AI finds 21 points. For each frame it returns 21 landmarks: the wrist, every joint and every fingertip. Point 8 is the tip of your index finger and point 4 the tip of your thumb. You can see them as white dots in the demo.

3. Simple physics moves the particles. Each particle is pulled towards your fingertip, gets a small sideways push so it orbits, and slows down a little every frame. When the thumb and index tips almost touch, it counts as a pinch and every particle gets a random kick.

Make it yours

At the top of the script there is a Settings block. Change a value, save, and refresh the page:

Change the colour

Replace the HUE line. 0 is red, 30 orange, 120 green, 280 purple.

const HUE = 280;             // purple

More (or fewer) particles

A denser cloud looks great on a fast laptop. If it stutters, go down to 600.

const PARTICLE_COUNT = 3000;

A wild swirl

Make the particles orbit your finger like a whirlpool.

const SWIRL = 2.5;

Bigger pinch explosion

Pinch your thumb and index finger together to blow the cloud apart.

const BURST = 40;

Not working?

Black screen or no camera prompt: some browsers (like Safari) block the camera when the file is opened by double-click. Use option B from step 3.

"Permission denied": click the camera icon in the address bar, allow the camera, and refresh.

The hand is not detected: add light, keep your whole hand in view and move it a bit further from the camera.

It stutters: lower PARTICLE_COUNT to 600.

Made by Axyvio · Real science you can try yourself