Make me a squishy interactive cube in a single html file
- User
Make me a squishy interactive cube in a single html file
Assistant
Here's a squishy interactive cube in a single HTML file:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Squishy Interactive Cube</title> <style> body { margin: 0; padding: 0; height: 100vh; display: flex; justify-content: center; align-items: center; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); overflow: hidden; cursor: grab; } body:active { cursor: grabbing; } .scene { width: 200px; height: 200px; perspective: 1000px; } .cube { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transform: rotateX(-20deg) rotateY(-30deg); transition: transform 0.1s ease-out; } .cube.squishing { animation: squish 0.3s ease-out; } @keyframes squish { 0%, 100% { transform: rotateX(var(--rotX)) rotateY(var(--rotY)) scale3d(1, 1, 1); } 50% { transform: rotateX(var(--rotX)) rotateY(var(--rotY)) scale3d(1.2, 0.8, 1.2); } } .face { position: absolute; width: 200px; height: 200px; border: 2px solid rgba(255, 255, 255, 0.3); border-radius: 20px; background: rgba(255, 255, 255, 0.1); backdrop-filter: blur(10px); box-shadow: inset 0 0 30px rgba(255, 255, 255, 0.2); } .face::before { content: ''; position: absolute; top: 10%; left: 10%; width: 30%; height: 30%; background: radial-gradient(circle, rgba(255, 255, 255, 0.4) 0%, transparent 70%); border-radius: 50%; } .front { transform: rotateY( 0deg) translateZ(100px); background: rgba(255, 100, 100, 0.3); } .back { transform: rotateY(180deg) translateZ(100px); background: rgba(100, 255, 100, 0.3); } .right { transform: rotateY( 90deg) translateZ(100px); background: rgba(100, 100, 255, 0.3); } .left { transform: rotateY(-90deg) translateZ(100px); background: rgba(255, 255, 100, 0.3); } .top { transform: rotateX( 90deg) translateZ(100px); background: rgba(255, 100, 255, 0.3); } .bottom { transform: rotateX(-90deg) translateZ(100px); background: rgba(100, 255, 255, 0.3); } .instructions { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); color: white; font-family: Arial, sans-serif; text-align: center; opacity: 0.8; } </style> </head> <body> <div class="scene"> <div class="cube" id="cube"> <div class="face front"></div> <div class="face back"></div> <div class="face right"></div> <div class="face left"></div> <div class="face top"></div> <div class="face bottom"></div> </div> </div> <div class="instructions"> Drag to rotate • Click to squish </div> <script> const cube = document.getElementById('cube'); let isDragging = false; let currentX, currentY; let rotationX = -20; let rotationY = -30; let velocityX = 0; let velocityY = 0; // Mouse events document.addEventListener('mousedown', (e) => { isDragging = true; currentX = e.clientX; currentY = e.clientY; }); document.addEventListener('mousemove', (e) => { if (!isDragging) return; const deltaX = e.clientX - currentX; const deltaY = e.clientY - currentY; rotationY += deltaX * 0.5; rotationX -= deltaY * 0.5; velocityX = deltaX * 0.5; velocityY = deltaY * 0.5; cube.style.setProperty('--rotX', rotationX + 'deg'); cube.style.setProperty('--rotY', rotationY + 'deg'); cube.style.transform = `rotateX(${rotationX}deg) rotateY(${rotationY}deg)`; currentX = e.clientX; currentY = e.clientY; }); document.addEventListener('mouseup', () => { isDragging = false; applyInertia(); }); // Touch events for mobile document.addEventListener('touchstart', (e) => { isDragging = true; currentX = e.touches[0].clientX; currentY = e.touches[0].clientY; }); document.addEventListener('touchmove', (e) => { if (!isDragging) return; e.preventDefault(); const deltaX = e.touches[0].clientX - currentX; const deltaY = e.touches[0].clientY - currentY; rotationY += deltaX * 0.5; rotationX -= deltaY * 0.5; velocityX = deltaX * 0.5; velocityY = deltaY * 0.5; cube.style.setProperty('--rotX', rotationX + 'deg'); cube.style.setProperty('--rotY', rotationY + 'deg'); cube.style.transform = `rotateX(${rotationX}deg) rotateY(${rotationY}deg)`; currentX = e.touches[0].clientX; currentY = e.touches[0].clientY; }); document.addEventListener('touchend', () => { isDragging = false; applyInertia(); }); // Click to squish cube.addEventListener('click', (e) => { if (!isDragging) { cube.classList.add('squishing'); setTimeout(() => { cube.classList.remove('squishing'); }, 300); } }); // Inertia effect function applyInertia() { const friction = 0.95; function animate() { if (Math.abs(velocityX) > 0.1 || Math.abs(velocityY) > 0.1) { rotationY += velocityX; rotationX -= velocityY; cube.style.transform = `rotateX(${rotationX}deg) rotateY(${rotationY}deg)`; velocityX *= friction; velocityY *= friction; requestAnimationFrame(animate); } } animate(); } // Auto-rotate when idle let idleTimer; let autoRotating = false; function startAutoRotate() { autoRotating = true; function rotate() { if (autoRotating && !isDragging) { rotationY += 0.5; cube.style.transform = `rotateX(${rotationX}deg) rotateY(${rotationY}deg)`; requestAnimationFrame(rotate); } } rotate(); } function resetIdleTimer() { autoRotating = false; clearTimeout(idleTimer); idleTimer = setTimeout(startAutoRotate, 3000); } document.addEventListener('mousedown', resetIdleTimer); document.addEventListener('touchstart', resetIdleTimer); // Start idle timer resetIdleTimer(); </script> </body> </html>This creates an interactive 3D cube with the following features:
- Drag to rotate: Click and drag (or touch and drag on mobile) to rotate the cube in 3D space
- Click to squish: Click on the cube to trigger a squish animation
- Inertia: When you release after dragging, the cube continues rotating with momentum that gradually slows down
- Auto-rotate: After 3 seconds of inactivity, the cube starts slowly rotating on its own
- Glass-like appearance: Each face has a translucent, frosted glass effect with subtle highlights
- Responsive: Works on both desktop and mobile devices
The cube has a modern, squishy feel with smooth animations and a colorful gradient background. Each face has a different tint color to make the 3D effect more visible.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.