Gestures & WebcamPremium

Energy Crystal

A faceted crystal floats between your hands on the webcam: an open palm charges it, a fist shatters it, a pinch re-forms it and sets its size. Without a camera, one click does it.

WebcamMediaPipeHand trackingWebGLParticles

Updated

This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Gestures & Webcam has 11 effects, all premium. Explore the category →

3 usage examples

"Open, close, pinch" finger warm-up before climbing — app of a climbing gym — Energy Crystal example 1

① "Open, close, pinch" finger warm-up before climbing — app of a climbing gym

WhenBefore the first route, the climber props up the phone and follows the set: the hand opens and the beam charges the crystal; the fist tightens and the crystal shatters; a pinch brings it back. Each recognised gesture adds one repetition to its row.
WhyThe effect's three gestures are those of a finger warm-up. The crystal gives instant feedback on a movement usually done in thin air, and the list counts for the climber.
Settings342 × 262 px block, gesture panel kept, privacy line moved to the left column. The page watches data-ecx-gesture with a MutationObserver: the row of the current gesture lights up and its counter moves up by one.
Break the crystal to draw the theme of the next scene — screen of an improv theatre match — Energy Crystal example 2

② Break the crystal to draw the theme of the next scene — screen of an improv theatre match

WhenBetween two scenes, the referee steps in front of the screen and closes a fist: the crystal bursts and the card at the bottom shows the theme, the category and the length. A pinch re-forms the crystal for the next draw. In the capture, a click plays the fist.
WhyDrawing the theme is part of the show: the shatter can be seen from the stands, and the theme only appears on the referee's gesture, not before.
Settings238 × 200 px block between the two scores, gesture panel removed from the HTML, camera button made smaller and right-aligned. The page watches data-ecx-crystal: each time it turns to burst, it shows the next theme in its list.
A crystal between two hands at the top of the page — site of a spa town's mineral fair — Energy Crystal example 3

③ A crystal between two hands at the top of the page — site of a spa town's mineral fair

WhenThe visitor opens the site: to the right of the headline, two hands charge a spinning crystal, then one shatters it and the other re-forms it. The button invites them to try with their camera before heading to the ticket office.
WhyHolding a crystal is what the fair promises. The demonstration plays by itself while the dates are being read, and those who turn the camera on see their own picture pass through the facets.
SettingsVariant from the shipped CSS: .ecx-kiosk on the scene, .ecx-scrim veil, text in .ecx-kiosk-content (kept to 236 px wide here so it does not cover the crystal), .ecx-cta button with data-ecx-start. pointer-events: none on the scene: it ignores the cursor and plays its demonstration, only the button stays clickable.

How it works

The crystal is a 12-facet bipyramid, computed in WebGL in a 512 px buffer and then copied onto the scene canvas. It sits halfway between two hands, or next to a single hand, spins on its axis and is surrounded by 150 orbiting particles. Each facet shows what lies behind it, with a different refraction index for red, green and blue: on the webcam, your own picture bends inside the crystal.

Three gestures make a cycle. Open palm: a beam leaves the palm, the crystal's charge rises by 50% per second per hand, it spins faster and glows more; with no palm it drops by 16% per second. Fist: the crystal vanishes and its particles are thrown outwards, with a glow and a ring that stay around it. Pinch (thumb against index, other fingers straight): the particles spiral back and the crystal re-forms; the gap between thumb and index then sets its size, from 0.7 to 1.6 times the starting size.

A small panel in the top right corner shows the number of hands, the recognised gesture and the state of the crystal. The script only writes two attributes on the scene, data-ecx-gesture and data-ecx-crystal; the CSS picks the label. Your page can read both attributes to react, as the first two examples do.

Without a camera, the palm of a drawn hand follows the cursor, a click or a tap counts as a fist, and the second hand comes in 1.2 s later to pinch the crystal back together. If nobody touches anything, the two hands run through the three gestures on their own over 13 s. The captures on this page are made this way, with the code you buy. The webcam only opens from its button: the MediaPipe hand detector is then downloaded and runs inside the page, and no image leaves the device. Only one thing goes out: about a minute after the detector loads, then every minute while the camera is filming, Google's library sends a technical report of about a hundred bytes (its version, processing times) to odml.pa.googleapis.com on its own, with no image. Mention it in your site's privacy policy.

Accessibility

  • Keyboard: a single tab stop, the camera button (Enter or Space). Shattering the crystal takes a click, a tap or a real fist: there is no key for it. With no pointer, the automatic demonstration still shows all three states.
  • Reduced motion: rotation, orbits and automatic hands stop: with no pointer, the crystal stays still, down to the pixel. A click still shatters the crystal, but the particles are placed straight at their end position, with no flight and no glow, and then it reappears.
  • State for screen readers: the gesture panel is aria-hidden, like the canvas. Only the camera messages (loading, camera on, no hand, refusal) are announced, through a role="status" pill. If a gesture triggers something on your page, announce it yourself.
  • Touch: a tap shatters, a horizontal swipe moves the hand, a vertical swipe scrolls the page. The tap was checked in touch emulation in all three engines, the swipes in Chromium only; nothing on a real phone.
  • Light: the shatter is a glow and a ring around the crystal, gone in half a second, never a full-screen flash, and the code allows one every 0.7 s at most. The .ecx-solid class on the scene dims the effect by 45% and makes the panels opaque.

Browser compatibility

