Lab: Build

Holo Card Pack: A Card Pack Opening Animation You Tear With Your Mouse

A trading card pack opening animation that runs in the browser: drag to tear the foil, a rainbow burst and confetti, then five 3D characters fly round into a row and react to your cursor. JavaScript, Canvas and three.js, no game engine.

We saw a short clip of a pack-opening interaction: you drag across a foil pack, it peels open, light spills out and the cards fly round into a row. We wanted to know if the whole thing could run in a browser, with real 3D characters, no game engine and no video file. It can. Open it at alphenex.com/lab/holo-card-pack and tear one yourself.

There are two outputs: the interactive page linked here, and the 4K 60fps video below, rendered from that same page, frame by frame. This post shows how each part works, with the real code, and ends with a prompt you can paste into Claude Code (or any coding agent) to build your own.

The short version

Everything sits on a fixed 1920 by 1080 stage that is scaled to fit the screen. One tiny spring class moves every number on it. The pack is a painted canvas, the tear is a single value that only moves forward, the rainbow is 30 ribbons drawn on a 2D canvas, and the five characters are three.js scenes rendered into ordinary canvases on each card. A recorded mouse path lets the page replay itself, and a frame-stepping mode turns it into a video.

The rendered video: the blue COBALT pack, the tear, the rainbow burst, the carousel, every hover reaction, then a second BUBBLEGUM pack. 19.2 seconds, rendered from the live page.

Step 1: one stage, one spring

Every coordinate in the code is in 1920 by 1080 pixels. A single transform scales the stage to the window, so the layout never changes on a phone; it just gets smaller. Pointer positions are mapped back into stage pixels before anything uses them.

function layout(){
  S = Math.min(innerWidth / W, innerHeight / H);
  OX = (innerWidth - W * S) / 2; OY = (innerHeight - H * S) / 2;
  stage.style.transform = 'translate(' + OX + 'px,' + OY + 'px) scale(' + S + ')';
}
const toStage = e => [(e.clientX - OX) / S, (e.clientY - OY) / S];

Then one spring does all the motion: pack tilt, card position, rotation, scale, hover lift and the characters' eyes. A spring has a target, and each frame it accelerates toward it and loses some speed to damping. Lower damping overshoots more, which is where the bounce comes from.

class Spring {
  constructor(v, k = 150, c = 20){ this.v = v; this.t = v; this.vel = 0; this.k = k; this.c = c; }
  step(dt){ const a = this.k * (this.t - this.v) - this.c * this.vel; this.vel += a * dt; this.v += this.vel * dt; }
  set(v){ this.v = this.t = v; this.vel = 0; }
}

Step 2: the pack

The pack is painted once on a canvas: a rounded foil body in the theme colour with a lighter and darker band, a crimped top and bottom, the "holo" name strip and a soft-light sheen layer on top. A 3D star mascot sits on the front. While you are not touching it, the pack bobs on slow sine waves and tilts a few degrees toward the pointer; the star's eyes follow the pointer too, and it smiles when you hover over the pack.

Five colour themes (COBALT, BUBBLEGUM, MINT, TANGERINE, GRAPE) are just five sets of three colours, so "Open another pack" repaints the same canvas in a new theme.

Step 3: the tear

The whole tear is one number: how far along the top edge it has opened. Pressing near the top of the pack starts it. Moving the pointer sets a target, and the target only ever grows, so pulling back never closes the pack.

function onMove(x, y){
  if (tear.active && !tear.done){
    const r = packRect();
    tear.target = Math.max(tear.target, clamp(x - r.l, 0, PW * 1.1));
  }
}
// each frame: ease toward the target, with a minimum speed so it never stalls
if (tear.target > tear.x){
  const d = tear.target - tear.x;
  tear.x += Math.min(d * (1 - Math.exp(-6.5 * dt)), Math.max(90, d * 2.2) * dt * 4.2);
}
if (!tear.done && tear.x >= PW * 0.78) completeTear();

While it opens, three small things sell it: the pack shakes in proportion to how far the pointer is ahead of the tear, rainbow wisps leak out of the opening, and the star squints. The torn strip is drawn as a curl that peels away from a jagged line made of random 3px steps. At 78% the strip detaches and becomes a ribbon of points with distance constraints (simple verlet physics), so it dangles from the cursor until you let go and then falls.

Step 4: the rainbow burst

The rainbow is not an image. It is 30 ribbons, each a path that leaves the pack mouth at its own angle and bends upward as it travels. A sine wave runs along every path, so the whole fan ripples. Each ribbon is filled between its own path and the next one, gets a glossy highlight, and the gaps between ribbons are stroked in thin white.

The soft look comes from erasing, not from adding. Two radial gradients are drawn with destination-out, one fading the inner end as the rainbow retracts and one fading the far tips, then a white glow is added at the mouth and four-point twinkles ride along the ribbons.

