Lava lamp v1 · Antigravity CLI19.11.2026 02:49
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>Lava Lamp</title><style> *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; } :root { --power: 1; --lamp-scale: min(1, calc(100dvh / 720px), calc(100vw / 380px)); } html, body { width: 100%; height: 100dvh; overflow: hidden; background: #0b0910; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; user-select: none; touch-action: manipulation; } .scene { position: relative; width: 100%; height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; background: radial-gradient(circle at 50% 44%, #1a1224 0%, #0d0a14 55%, #07050a 100%); overflow: hidden; } /* Ambient wall glow behind the lamp */ .wall-glow { position: absolute; left: 50%; bottom: 24dvh; width: min(92vw, 520px); height: min(68dvh, 560px); transform: translateX(-50%); background: radial-gradient(ellipse at 50% 62%, rgba(255, 118, 42, 0.34) 0%, rgba(214, 48, 98, 0.16) 36%, rgba(88, 28, 125, 0.06) 62%, transparent 78%); filter: blur(28px); opacity: var(--power); transition: opacity 0.9s ease; pointer-events: none; z-index: 1; } /* Desk surface */ .desk { position: relative; width: 100%; height: 24dvh; min-height: 120px; max-height: 210px; z-index: 2; background: repeating-linear-gradient( 90deg, rgba(255, 255, 255, 0.012) 0px, rgba(255, 255, 255, 0.012) 2px, transparent 2px, transparent 9px ), linear-gradient( 180deg, #3a2921 0%, #2b1d17 18%, #1e1410 72%, #140d0a 100% ); box-shadow: inset 0 2px 0 rgba(255, 220, 190, 0.08), 0 -12px 40px rgba(0, 0, 0, 0.65); } /* Subtle warm pool of light reflected on the wooden desk */ .desk-glow { position: absolute; top: -10px; left: 50%; transform: translateX(-50%); width: min(86vw, 440px); height: 120px; background: radial-gradient(ellipse at 50% 25%, rgba(255, 130, 56, 0.42) 0%, rgba(215, 58, 96, 0.18) 42%, transparent 74%); filter: blur(14px); opacity: var(--power); transition: opacity 0.9s ease; pointer-events: none; } /* Desk front bevel */ .desk::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 16px; background: linear-gradient(180deg, #160e0b 0%, #0c0706 100%); border-top: 1px solid rgba(255, 210, 180, 0.05); } /* Lamp + cord + switch stage anchored to desk top */ .lamp-stage { position: absolute; bottom: calc(24dvh - 34px); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; z-index: 5; pointer-events: none; } @media (max-height: 500px) { .lamp-stage { bottom: calc(120px - 34px); } } @media (min-height: 875px) { .lamp-stage { bottom: calc(210px - 34px); } } /* Contact shadow under lamp base */ .lamp-shadow { position: absolute; bottom: -8px; left: 50%; transform: translateX(-50%); width: 170px; height: 26px; background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.82) 0%, rgba(0, 0, 0, 0.35) 55%, transparent 75%); filter: blur(4px); z-index: 0; } .lamp { position: relative; display: flex; flex-direction: column; align-items: center; transform-origin: bottom center; transform: scale(clamp(0.56, min(calc(72dvh / 490px), calc(82vw / 240px)), 1.12)); z-index: 2; } /* Top metallic cap */ .cap { position: relative; width: 78px; height: 44px; margin-bottom: -6px; z-index: 4; clip-path: polygon(18% 0%, 82% 0%, 100% 100%, 0% 100%); background: linear-gradient( 90deg, #1b1c22 0%, #3a3d47 18%, #7c8190 34%, #484b56 52%, #272930 74%, #464954 90%, #1a1b20 100% ); border-radius: 6px 6px 0 0; box-shadow: inset 0 2px 3px rgba(255, 255, 255, 0.28); } .cap-rim { width: 82px; height: 7px; margin-bottom: -3px; z-index: 5; border-radius: 4px; background: linear-gradient( 90deg, #18191e 0%, #595d6a 28%, #8b90a0 40%, #32353f 68%, #17181d 100% ); box-shadow: 0 2px 5px rgba(0, 0, 0, 0.55); } /* Glass vessel canvas */ .glass-wrap { position: relative; width: 210px; height: 310px; z-index: 3; filter: drop-shadow(0 0 18px rgba(255, 104, 46, calc(var(--power) * 0.25))); transition: filter 0.8s ease; } #lava-canvas { display: block; width: 210px; height: 310px; } /* Lower metallic collar & hourglass base */ .base-collar { position: relative; width: 126px; height: 12px; margin-top: -8px; z-index: 5; border-radius: 6px; background: linear-gradient( 90deg, #1b1c22 0%, #4b4f5c 25%, #8f94a3 38%, #3b3e48 64%, #1c1d23 100% ); box-shadow: 0 -2px 10px rgba(255, 150, 64, calc(var(--power) * 0.55)), 0 3px 6px rgba(0, 0, 0, 0.5); transition: box-shadow 0.8s ease; } .base-upper { width: 120px; height: 46px; margin-top: -2px; z-index: 4; clip-path: polygon(0% 0%, 100% 0%, 72% 100%, 28% 100%); background: linear-gradient( 90deg, #17181d 0%, #363943 20%, #777c8b 36%, #424550 54%, #22242b 76%, #3d404b 90%, #14151a 100% ); } .base-lower { position: relative; width: 146px; height: 68px; margin-top: -2px; z-index: 3; clip-path: polygon(27% 0%, 73% 0%, 100% 92%, 96% 100%, 4% 100%, 0% 92%); background: linear-gradient( 90deg, #15161b 0%, #343742 18%, #7a7f8e 35%, #3e414c 55%, #1f2128 76%, #414551 90%, #141519 100% ); } .base-foot { width: 148px; height: 9px; margin-top: -4px; z-index: 2; border-radius: 0 0 12px 12px; background: linear-gradient(90deg, #101114, #2b2d35 35%, #16171c 75%, #0c0d10); box-shadow: 0 5px 12px rgba(0, 0, 0, 0.75); } /* Power cord & inline desk switch */ .cord-layer { position: absolute; left: 0; right: 0; bottom: 0; height: 24dvh; min-height: 120px; max-height: 210px; pointer-events: none; z-index: 6; } .cord-svg { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); width: min(94vw, 440px); height: 110px; overflow: visible; } .switch-dock { position: absolute; left: 50%; bottom: clamp(18px, 4.5dvh, 42px); transform: translateX(-50%); display: flex; align-items: center; gap: 12px; pointer-events: auto; z-index: 10; } .switch-btn { position: relative; display: inline-flex; align-items: center; gap: 10px; padding: 10px 16px 10px 14px; min-height: 46px; border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 999px; background: linear-gradient(180deg, #27252e 0%, #17161c 100%); color: #e9e4df; font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; cursor: pointer; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.14); transition: transform 0.12s ease, box-shadow 0.25s ease, border-color 0.25s ease; outline: none; } .switch-btn:active { transform: translateY(1px) scale(0.98); } .switch-btn:focus-visible { border-color: rgba(255, 160, 82, 0.8); box-shadow: 0 0 0 3px rgba(255, 140, 62, 0.28), 0 8px 20px rgba(0, 0, 0, 0.65); } .toggle-track { position: relative; width: 44px; height: 24px; border-radius: 999px; background: #0e0d12; box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.85); transition: background 0.25s ease; } .switch-btn[aria-pressed="true"] .toggle-track { background: linear-gradient(90deg, #c93b5b, #ff8b38); } .toggle-thumb { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: linear-gradient(180deg, #f3f0ec 0%, #b7b3ae 100%); box-shadow: 0 2px 5px rgba(0, 0, 0, 0.55); transition: transform 0.22s cubic-bezier(0.34, 1.4, 0.64, 1); } .switch-btn[aria-pressed="true"] .toggle-thumb { transform: translateX(20px); } .led { width: 7px; height: 7px; border-radius: 50%; background: #3a343b; box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.6); transition: background 0.25s ease, box-shadow 0.25s ease; } .switch-btn[aria-pressed="true"] .led { background: #ff9c42; box-shadow: 0 0 8px #ff8528, 0 0 2px #fff2d6; } .switch-label { min-width: 30px; text-align: left; }</style></head><body><main class="scene" id="scene"> <div class="wall-glow" aria-hidden="true"></div> <div class="lamp-stage"> <div class="lamp-shadow" aria-hidden="true"></div> <div class="lamp"> <div class="cap" aria-hidden="true"></div> <div class="cap-rim" aria-hidden="true"></div> <div class="glass-wrap"> <canvas id="lava-canvas" width="420" height="620" aria-label="Glass lava lamp with rising and sinking wax blobs"></canvas> </div> <div class="base-collar" aria-hidden="true"></div> <div class="base-upper" aria-hidden="true"></div> <div class="base-lower" aria-hidden="true"></div> <div class="base-foot" aria-hidden="true"></div> </div> </div> <div class="desk" aria-hidden="true"> <div class="desk-glow"></div> </div> <div class="cord-layer"> <svg class="cord-svg" viewBox="0 0 400 110" fill="none" aria-hidden="true"> <path d="M 248 16 C 305 24, 338 52, 286 74 C 258 86, 232 84, 218 84" stroke="#0e0c10" stroke-width="6" stroke-linecap="round" opacity="0.6" transform="translate(0, 3)"/> <path d="M 248 16 C 305 24, 338 52, 286 74 C 258 86, 232 84, 218 84" stroke="#1e1c23" stroke-width="5" stroke-linecap="round"/> <path d="M 248 16 C 305 24, 338 52, 286 74 C 258 86, 232 84, 218 84" stroke="rgba(255,255,255,0.08)" stroke-width="1.2" stroke-linecap="round"/> </svg> <div class="switch-dock"> <button id="power-switch" class="switch-btn" type="button" aria-pressed="true" aria-label="Toggle lava lamp power"> <span class="led" aria-hidden="true"></span> <span class="toggle-track" aria-hidden="true"> <span class="toggle-thumb"></span> </span> <span class="switch-label" id="switch-label">On</span> </button> </div> </div></main><script>(() => { 'use strict'; const canvas = document.getElementById('lava-canvas'); const switchBtn = document.getElementById('power-switch'); const switchLabel = document.getElementById('switch-label'); const root = document.documentElement; // Match canvas backing resolution to display DPR (capped at 2 for steady 60fps on mobile) const CSS_W = 210; const CSS_H = 310; const DPR = Math.min(window.devicePixelRatio || 1, 2); canvas.width = Math.round(CSS_W * DPR); canvas.height = Math.round(CSS_H * DPR); // Aspect ratio in normalized simulation space: y in [0, 1], x in [-ASPECT/2, ASPECT/2] const ASPECT = CSS_W / CSS_H; // ~0.6774 // Exact glass inner half-width profile shared by physics and shader // y = 0 is bottom of glass, y = 1 is top of glass function glassHalfWidth(y) { const cy = Math.max(0, Math.min(1, y)); // Classic Astro lava lamp taper: widest around y = 0.25, narrower at bottom and top const bottomTaper = 0.235 + 0.095 * Math.sin(Math.min(1, cy / 0.28) * Math.PI * 0.5); const upperTaper = 0.33 - 0.165 * Math.pow(Math.max(0, (cy - 0.22) / 0.78), 1.15); return cy < 0.24 ? bottomTaper : upperTaper; } // Lamp state let isOn = true; let powerLevel = 1.0; // Smoothly eases between 0 and 1 // Optional subtle mechanical switch click via Web Audio API (no external assets) let audioCtx = null; function playClick(turningOn) { try { const Ctx = window.AudioContext || window.webkitAudioContext; if (!Ctx) return; if (!audioCtx) audioCtx = new Ctx(); if (audioCtx.state === 'suspended') audioCtx.resume(); const now = audioCtx.currentTime; const osc = audioCtx.createOscillator(); const gain = audioCtx.createGain(); osc.type = 'triangle'; osc.frequency.setValueAtTime(turningOn ? 240 : 175, now); osc.frequency.exponentialRampToValueAtTime(60, now + 0.032); gain.gain.setValueAtTime(0.08, now); gain.gain.exponentialRampToValueAtTime(0.0001, now + 0.035); osc.connect(gain); gain.connect(audioCtx.destination); osc.start(now); osc.stop(now + 0.04); } catch (_) { // Ignore audio errors } } function setPower(nextOn) { isOn = nextOn; switchBtn.setAttribute('aria-pressed', String(isOn)); switchLabel.textContent = isOn ? 'On' : 'Off'; playClick(isOn); } switchBtn.addEventListener('click', () => setPower(!isOn)); // Wax blob simulation const MAX_BLOBS = 18; const BASE_POOL_COUNT = 3; // Permanent base wax anchors at bottom const blobs = []; function rand(min, max) { return min + Math.random() * (max - min); } function initBlobs() { blobs.length = 0; // 3 wide base pool blobs hugging the heating element blobs.push( { x: -0.095, y: 0.042, vx: 0, vy: 0, r: 0.092, temp: 0.85, base: true, phase: 0.0 }, { x: 0.000, y: 0.036, vx: 0, vy: 0, r: 0.105, temp: 0.92, base: true, phase: 2.1 }, { x: 0.095, y: 0.042, vx: 0, vy: 0, r: 0.092, temp: 0.85, base: true, phase: 4.2 } ); // Dynamic wax blobs at various heights and temperatures const initialCount = 10; for (let i = 0; i < initialCount; i++) { const y = rand(0.10, 0.84); const hw = glassHalfWidth(y) - 0.07; blobs.push({ x: rand(-hw * 0.7, hw * 0.7), y, vx: rand(-0.015, 0.015), vy: rand(-0.02, 0.025), r: rand(0.052, 0.086), temp: y < 0.45 ? rand(0.55, 0.88) : rand(0.22, 0.52), base: false, mergeCooldown: rand(0.5, 2.0), splitCooldown: rand(1.0, 3.0), phase: rand(0, Math.PI * 2) }); } } initBlobs(); let simTime = 0; function stepPhysics(dt) { simTime += dt; // Smoothly ramp bulb power const targetPower = isOn ? 1.0 : 0.0; powerLevel += (targetPower - powerLevel) * Math.min(1, dt * 2.4); root.style.setProperty('--power', powerLevel.toFixed(3)); // Gentle undulation of base pool blobs for (let i = 0; i < BASE_POOL_COUNT; i++) { const b = blobs[i]; const wobble = Math.sin(simTime * 0.7 + b.phase) * 0.008 * (0.25 + 0.75 * powerLevel); b.x = (i - 1) * 0.092 + wobble; b.y = 0.038 + Math.cos(simTime * 0.55 + b.phase) * 0.006 * powerLevel; const targetTemp = powerLevel * 0.94; b.temp += (targetTemp - b.temp) * dt * 0.45; } // Update dynamic blobs for (let i = BASE_POOL_COUNT; i < blobs.length; i++) { const b = blobs[i]; if (b.mergeCooldown > 0) b.mergeCooldown -= dt; if (b.splitCooldown > 0) b.splitCooldown -= dt; // Thermal transfer: heat near bottom coil when ON, cool near top or when OFF const bottomHeatZone = Math.max(0, 1 - b.y / 0.28); const topCoolZone = Math.max(0, (b.y - 0.58) / 0.42); if (powerLevel > 0.05) { // Heating near bottom b.temp += bottomHeatZone * bottomHeatZone * powerLevel * 0.34 * dt; // Ambient gentle cooling throughout, stronger near top b.temp -= (0.025 + topCoolZone * 0.26) * dt; } else { // Lamp is OFF: everything cools down and sinks b.temp -= 0.16 * dt; } // Slight thermal variation so blobs don't move in lockstep b.temp += Math.sin(simTime * 0.45 + b.phase) * 0.012 * dt * powerLevel; b.temp = Math.max(0, Math.min(1, b.temp)); // Buoyancy: warm wax rises, cool wax sinks const neutralTemp = 0.48; const buoyancy = (b.temp - neutralTemp) * 0.26; b.vy += buoyancy * dt; // Gentle convective swirl (inward near bottom, outward near middle, inward near top) const swirlX = Math.sin(simTime * 0.42 + b.y * 5.2 + b.phase) * 0.022 * (0.15 + 0.85 * powerLevel); b.vx += swirlX * dt; // Centering drift when lamp is off so resting wax pools neatly if (powerLevel < 0.2) { b.vx -= b.x * 0.08 * dt; } // Viscous fluid drag const drag = Math.exp(-1.55 * dt); b.vx *= drag; b.vy *= drag; // Clamp max speed for dreamy lava motion const maxSpeed = 0.16; const spd = Math.hypot(b.vx, b.vy); if (spd > maxSpeed) { b.vx = (b.vx / spd) * maxSpeed; b.vy = (b.vy / spd) * maxSpeed; } b.x += b.vx * dt; b.y += b.vy * dt; // Keep inside glass vessel walls const minY = 0.055 + b.r * 0.25; const maxY = 0.945 - b.r * 0.55; if (b.y < minY) { b.y = minY; if (b.vy < 0) b.vy *= -0.25; } else if (b.y > maxY) { b.y = maxY; if (b.vy > 0) b.vy *= -0.25; } const hw = Math.max(0.04, glassHalfWidth(b.y) - b.r * 0.72 - 0.014); if (b.x < -hw) { b.x = -hw; if (b.vx < 0) b.vx *= -0.35; } else if (b.x > hw) { b.x = hw; if (b.vx > 0) b.vx *= -0.35; } } // Blob-to-blob interaction: soft cohesion, thermal exchange, and merging for (let i = BASE_POOL_COUNT; i < blobs.length; i++) { const a = blobs[i]; for (let j = i + 1; j < blobs.length; j++) { const b = blobs[j]; const dx = b.x - a.x; const dy = b.y - a.y; const dist = Math.hypot(dx, dy) || 0.0001; const sumR = a.r + b.r; if (dist < sumR * 1.45) { const nx = dx / dist; const ny = dy / dist; // Gentle surface tension pull when close, soft repulsion when overlapping deeply if (dist > sumR * 0.72) { const pull = 0.016 * dt; a.vx += nx * pull; a.vy += ny * pull; b.vx -= nx * pull; b.vy -= ny * pull; } else { const push = (sumR * 0.72 - dist) * 0.45 * dt; a.vx -= nx * push; a.vy -= ny * push; b.vx += nx * push; b.vy += ny * push; } // Thermal conduction when touching const tempDiff = (b.temp - a.temp) * 0.5 * dt; a.temp += tempDiff; b.temp -= tempDiff; // Merge two touching blobs into one larger blob (conserving area) const combinedR = Math.hypot(a.r, b.r); if ( dist < sumR * 0.56 && combinedR <= 0.112 && a.mergeCooldown <= 0 && b.mergeCooldown <= 0 && blobs.length > BASE_POOL_COUNT + 5 ) { const areaA = a.r * a.r; const areaB = b.r * b.r; const totalArea = areaA + areaB; a.x = (a.x * areaA + b.x * areaB) / totalArea; a.y = (a.y * areaA + b.y * areaB) / totalArea; a.vx = (a.vx * areaA + b.vx * areaB) / totalArea; a.vy = (a.vy * areaA + b.vy * areaB) / totalArea; a.temp = (a.temp * areaA + b.temp * areaB) / totalArea; a.r = combinedR; a.mergeCooldown = 2.4; a.splitCooldown = 1.4; blobs.splice(j, 1); j--; } } } } // Splitting: large blobs stretched by buoyancy/heat pinch off into two daughter blobs if (powerLevel > 0.35 && blobs.length < MAX_BLOBS - 1) { for (let i = BASE_POOL_COUNT; i < blobs.length; i++) { const b = blobs[i]; const wantsToSplit = b.r > 0.088 && b.splitCooldown <= 0 && ((b.temp > 0.68 && b.y < 0.45) || (b.temp < 0.36 && b.y > 0.55)); if (wantsToSplit && Math.random() < dt * 0.65) { const ratio = rand(0.36, 0.5); const area = b.r * b.r; const r1 = Math.sqrt(area * (1 - ratio)); const r2 = Math.sqrt(area * ratio); const angle = rand(-0.55, 0.55) + (b.temp > 0.5 ? Math.PI * 0.5 : -Math.PI * 0.5); const sep = (r1 + r2) * 0.52; const ox = Math.cos(angle) * sep; const oy = Math.sin(angle) * sep; b.r = r1; b.x -= ox * 0.4; b.y -= oy * 0.4; b.splitCooldown = 3.2; b.mergeCooldown = 2.6; blobs.push({ x: b.x + ox, y: Math.max(0.08, Math.min(0.90, b.y + oy)), vx: b.vx + Math.cos(angle) * 0.025, vy: b.vy + Math.sin(angle) * 0.032, r: r2, temp: Math.max(0, Math.min(1, b.temp + (b.temp > 0.5 ? 0.06 : -0.06))), base: false, mergeCooldown: 2.6, splitCooldown: 3.2, phase: rand(0, Math.PI * 2) }); break; } } } } // WebGL renderer for silky-smooth 60fps metaballs + glass shading const gl = canvas.getContext('webgl', { alpha: true, antialias: true, premultipliedAlpha: true }); const vertSrc = ` attribute vec2 aPos; varying vec2 vUv; void main() { vUv = aPos * 0.5 + 0.5; gl_Position = vec4(aPos, 0.0, 1.0); } `; const fragSrc = ` precision mediump float; varying vec2 vUv; uniform float uAspect; uniform float uPower; uniform float uTime; uniform int uBlobCount; uniform vec4 uBlobs[${MAX_BLOBS}]; // xy = pos, z = radius, w = temp float glassHalfWidth(float y) { float cy = clamp(y, 0.0, 1.0); float bottomTaper = 0.235 + 0.095 * sin(min(1.0, cy / 0.28) * 1.5707963); float upperTaper = 0.33 - 0.165 * pow(max(0.0, (cy - 0.22) / 0.78), 1.15); return cy < 0.24 ? bottomTaper : upperTaper; } vec2 evalField(vec2 p) { float field = 0.0; float tempSum = 0.0; for (int i = 0; i < ${MAX_BLOBS}; i++) { if (i >= uBlobCount) break; vec4 b = uBlobs[i]; vec2 d = p - b.xy; float dist2 = dot(d, d) + 0.00055; float contrib = (b.z * b.z) / dist2; field += contrib; tempSum += contrib * b.w; } return vec2(field, tempSum / max(field, 0.0001)); } void main() { vec2 p = vec2((vUv.x - 0.5) * uAspect, vUv.y); float hw = glassHalfWidth(p.y); float distToWall = hw - abs(p.x); // Soft anti-aliased silhouette mask for glass vessel float edgeMask = smoothstep(0.0, 0.008, distToWall) * smoothstep(0.0, 0.012, p.y) * smoothstep(1.0, 0.988, p.y); if (edgeMask <= 0.001) discard; float xNorm = p.x / max(hw, 0.001); // -1 to 1 across glass width // Liquid background gradient (warm glowing violet-magenta when ON, dark ink when OFF) vec3 liqBottomOn = vec3(0.42, 0.11, 0.22); vec3 liqMidOn = vec3(0.19, 0.06, 0.24); vec3 liqTopOn = vec3(0.08, 0.03, 0.15); vec3 liqOn = mix(liqBottomOn, liqMidOn, smoothstep(0.0, 0.48, p.y)); liqOn = mix(liqOn, liqTopOn, smoothstep(0.45, 1.0, p.y)); vec3 liqOff = mix(vec3(0.07, 0.06, 0.09), vec3(0.03, 0.03, 0.05), p.y); vec3 bg = mix(liqOff, liqOn, uPower); // Warm bulb uplight inside liquid float bulbGlow = exp(-length(vec2(p.x * 2.2, p.y * 1.9)) * 2.4) * uPower; bg += vec3(0.75, 0.26, 0.08) * bulbGlow * 0.55; // Evaluate metaball wax field vec2 res = evalField(p); float field = res.x; float temp = res.y; // Soft inner halo around wax in liquid float halo = smoothstep(0.35, 1.05, field) * (0.28 * uPower); bg += vec3(0.95, 0.34, 0.16) * halo; // Smooth wax surface threshold float waxMask = smoothstep(0.96, 1.06, field); vec3 color = bg; if (waxMask > 0.001) { // Estimate 2D gradient for fake 3D shading & subsurface glow float eps = 0.006; float fx = evalField(p + vec2(eps, 0.0)).x - field; float fy = evalField(p + vec2(0.0, eps)).x - field; vec3 normal = normalize(vec3(-fx, -fy, 0.28)); // Wax colors driven by temperature + lamp power vec3 coolWaxOn = vec3(0.78, 0.14, 0.28); vec3 hotWaxOn = vec3(1.00, 0.72, 0.18); vec3 waxOn = mix(coolWaxOn, hotWaxOn, smoothstep(0.2, 0.92, temp)); vec3 waxOff = mix(vec3(0.16, 0.09, 0.13), vec3(0.24, 0.12, 0.14), temp); vec3 waxBase = mix(waxOff, waxOn, uPower); // Lighting: warm key from bottom bulb + soft cool ambient from top-left vec3 bulbDir = normalize(vec3(-p.x * 0.4, -0.85, 0.55)); float bulbDiff = max(0.0, dot(normal, bulbDir)); float topDiff = max(0.0, dot(normal, normalize(vec3(-0.5, 0.7, 0.6)))); // Subsurface core glow (thicker/hotter wax glows brighter inside) float thickness = clamp((field - 1.0) * 0.35, 0.0, 1.0); vec3 waxLit = waxBase * (0.55 + 0.55 * bulbDiff * uPower + 0.25 * topDiff); waxLit += vec3(1.0, 0.52, 0.12) * thickness * (0.25 + 0.45 * temp) * uPower; // Subtle rim highlight on wax blobs float rim = pow(1.0 - max(0.0, normal.z), 2.2); waxLit += mix(vec3(0.18, 0.12, 0.16), vec3(1.0, 0.78, 0.45), uPower) * rim * 0.22; color = mix(color, waxLit, waxMask); } // Cylindrical glass Fresnel shading & specular highlights float fresnel = pow(abs(xNorm), 3.0); color *= 1.0 - fresnel * 0.32; // Primary curved glass reflection on left float leftSpec = smoothstep(0.16, 0.0, abs(xNorm + 0.64)) * (0.22 + 0.10 * (1.0 - p.y)); // Secondary softer reflection on right float rightSpec = smoothstep(0.12, 0.0, abs(xNorm - 0.76)) * 0.12; // Rim glass glint float rimGlint = smoothstep(0.86, 0.99, abs(xNorm)) * (0.14 + 0.12 * uPower); color += vec3(0.95, 0.92, 1.0) * (leftSpec + rightSpec); color += mix(vec3(0.35, 0.38, 0.46), vec3(1.0, 0.76, 0.62), uPower) * rimGlint; gl_FragColor = vec4(color * edgeMask, edgeMask); } `; function createShader(type, src) { const sh = gl.createShader(type); gl.shaderSource(sh, src); gl.compileShader(sh); if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) { console.error(gl.getShaderInfoLog(sh)); return null; } return sh; } let program = null; let uAspectLoc, uPowerLoc, uTimeLoc, uBlobCountLoc, uBlobsLoc; const blobUniformData = new Float32Array(MAX_BLOBS * 4); if (gl) { const vs = createShader(gl.VERTEX_SHADER, vertSrc); const fs = createShader(gl.FRAGMENT_SHADER, fragSrc); if (vs && fs) { program = gl.createProgram(); gl.attachShader(program, vs); gl.attachShader(program, fs); gl.linkProgram(program); const buf = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, buf); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ -1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1 ]), gl.STATIC_DRAW); const posLoc = gl.getAttribLocation(program, 'aPos'); gl.enableVertexAttribArray(posLoc); gl.vertexAttribPointer(posLoc, 2, gl.FLOAT, false, 0, 0); uAspectLoc = gl.getUniformLocation(program, 'uAspect'); uPowerLoc = gl.getUniformLocation(program, 'uPower'); uTimeLoc = gl.getUniformLocation(program, 'uTime'); uBlobCountLoc = gl.getUniformLocation(program, 'uBlobCount'); uBlobsLoc = gl.getUniformLocation(program, 'uBlobs[0]'); gl.viewport(0, 0, canvas.width, canvas.height); gl.clearColor(0, 0, 0, 0); } } // Lightweight 2D fallback if WebGL is unavailable const ctx2d = !program ? canvas.getContext('2d') : null; function renderWebGL() { gl.clear(gl.COLOR_BUFFER_BIT); gl.useProgram(program); const count = Math.min(blobs.length, MAX_BLOBS); for (let i = 0; i < count; i++) { const b = blobs[i]; const o = i * 4; blobUniformData[o] = b.x; blobUniformData[o + 1] = b.y; blobUniformData[o + 2] = b.r; blobUniformData[o + 3] = b.temp; } gl.uniform1f(uAspectLoc, ASPECT); gl.uniform1f(uPowerLoc, powerLevel); gl.uniform1f(uTimeLoc, simTime); gl.uniform1i(uBlobCountLoc, count); gl.uniform4fv(uBlobsLoc, blobUniformData); gl.drawArrays(gl.TRIANGLES, 0, 6); } function render2DFallback() { const w = canvas.width; const h = canvas.height; ctx2d.clearRect(0, 0, w, h); ctx2d.save(); // Clip to glass silhouette ctx2d.beginPath(); for (let i = 0; i <= 40; i++) { const y = i / 40; const x = (0.5 + glassHalfWidth(y) / ASPECT) * w; const py = (1 - y) * h; if (i === 0) ctx2d.moveTo(x, py); else ctx2d.lineTo(x, py); } for (let i = 40; i >= 0; i--) { const y = i / 40; const x = (0.5 - glassHalfWidth(y) / ASPECT) * w; const py = (1 - y) * h; ctx2d.lineTo(x, py); } ctx2d.closePath(); ctx2d.clip(); const grad = ctx2d.createLinearGradient(0, h, 0, 0); grad.addColorStop(0, powerLevel > 0.2 ? '#591a36' : '#14111a'); grad.addColorStop(1, powerLevel > 0.2 ? '#160926' : '#09080d'); ctx2d.fillStyle = grad; ctx2d.fillRect(0, 0, w, h); for (const b of blobs) { const cx = (0.5 + b.x / ASPECT) * w; const cy = (1 - b.y) * h; const r = (b.r / ASPECT) * w; const g = ctx2d.createRadialGradient(cx, cy, r * 0.1, cx, cy, r); const hot = Math.round(80 + b.temp * 140 * powerLevel); g.addColorStop(0, `rgb(${Math.round(70 + 185 * powerLevel)}, ${hot}, ${Math.round(45 + 30 * powerLevel)})`); g.addColorStop(1, `rgba(${Math.round(50 + 150 * powerLevel)}, ${Math.round(25 + 35 * powerLevel)}, 60, 0.85)`); ctx2d.fillStyle = g; ctx2d.beginPath(); ctx2d.arc(cx, cy, r, 0, Math.PI * 2); ctx2d.fill(); } ctx2d.restore(); } let lastTime = performance.now(); function loop(now) { const dt = Math.min(0.05, Math.max(0.001, (now - lastTime) / 1000)); lastTime = now; stepPhysics(dt); if (program) renderWebGL(); else if (ctx2d) render2DFallback(); requestAnimationFrame(loop); } requestAnimationFrame(loop);})();</script></body></html>