WebGL 1 for the crystal, Canvas 2D for everything else, 63 KB of unminified JavaScript, no library in demo mode. Our tests (Chromium 149, Firefox 151, WebKit 26.5): with two crystals on the same page, clicking the second breaks only that one; in demo, not a single network request; off screen, drawing stops. On the camera side, tried in Chromium and Firefox with their simulated webcam: four files to download (10.7 MB transferred, around twenty once unpacked), then the MediaPipe report of about 100 bytes every minute. A CSP whose connect-src does not allow odml.pa.googleapis.com blocks that report without affecting the crystal (tried in Chromium). For the three gestures, simulated hand landmarks were passed to the shipped code in Chromium, and a trial video showed that a real hand is recognised. Camera never tried in Safari.

Chrome 88+✓ Full (measured)
Firefox 89+✓ Full (measured)
Safari 15+✓ Demo measured · camera not verified
Edge 88+✓ Not verified
iOS Safari 15+✓ Not verified
Android Chrome 88+✓ Not verified

No WebGL, or context lost: the crystal is drawn in Canvas 2D, with flat blue facets and light edges, without refraction; particles, beams and gestures are unchanged. Camera refused or missing: a 10 s message, and the demonstration resumes. On camera, a shattered crystal re-forms by itself when no hand has been seen for 3 s.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="fx-0848-root">
  <div class="ecx-scene" data-ecx-lang="en" role="region" aria-label="Energy Crystal — a faceted crystal floats between your hands: open palm to charge it, fist to shatter it, pinch to re-form it. Cursor demo, camera on request (processed on your device only)">
    <video class="ecx-video" playsinline muted autoplay aria-hidden="true" tabindex="-1"></video>
    <canvas class="ecx-canvas" aria-hidden="true"></canvas>
    <div class="ecx-bar">
      <button class="ecx-btn ecx-cam-btn" type="button" aria-pressed="false">
        <span class="ecx-btn-ico" aria-hidden="true"></span><span class="ecx-btn-txt">Turn camera on</span>
      </button>
      <p class="ecx-privacy">No image ever leaves your device.</p>
    </div>
    <p class="ecx-status" role="status" aria-live="polite"></p>
    <div class="ecx-label" aria-hidden="true">
      <span>Energy Crystal</span>
      <span class="ecx-hint">move the cursor · click to shatter · or turn the camera on</span>
    </div>
    <div class="ecx-hud" aria-hidden="true">
      <span class="ecx-hud-k">Hands</span><span class="ecx-hud-v ecx-hud-hands">0</span>
      <span class="ecx-hud-k">Gesture</span><span class="ecx-hud-v"><i data-g="none">none</i><i data-g="palm">palm · beam</i><i data-g="fist">fist · shatter</i><i data-g="pinch">pinch · size</i></span>
      <span class="ecx-hud-k">Crystal</span><span class="ecx-hud-v"><i data-c="stable">stable</i><i data-c="charge">charged</i><i data-c="burst">shattered · pinch</i><i data-c="form">forming</i> <b class="ecx-hud-scale">1.0×</b></span>
    </div>
  </div>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Size set by the pinch (JS — SIZE_MIN, SIZE_MAX) 0.7 and 1.6 Bounds of the crystal's size, as multiples of its base size (18.5% of the scene's short side, between 40 and 160 px in radius). Use two equal values for a fixed size.
Delay between two shatters (JS — BLAST_GAP) 0.7 s Minimum time between two bursts. Do not go below 0.34 s: past three bursts per second, you leave the limit the code set itself for photosensitive people.
Gesture hold (JS — GEST_HOLD) 0.1 s How long a hand shape must stay stable before it counts as a gesture. 0.25 s avoids accidental shatters when a hand crosses the frame.
Charge speed (JS — 0.5 * feed : -0.16 in render) +50% per second per palm, −16% otherwise The first number sets the rise, the second the fall. The panel reads "charged" above 75%.
Particles (JS — DUST_N, FLUX_MAX) 150 and 260 Number of orbiting particles, and cap on those travelling up the beams. Halve both on a slow device.
Crystal sharpness (JS — GL_SIZE) 512 px Side of the WebGL buffer. 256 is enough for a crystal under 120 px on screen; 1024 for a full-screen kiosk.
Refracted backdrop in demo (JS — c0, c1, c2 in FS) the scene's night-blue gradient Without a camera, the crystal refracts a gradient written in the shader, not your page. If you change the scene background in CSS, copy the same colours there.
Hero variant (HTML — .ecx-kiosk, data-ecx-start) to add to the HTML A dark veil on the left holds your headline, your text and the call-to-action button. The gesture panel only shows once the camera is on.
Gesture panel (HTML — .ecx-hud) present Remove the block from the HTML: the script does without it and keeps writing the two attributes on the scene.

FAQ

Through two attributes the script keeps up to date on the scene: data-ecx-gesture is none, palm, fist or pinch, and data-ecx-crystal is stable, charge, burst or form. An attribute selector is enough to change a style; to run code, watch them with a MutationObserver. The charge (0.12 to 1) and the size can be read from scene.ecxBase.effect.charge and .sizeF.
Yes, when the camera is on: every video frame is sent to the shader, which reads it three times with three offsets to pull the colours slightly apart. On a bright backdrop (a face, a lit wall), this layer is toned down so the crystal does not wash out to white. In demo there is no picture: the crystal refracts a dark gradient, so the prism effect is far less noticeable.
On camera, it re-forms by itself once no hand has been seen for 3 s, or after 12 s in any case: the screen does not stay empty for the next person. We checked it by removing the hands after a fist. A fist kept closed does not shatter the crystal again; it has to open and close once more.