c.globalCompositeOperation = 'destination-out';
let g = c.createRadialGradient(ox, oy, Math.max(0, s0 - 30), ox, oy, s0 + 150);
g.addColorStop(0, 'rgba(0,0,0,1)'); g.addColorStop(1, 'rgba(0,0,0,0)');
c.fillStyle = g; c.fillRect(0, 0, W, H);   // fade the inner end
g = c.createRadialGradient(ox, oy, 560, ox, oy, 980);
g.addColorStop(0, 'rgba(0,0,0,0)'); g.addColorStop(1, 'rgba(0,0,0,1)');
c.fillStyle = g; c.fillRect(0, 0, W, H);   // fade the far tips
c.globalCompositeOperation = 'source-over';

At the same moment three waves of confetti fire (240, then 90, then 70 pieces, a fraction of a second apart) and the pack drops away under gravity.

Step 5: the cards fly round

This is the part that took the most care. We measured where each card sat in the reference clip, frame by frame, and wrote one function that returns a card's pose for any moment of the burst. It blends three movements: shoot up out of the pack, swing round a tilted ring (cards at the front of the ring are bigger), then flatten into the row.

function cardPose(c, bt){
  // 1) shoot out of the pack
  const ue = clamp((bt - 0.025 * c.k) / 0.3, 0, 1), ee = 1 - Math.pow(1 - ue, 3);
  const ex = lerp(c.start[0], c.top[0], ee), ey = lerp(c.start[1], c.top[1], ee) - Math.sin(ue * Math.PI) * 40;
  // 2) swing round a tilted ring that opens up and flattens
  const u = clamp((bt - 0.3) / 1.15, 0, 1), e = 1 - Math.pow(1 - u, 2.3);
  const phi = (180 - 45 * c.slot + D0[c.slot] * (1 - e)) * deg;
  const Rx = lerp(300, 630, e), Ry = 170 * (1 - smooth(0.45, 0.88, u));
  // 3) slide into the row
  const rowX = 330 + c.slot * 315, flat = smooth(0.52, 1, u);
  const rx = lerp(Cx + Rx * Math.cos(phi), rowX, flat), ry = Cy + Ry * Math.sin(phi);
  const w = smooth(0.24, 0.52, bt);                    // hand-off from phase 1 to the ring
  const depth = Math.sin(phi) * (Ry / 170);            // front of the ring = bigger
  return { x: lerp(ex, rx, w), y: lerp(ey, ry, w), sc: lerp(1.06, 1 + 0.2 * depth, w) };
}

(Trimmed: the real function also returns rotation and stacking order.) Because the pose is a pure function of time, the burst is identical every time and can be slowed down with one constant: the whole sequence plays at 1.5 times the reference length, which is what makes it feel smooth rather than snappy. When the last card lands, every card hands over to its springs, which is how they lift and tilt on hover.

Step 6: 3D characters with three.js

The five characters (Blip, Ringo, Cubit, Facet, Nova) and the star on the pack are real 3D models built from code: a sphere, a sphere with a torus ring, a rounded cube, a faceted gem and an inflated star. Each one uses a glossy MeshPhysicalMaterial with a clearcoat and is lit by a room environment, a key light and a rim light.

const m = new THREE.Mesh(
  new THREE.SphereGeometry(1, 96, 64),
  new THREE.MeshPhysicalMaterial({ color: 0xff2e1f, roughness: 0.16, clearcoat: 1, clearcoatRoughness: 0.04, sheen: 0.4 })
);

Only one WebGL renderer exists. Each character renders into it and the result is copied into a plain 2D canvas on its card, so five cards do not need five WebGL contexts. The faces are drawn on a separate canvas texture wrapped on a thin shell over the body, which makes expressions cheap: blinking, eyes following the pointer, a heart-eyes look, a wink, a "wow" mouth and star eyes are all just different drawings. A springy squash on every expression change makes them pop.

Step 7: the holographic card effect

The rare cards shimmer when you move the pointer over them. That is one CSS layer: a rainbow linear gradient blended with color-dodge, three times larger than the card, whose position follows the pointer. A grain layer made from an inline SVG noise filter stops it looking like flat plastic.

.card .holo{
  position:absolute; inset:0; mix-blend-mode:color-dodge; opacity:0;
  background:linear-gradient(115deg, transparent 8%, rgba(255,0,170,.55) 22%, rgba(0,255,210,.45) 36%,
    rgba(255,240,0,.40) 50%, rgba(0,150,255,.5) 64%, rgba(255,0,200,.45) 78%, transparent 92%);
  background-size:300% 300%;
  background-position:var(--hx,50%) var(--hy,50%);
}

Common cards get none, rare cards a little, and the ultra rare Nova the most, so rarity is visible at a glance.

Step 8: from a web page to a 4K video

To match the reference clip we tracked the mouse cursor through every frame of it with OpenCV template matching, cleaned up the path and saved it as demo-track.js. Adding ?demo to the page replays that exact path with a drawn cursor, including the presses, so the page performs the same sequence as the clip.

For the video, ?capture turns off the real clock. The page exposes a step function, a Playwright script advances it by exactly 1/60 of a second, screenshots the stage at 2x and pipes the frames to ffmpeg. No dropped frames, no timing drift, and the output is a 3840 by 2160, 60fps MP4.

