o3-2025-04-16· OpenAI
LMArena Human Preference 140K
Make me a squishy interactive cube in a single html file
- User
Make me a squishy interactive cube in a single html file
- Assistant
Below is a single, self-contained HTML file that renders a “squishy” 3-D cube.
• Drag with the mouse (or touch) to rotate it.
• Click / tap anywhere on the cube to see it “squish” and spring back.<!DOCTYPE html> <html lang="en"> <meta charset="UTF-8"> <title>Squishy Interactive Cube</title> <style> /* ---- Reset / layout ---------------------------------------------- */ *{box-sizing:border-box;margin:0;padding:0} html,body{height:100%;width:100%;display:flex;align-items:center; justify-content:center;background:#111;font-family:sans-serif;overflow:hidden} /* ---- Scene & Cube ------------------------------------------------- */ .scene{ width:300px; /* size of the viewport cube sits in */ height:300px; perspective: 800px; /* depth perception */ cursor: grab; } .cube{ position:relative; width:100%; height:100%; transform-style:preserve-3d; transition:transform .15s cubic-bezier(.26,.53,.74,1.48); /* snap-back after drag */ } /* ---- Faces -------------------------------------------------------- */ .face{ position:absolute; width:100%; height:100%; border:2px solid #fff; background:rgba(0,180,255,.8); display:flex; align-items:center; justify-content:center; font-size:2rem; color:#fff; font-weight:bold; backface-visibility:hidden; } /* individual face transforms */ .front {transform:translateZ(150px);} .back {transform:rotateY(180deg) translateZ(150px);} .right {transform:rotateY( 90deg) translateZ(150px);} .left {transform:rotateY(-90deg) translateZ(150px);} .top {transform:rotateX( 90deg) translateZ(150px);} .bottom {transform:rotateX(-90deg) translateZ(150px);} /* Slightly different hues for fun */ .front {background:rgba(0,180,255,.85);} .back {background:rgba(0,140,255,.85);} .right {background:rgba(0,200,220,.85);} .left {background:rgba(0,160,220,.85);} .top {background:rgba(0,190,255,.85);} .bottom {background:rgba(0,150,255,.85);} /* ---- Squish animation -------------------------------------------- */ @keyframes squish { 0% {transform:scale3d(1,1,1) rotateX(var(--rx)) rotateY(var(--ry));} 35% {transform:scale3d(.75, .75, 1.25) rotateX(calc(var(--rx)*1deg)) rotateY(calc(var(--ry)*1deg));} 55% {transform:scale3d(1.15,1.15,.85) rotateX(calc(var(--rx)*1deg)) rotateY(calc(var(--ry)*1deg));} 100% {transform:scale3d(1,1,1) rotateX(calc(var(--rx)*1deg)) rotateY(calc(var(--ry)*1deg));} } .cube.squish{ animation:squish .4s ease-out; } </style> <body> <div class="scene"> <div class="cube" id="cube"> <div class="face front">1</div> <div class="face back">2</div> <div class="face right">3</div> <div class="face left">4</div> <div class="face top">5</div> <div class="face bottom">6</div> </div> </div> <script> /* --------------------------------------------------------------- Rotatable + Squishy Cube -----------------------------------------------------------------*/ (() =>{ const cube = document.getElementById('cube'); const scene = document.querySelector('.scene'); let isDown = false, startX, startY; let rotX = -30, rotY = 30; // initial orientation // apply rotation to CSS vars (for squish keyframes too) function updateCube(){ cube.style.setProperty('--rx', rotX); // needed for keyframe var() cube.style.setProperty('--ry', rotY); cube.style.transform = `rotateX(${rotX}deg) rotateY(${rotY}deg)`; } updateCube(); /* ---- Drag to rotate ------------------------------------------------- */ scene.addEventListener('pointerdown', e=>{ isDown = true; scene.setPointerCapture(e.pointerId); startX = e.clientX; startY = e.clientY; scene.style.cursor='grabbing'; addSquish(); // little squish on grab }); scene.addEventListener('pointermove', e=>{ if(!isDown) return; const dx = e.clientX - startX; const dy = e.clientY - startY; startX = e.clientX; startY = e.clientY; rotY += dx * 0.5; rotX -= dy * 0.5; updateCube(); }); scene.addEventListener('pointerup', e=>{ isDown=false; scene.releasePointerCapture(e.pointerId); scene.style.cursor='grab'; addSquish(); // squish on release }); /* ---- Click/Tap squish ----------------------------------------------- */ scene.addEventListener('click', addSquish); scene.addEventListener('touchend', addSquish); function addSquish(){ cube.classList.remove('squish'); // restart animation void cube.offsetWidth; // force reflow cube.classList.add('squish'); } })(); </script> </body> </html>How it works (in a nutshell)
- The
.sceneprovides a 3-D perspective; the.cubekeeps its faces inpreserve-3dspace. - Faces are absolutely positioned, each moved 150 px along the Z-axis (half of cube size) then rotated as needed.
- Pointer events update
rotX/rotYangles; CSS variables--rx/--ryare reused inside the@keyframesso the cube squishes relative to its current orientation. - A quick
@keyframes squishscales the cube in X/Y vs. Z to simulate a satisfying “smoosh → bounce” effect.
Drop the file in a browser and enjoy your squishy interactive cube!
- The
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.