How I Built Origami Hand Detection with Antigravity
Turning a flat sheet of yellow paper into a 6-step waving Origami Pikachu controlled by your fingers — using MediaPipe HandLandmarker, 120-frame canvas scrubbing, and Antigravity.
Origami is one of the most tactile experiences in the physical world. You start with a single flat square of paper, crease it step by step, and watch a character emerge between your fingers.
When I set out to build Origami Hand Detection for my Design Lab, I wanted to capture that exact physical delight on the web—without forcing anyone to click a slider or wear a VR headset. Hold up 0 fingers (a closed fist) and you see a flat sheet of yellow origami paper on a warm wooden desk. Raise 1, 2, 3, 4, or 5 fingers and the paper smoothly folds—or unfolds in reverse—through all six stages until Pikachu stands up and waves back at you.
Building a responsive computer-vision interaction that feels effortless at 60fps usually takes days of wrestling with webcam pipelines, landmark math, and video codec quirks. Working with Antigravity, I was able to focus almost entirely on interaction feel and visual craft while iterating rapidly through four clear engineering breakthroughs.
Stage 1: Designing the 0–5 Finger Grammar with MediaPipe
My first instinct was to map every folding stage to a natural, unmistakable hand count—no obscure sign language to memorize:
- 0 Fingers (
✊Fist) → Step 1: Flat square yellow sheet - 1–4 Fingers → Steps 2–5: Progressive origami folds, ears, cheeks, and lightning tail
- 5 Fingers (
🖐️Open Palm) → Step 6: Completed Origami Pikachu waving hello - Two Hands (
🙌Spread / Pinch) → Continuous zoom from50%to175%
The catch with raw webcam hand tracking is jitter. Early prototypes flicker wildly between 3 and 4 fingers—especially with the thumb, which bends sideways instead of vertically.
“Use Google MediaPipe HandLandmarker (@mediapipe/tasks-vision) to count 0 to 5 extended fingers reliably across different camera distances. Normalize thumb extension against palm width (landmarks 5 to 17) instead of raw screen coordinates so it never flickers when the user moves closer or farther from the webcam.”
Antigravity implemented a palm-normalized ratio detector in countFingers0To5() that compares wrist-to-fingertip distance against both the PIP and MCP joints, while checking the thumb against palmWidth:
function isMainFingerExtended(landmarks, tipIdx, pipIdx, mcpIdx) {
const wrist = landmarks[0];
const dTip = dist2D(landmarks[tipIdx], wrist);
const dPip = dist2D(landmarks[pipIdx], wrist);
const dMcp = dist2D(landmarks[mcpIdx], wrist);
return dTip > dPip * 1.07 && dTip > dMcp * 1.18;
}
That single architectural choice—normalizing against the hand’s own anatomy rather than pixel coordinates—made finger counting immediately rock-solid under everyday laptop lighting.
Stage 2: Why I Ditched <video> Seeking for 120-Frame Canvas Scrubbing
My first version scrubbed an HTML5 <video> element (origami_pikachu.mp4) by setting video.currentTime whenever the finger count changed. It worked in theory, but felt laggy in practice: browsers decode MP4 keyframes asynchronously, so scrubbing backward from 5 fingers to 2 fingers stuttered noticeably.
I asked Antigravity to solve the seek latency at the root. Together we switched to a 120-frame preloaded JPEG sequence (frames/frame_000.jpg through frame_119.jpg) rendered onto an HTML5 <canvas> with fractional cross-fading:
- Raising or lowering fingers updates a
targetFrameFloatbetween0and119. - Every animation tick eases
currentFrameFloatsmoothly toward the target with velocity clamping (maxStepPerTick). - Between consecutive integer frames (
fFloorandfCeil), the renderer blendsimgAandimgBby the fractional alphafrac—creating buttery 60fps forward and reverse folding motion with zero codec stutter.
Great tangible UI lives or dies on perceived latency. Replacing
<video>seeking with 120 preloaded canvas frames turned a cool CV demo into something that actually feels like folding paper in mid-air.
Stage 3: Eliminating Black Bars with Edge-Feathered Tabletop Immersion
Once the folding animation was smooth, a visual design problem bothered me: on wide desktop monitors, a centered vertical or 4:3 origami frame leaves awkward dark letterbox bars on the left and right. Cropping to object-fit: cover wasn’t an option either—it sliced off Pikachu’s ear-tips or paws.
So I briefed Antigravity on a custom studio compositing trick inside drawImmersiveFrame():
- Full-bleed blurred backdrop: Draw the current frame stretched horizontally with a
26pxblur at the exact same vertical horizon so the warm wooden tabletop grain extends edge-to-edge across100vw × 100vh. - Offscreen feathered subject: Render the crisp Pikachu frame onto an offscreen canvas (
subjectCanvas), apply adestination-inhorizontal linear gradient (14%soft feather on left and right edges), and composite it seamlessly onto the tabletop.
The result: zero black bars on any screen ratio, while Pikachu remains 100% uncropped from ear-tips to paws—even when you spread two hands apart to zoom in to 175%.
“Keep Pikachu 100% visible from ear-tips to paws on widescreen monitors with zero dark borders. Extend the wooden table backdrop across 100vw × 100vh with a horizon-aligned blur, and feather the left/right edges of the crisp center subject onto an offscreen canvas so the table merges invisibly.”
Stage 4: Dual Modes, Keyboard Fallbacks, and Framer Portability
Not everyone opens a portfolio link in a room where they want to turn on their webcam. In the final polish pass with Antigravity, we made sure the experience stayed joyful in every context:
- Dual Display Modes: A single HUD toggle switches between Video Animation (120-frame scrub) and 6-Step Image Panels (
step1.jpg–step6.jpg) for inspecting each fold crease clearly. - Zero-Camera Fallback: Pressing keys
0–5(or clicking any of the 6 step cards) triggers the exact same 60fps folding interpolation; pressingHtoggles Pure Mode to hide the glassmorphism HUD completely. - Framer & Trio Experiments: Alongside the standalone web app, Antigravity helped package a drop-in React/Framer component (
FramerOrigamiHandDetection.tsx) and a companion Pokémon Trio prototype (Pikachu, Raichu, and Eevee) built on a watertight 25-vertex origami crease mesh.
What This Project Taught Me About Designing with Antigravity
Building Origami Hand Detection reinforced something I now rely on in every Design Lab experiment:
- Solve feel problems with engineering, not just visuals. Switching from MP4 seeking to 120-frame canvas interpolation wasn’t a visual tweak—it was an engineering architecture shift that transformed the emotional feel of the interaction. Antigravity made that pivot take minutes instead of days.
- Treat edge cases as first-class UX. Palm-normalized thumb math, two-hand zoom bounds, widescreen edge feathering, and keyboard fallbacks are what separate a fragile hackathon script from a portfolio piece anyone can enjoy.
- Prototype directly in the real medium. Instead of mocking up hand-tracking curves in static slides, Antigravity lets me test real webcam ergonomics in the browser on minute one—and iterate until the gesture feels invisible.
Try Origami Hand Detection Live
Allow camera access and hold up 0–5 fingers to fold Pikachu in real time—or press keys 0–5 to scrub all six steps.