// in the page
if (CAPTURE) window.__step = (n = 1) => { for (let i = 0; i < n; i++) frame(1 / 60); return T; };

# in the capture script (Python + Playwright)
page.goto('http://127.0.0.1:8765/index.html?capture')
for i in range(int(seconds * fps)):
    page.evaluate('window.__step(1)')
    ffmpeg.stdin.write(page.screenshot(type='png'))

The small things

  • Seeded randomness. In demo and capture mode the random generator is seeded, so the jagged tear, the confetti and the card order are identical on every run.
  • A second pack. "Open another pack" brings in a pink BUBBLEGUM pack that spins in from the right, and the cards come out in a new order.
  • It works on touch. Everything listens to pointer events, so a finger tears the pack the same way a mouse does.
  • Sharp at any size. The effect canvases are sized from the stage scale and the device pixel ratio, capped at 2x, so it is crisp on a retina screen without wasting memory on a 4K monitor.
  • One file. The whole page is a single HTML file plus the recorded mouse path. three.js is the only dependency, loaded from a CDN with an import map.

Build your own

Paste this into Claude Code, Cursor or another coding agent. Ask for one part at a time if the first version is rough: the tear first, then the burst, then the card path, then the characters.

The prompt
Build a single-file web page (HTML, CSS, JavaScript, three.js from a CDN, no other libraries) of a trading card pack you tear open with the mouse.

Stage: a fixed 1920x1080 stage scaled to fit the window, warm off-white radial background. One Spring class (k, c, value, velocity) drives every moving number.

Pack: a glossy foil pack (356x498) painted on a canvas, with a theme colour, a name strip ("holo", "COBALT") and a cute 3D star mascot on the front. It bobs and tilts toward the pointer and the mascot's eyes follow it. Hovering makes the mascot smile.

Tear: press near the top edge and drag right. The tear position eases toward the furthest point the pointer has reached (never backwards), the pack shakes slightly while you pull, rainbow wisps leak out of the opening, and the mascot squints. At 78% of the width the strip detaches as a falling ribbon (verlet points with distance constraints) that hangs from the cursor until you let go.

Burst: 30 soft pastel ribbons fan out of the pack mouth and curve upward, each with a travelling sine wave, a thin white gap between ribbons, a glossy highlight, a white glow at the mouth and small four-point twinkles. Fade the inner end and the far tips with destination-out gradients. Fire three waves of confetti. The pack drops away with gravity.

Cards: five cards (290x420) shoot out of the pack, swing round a tilted carousel ring with the front ones larger, then flatten into a row with a slight fan of rotations. Each card has a 3D character rendered with three.js into a 2D canvas (glossy MeshPhysicalMaterial with clearcoat, a face drawn on a CanvasTexture), a name, a tag, a number and a rarity. Rare cards get a holographic color-dodge gradient whose position follows the pointer.

Hover: the hovered card lifts, tilts toward the pointer and its character changes expression (happy, heart eyes, wink, "wow", star eyes). After the row settles, show an "Open another pack" button that brings in a new pack in a different colour that spins in from the right.

Make the whole burst 1.5x slower than feels natural so it reads as smooth. Support ?demo to replay a recorded pointer path and ?capture to step frames deterministically for video export.

To make it yours, swap the characters for your products or mascots, change the five pack themes to your brand colours and replace the card text. To put it on a site, host the page and embed it in an iframe, or port the script into a React component that owns one canvas and one animation loop. Load it only when it scrolls into view (the demo above waits for a click), because three.js and the 3D rendering are the heaviest part.

Where this is useful

A pack opening is a reveal, and reveals work anywhere a brand wants a moment of surprise: a drop or launch page, a reward after sign-up, a loyalty or referral prize, a product configurator, a collectible campaign or an interactive ad. It is also a good test of a front-end team, because it combines physics, Canvas, WebGL, CSS and careful timing in one small page.

We build interactive pieces like this as part of our custom website development work. If you want one for your brand, tell us what you are launching.

Topics in this article

  • Card pack animation
  • Holographic cards
  • three.js
  • Canvas
  • Creative coding
  • Claude Code

Sources

  1. 1
  2. 2
  3. 3
    MDN: mix-blend-mode
    · developer.mozilla.org

Frequently asked questions

Scale a fixed stage to the screen, move everything with one spring, track the tear as a single value that only grows as the pointer moves along the top of the pack, then on completion draw a burst on a canvas and move each card along a time-based path out of the pack and into a row. This demo uses plain JavaScript, Canvas and three.js.

Continue reading

Share this article

Joydip Bhakta, Alphenex
Written by

Co-Founder

Joydip leads digital strategy, content planning, social media growth, branding, and customer acquisition at Alphenex. He designs the channel mix and brand systems that turn qualified attention into measurable pipeline for every client engagement.

  • Social media strategy & UGC planning
  • Performance marketing
  • Google Ads & Meta Ads
  • B2B lead generation
  • Conversion optimization
  • Brand identity & creative direction
LinkedIn