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 single HTML file that creates a squishy, interactive 3D cube using Three.js. You can click and drag to rotate the cube, and it has a soft, squishy appearance with a jelly-like material:
<!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; overflow: hidden; background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%); font-family: Arial, sans-serif; } canvas { display: block; } #info { position: absolute; top: 10px; width: 100%; text-align: center; color: #333; font-size: 14px; pointer-events: none; } </style> </head> <body> <div id="info">Click and drag to rotate the squishy cube!</div> <script src="https://cdn.jsdelivr.net/npm/three@0.132.2/build/three.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/three@0.132.2/examples/js/controls/OrbitControls.js"></script> <script> // Initialize the scene const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); const renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setSize(window.innerWidth, window.innerHeight); renderer.setPixelRatio(window.devicePixelRatio); document.body.appendChild(renderer.domElement); // Add orbit controls const controls = new THREE.OrbitControls(camera, renderer.domElement); controls.enableDamping = true; controls.dampingFactor = 0.05; controls.rotateSpeed = 0.5; // Position the camera camera.position.z = 5; // Create a squishy cube with a jelly-like material const geometry = new THREE.BoxGeometry(2, 2, 2, 32, 32, 32); // Custom shader material for squishy effect const material = new THREE.MeshPhysicalMaterial({ color: 0xff6b6b, transparent: true, opacity: 0.9, metalness: 0.1, roughness: 0.3, clearcoat: 0.5, clearcoatRoughness: 0.1, transmission: 0.8, thickness: 1.5, ior: 1.5, specularIntensity: 0.5, envMapIntensity: 0.5, side: THREE.DoubleSide }); const cube = new THREE.Mesh(geometry, material); scene.add(cube); // Add subtle animation to make it feel squishy let time = 0; const originalPositions = geometry.attributes.position.array.slice(); function animate() { requestAnimationFrame(animate); // Squishy animation time += 0.01; const positions = geometry.attributes.position.array; for (let i = 0; i < positions.length; i += 3) { // Get original position const x = originalPositions[i]; const y = originalPositions[i + 1]; const z = originalPositions[i + 2]; // Calculate distance from center const distance = Math.sqrt(x * x + y * y + z * z); // Apply squishy effect based on distance and time const squishFactor = 0.1 * Math.sin(time + distance * 2) * (0.5 + 0.5 * Math.sin(time * 0.3)); // Apply the squish effect more to the edges const edgeFactor = Math.pow(Math.abs(x), 3) + Math.pow(Math.abs(y), 3) + Math.pow(Math.abs(z), 3); const finalSquish = squishFactor * (0.5 + edgeFactor * 0.5); positions[i] = x + x * finalSquish; positions[i + 1] = y + y * finalSquish; positions[i + 2] = z + z * finalSquish; } geometry.attributes.position.needsUpdate = true; // Rotate the cube slightly for more dynamic feel cube.rotation.x += 0.005; cube.rotation.y += 0.005; controls.update(); renderer.render(scene, camera); } // Handle window resize window.addEventListener('resize', () => { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth, window.innerHeight); }); // Add some ambient light const ambientLight = new THREE.AmbientLight(0xffffff, 0.5); scene.add(ambientLight); // Add directional light const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8); directionalLight.position.set(1, 1, 1); scene.add(directionalLight); // Start animation animate(); </script> </body> </html>This HTML file creates:
- A squishy, jelly-like cube with a soft, translucent appearance
- Interactive controls - you can click and drag to rotate the cube
- A subtle squishy animation that makes the cube appear to breathe and deform slightly
- Realistic lighting with both ambient and directional light sources
- A responsive design that works on different screen sizes
The cube uses a custom shader material with properties that give it a soft, squishy appearance, and the vertices are animated to create the squishy effect. The cube will automatically rotate slightly to give it a more dynamic feel.
You can save this code as a single HTML file and open it in any modern browser to see the squishy interactive cube.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.