Lava lamp v1 · Codex CLI25.11.2026 12:28
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover"><title>Lava Lamp</title><style> :root { color-scheme: dark; } * { box-sizing: border-box; } html, body { margin: 0; padding: 0; height: 100%; background: #12101a; overflow: hidden; font-family: system-ui, -apple-system, sans-serif; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; } #scene { display: block; width: 100vw; height: 100dvh; } #switchWrap { position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 10; } #lampSwitch { width: 74px; height: 122px; border-radius: 16px; border: 1px solid rgba(255,255,255,0.14); background: linear-gradient(180deg, #2a2438, #1b1726); box-shadow: 0 8px 22px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.08); position: relative; cursor: pointer; padding: 0; touch-action: manipulation; } #lampSwitch::before { content: ""; position: absolute; left: 50%; top: 12px; transform: translateX(-50%); width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,0.06); box-shadow: inset 0 2px 6px rgba(0,0,0,0.6); } #lever { position: absolute; left: 50%; top: 16px; width: 14px; height: 76px; border-radius: 8px; transform: translateX(-50%); background: linear-gradient(180deg, #e8e2f2, #8f86a3); box-shadow: 0 4px 10px rgba(0,0,0,0.55), inset 0 -4px 6px rgba(0,0,0,0.35); transition: transform 0.22s cubic-bezier(.5,1.6,.4,1), background 0.25s; } #switchWrap.on #lever { transform: translateX(-50%) translateY(34px); background: linear-gradient(180deg, #ffd9a0, #ff8a3c); box-shadow: 0 0 18px rgba(255,150,60,0.8), 0 4px 10px rgba(0,0,0,0.55); } #lampSwitch:focus-visible { outline: 2px solid #ffb35c; outline-offset: 3px; } #switchLabel { font-size: 11px; letter-spacing: 0.22em; text-transform: uppercase; color: rgba(255,255,255,0.55); }</style></head><body><canvas id="scene"></canvas><div id="switchWrap" class="on"> <button id="lampSwitch" role="switch" aria-checked="true" aria-label="Toggle lava lamp"> <span id="lever"></span> </button> <div id="switchLabel">Lamp</div></div><script>(() => { "use strict"; const canvas = document.getElementById("scene"); const ctx = canvas.getContext("2d"); const switchWrap = document.getElementById("switchWrap"); const lampSwitch = document.getElementById("lampSwitch"); let W = 0, H = 0, DPR = 1; let deskY = 0, glassTop = 0, glassBottom = 0, cx = 0, baseHalf = 0, baseH = 0; function resize() { DPR = Math.min(window.devicePixelRatio || 1, 2); W = window.innerWidth; H = window.innerHeight; canvas.width = Math.round(W * DPR); canvas.height = Math.round(H * DPR); canvas.style.width = W + "px"; canvas.style.height = H + "px"; ctx.setTransform(DPR, 0, 0, DPR, 0, 0); cx = W / 2; deskY = H * 0.80; baseH = Math.max(52, H * 0.075); glassTop = H * 0.13; glassBottom = deskY - baseH * 0.35; baseHalf = Math.min(W * 0.21, 92); } window.addEventListener("resize", resize); resize(); // Glass half-width at a given y (slightly tapered tube) function halfWidth(y) { const t = (y - glassTop) / (glassBottom - glassTop); return baseHalf * (0.82 + 0.20 * t); } function glassPath() { ctx.beginPath(); const steps = 28; for (let i = 0; i <= steps; i++) { const y = glassTop + (glassBottom - glassTop) * (i / steps); const hw = halfWidth(y); const x = cx - hw; if (i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y); } for (let i = steps; i >= 0; i--) { const y = glassTop + (glassBottom - glassTop) * (i / steps); ctx.lineTo(cx + halfWidth(y), y); } ctx.closePath(); } // ---- simulation state ---- let lampOn = true; let warmth = 1; // 0..1 animated lamp heat let time = 0; const MIN_BLOB_R = 14, MAX_BLOB_R = 34, MERGE_DIST = 0.82, SPLIT_R = 40; function makeBlob(x, y, r) { return { x: x, y: y, r: r, vy: 0, heat: 0.5, phase: Math.random() * Math.PI * 2, wobFreq: 0.9 + Math.random() * 1.4, wobAmp: 0.5 + Math.random() * 1.2, }; } let blobs = []; function seedBlobs() { blobs = []; const n = 9; for (let i = 0; i < n; i++) { const y = glassTop + (glassBottom - glassTop) * ((i + 0.5) / n); blobs.push(makeBlob(cx + (Math.random() - 0.5) * baseHalf, y, 16 + Math.random() * 14)); } } seedBlobs(); lampSwitch.addEventListener("click", () => { lampOn = !lampOn; switchWrap.classList.toggle("on", lampOn); lampSwitch.setAttribute("aria-checked", String(lampOn)); }); window.addEventListener("keydown", (e) => { if (e.key === " " || e.key === "Enter") { if (document.activeElement === lampSwitch) return; // button handles itself lampSwitch.click(); } }); // ---- update ---- function step(dt) { time += dt; warmth += ((lampOn ? 1 : 0) - warmth) * Math.min(1, dt * 1.4); const midY = (glassTop + glassBottom) / 2; for (const b of blobs) { // target heat: hotter near base, cooler near top; zero when off const yNorm = (b.y - glassTop) / (glassBottom - glassTop); // 0 top → 1 bottom const targetHeat = lampOn ? Math.max(0.06, 1 - (1 - yNorm) * 0.85) : 0; const rate = targetHeat > b.heat ? 0.55 : 0.30; // heat up faster than cool b.heat += (targetHeat - b.heat) * Math.min(1, dt * rate * 2.2); // buoyancy: hot rises, cold sinks const targetVy = (0.42 - b.heat) * (H * 0.16); b.vy += (targetVy - b.vy) * Math.min(1, dt * 1.6); b.y += b.vy * dt; // gentle horizontal drift + wobble b.x += Math.sin(time * b.wobFreq + b.phase) * b.wobAmp * dt * 14; if (Math.random() < dt * 0.35) b.phase += Math.random() * 2 - 1; // constrain inside glass const hw = halfWidth(b.y) - b.r * 0.55; const minX = cx - Math.max(6, hw), maxX = cx + Math.max(6, hw); if (b.x < minX) b.x = minX; if (b.x > maxX) b.x = maxX; const topLim = glassTop + b.r * 0.55; const botLim = glassBottom - b.r * 0.45; if (b.y < topLim) { b.y = topLim; if (b.vy < 0) b.vy *= -0.3; } if (b.y > botLim) { b.y = botLim; if (b.vy > 0) b.vy *= -0.25; } } // merge overlapping blobs for (let i = 0; i < blobs.length; i++) { for (let j = blobs.length - 1; j > i; j--) { const a = blobs[i], b = blobs[j]; const dx = a.x - b.x, dy = a.y - b.y; const d = Math.hypot(dx, dy); if (d < (a.r + b.r) * MERGE_DIST) { const mA = a.r * a.r, mB = b.r * b.r, mT = mA + mB; a.x = (a.x * mA + b.x * mB) / mT; a.y = (a.y * mA + b.y * mB) / mT; a.vy = (a.vy * mA + b.vy * mB) / mT; a.heat = (a.heat * mA + b.heat * mB) / mT; a.r = Math.sqrt(mT); a.phase = (a.phase + b.phase) / 2; blobs.splice(j, 1); } } } // split large blobs for (let i = 0; i < blobs.length; i++) { const b = blobs[i]; if (b.r > SPLIT_R && blobs.length < 16) { const newR = b.r * Math.SQRT1_2; const off = newR * 0.9; const jitter = Math.random() * Math.PI * 2; const child = makeBlob(b.x + Math.cos(jitter) * off, b.y + Math.sin(jitter) * off * 0.6, newR); child.heat = b.heat * (0.75 + Math.random() * 0.35); child.vy = b.vy + (Math.random() - 0.5) * 30; b.r = newR; b.vy += (Math.random() - 0.5) * 30; blobs.push(child); } else if (b.r > SPLIT_R) { // too many blobs: just nudge radius down a touch b.r = Math.max(MAX_BLOB_R, b.r * 0.98); } } // keep radii sane for (const b of blobs) b.r = Math.max(MIN_BLOB_R, Math.min(b.r, 60)); } // ---- drawing helpers ---- function lerp(a, b, t) { return a + (b - a) * t; } function mixColor(c1, c2, t) { return [lerp(c1[0], c2[0], t), lerp(c1[1], c2[1], t), lerp(c1[2], c2[2], t)]; } function rgb(c, a) { return `rgba(${c[0] | 0},${c[1] | 0},${c[2] | 0},${a === undefined ? 1 : a})`; } const FLUID_ON_TOP = [64, 18, 40], FLUID_ON_BOT = [200, 44, 16]; const FLUID_OFF_TOP = [26, 28, 44], FLUID_OFF_BOT = [14, 15, 26]; const BLOB_HOT = [255, 168, 66], BLOB_COLD = [150, 60, 52]; const BLOB_CORE = [255, 226, 150], BLOB_CORE_COLD = [110, 40, 38]; function drawBackground() { // wall const wall = ctx.createLinearGradient(0, 0, 0, deskY); wall.addColorStop(0, "#241d33"); wall.addColorStop(1, "#171220"); ctx.fillStyle = wall; ctx.fillRect(0, 0, W, deskY); // ambient glow behind lamp if (warmth > 0.01) { const g = ctx.createRadialGradient(cx, glassTop + (glassBottom - glassTop) * 0.55, 10, cx, glassTop + (glassBottom - glassTop) * 0.55, W * 0.75); g.addColorStop(0, `rgba(255,140,50,${0.30 * warmth})`); g.addColorStop(0.5, `rgba(255,90,40,${0.12 * warmth})`); g.addColorStop(1, "rgba(255,90,40,0)"); ctx.fillStyle = g; ctx.fillRect(0, 0, W, deskY); } // desk const desk = ctx.createLinearGradient(0, deskY, 0, H); desk.addColorStop(0, "#5a3b28"); desk.addColorStop(0.08, "#4a2f20"); desk.addColorStop(1, "#241610"); ctx.fillStyle = desk; ctx.fillRect(0, deskY, W, H - deskY); ctx.fillStyle = "rgba(255,210,160,0.10)"; ctx.fillRect(0, deskY, W, 2); } function drawBlobs() { ctx.save(); glassPath(); ctx.clip(); // fluid body const top = mixColor(FLUID_OFF_TOP, FLUID_ON_TOP, warmth); const bot = mixColor(FLUID_OFF_BOT, FLUID_ON_BOT, warmth); const fluid = ctx.createLinearGradient(0, glassTop, 0, glassBottom); fluid.addColorStop(0, rgb(top)); fluid.addColorStop(1, rgb(bot)); ctx.fillStyle = fluid; ctx.fillRect(cx - baseHalf * 1.4, glassTop - 2, baseHalf * 2.8, glassBottom - glassTop + 4); // inner glow near base when warm if (warmth > 0.02) { const gg = ctx.createRadialGradient(cx, glassBottom, 4, cx, glassBottom, baseHalf * 2.4); gg.addColorStop(0, `rgba(255,190,90,${0.55 * warmth})`); gg.addColorStop(1, "rgba(255,120,40,0)"); ctx.fillStyle = gg; ctx.fillRect(cx - baseHalf * 1.5, glassBottom - baseHalf * 2.2, baseHalf * 3, baseHalf * 2.4); } // wax blobs for (const b of blobs) { const wobble = 1 + 0.10 * Math.sin(time * b.wobFreq * 2.4 + b.phase); const r = b.r * wobble * (0.75 + 0.35 * b.heat); const warm = Math.min(1, b.heat * 1.5 + 0.12); const edge = mixColor(BLOB_COLD, BLOB_HOT, warm); const core = mixColor(BLOB_CORE_COLD, BLOB_CORE, warm); const grad = ctx.createRadialGradient(b.x - r * 0.25, b.y - r * 0.3, r * 0.15, b.x, b.y, r * 1.15); grad.addColorStop(0, rgb(core)); grad.addColorStop(0.55, rgb(edge)); grad.addColorStop(1, rgb(mixColor(edge, top, 0.55))); ctx.fillStyle = grad; ctx.beginPath(); // slightly lumpy outline const lobes = 9; for (let i = 0; i <= lobes; i++) { const a = (i / lobes) * Math.PI * 2; const rr = r * (1 + 0.09 * Math.sin(a * 3 + b.phase + time * 1.7)); const px = b.x + Math.cos(a) * rr; const py = b.y + Math.sin(a) * rr * 0.94; if (i === 0) ctx.moveTo(px, py); else ctx.lineTo(px, py); } ctx.closePath(); ctx.fill(); } ctx.restore(); } function drawGlass() { // glass tint glassPath(); const sheen = ctx.createLinearGradient(cx - baseHalf, 0, cx + baseHalf, 0); sheen.addColorStop(0, "rgba(255,255,255,0.16)"); sheen.addColorStop(0.18, "rgba(255,255,255,0.03)"); sheen.addColorStop(0.5, "rgba(255,255,255,0.00)"); sheen.addColorStop(0.82, "rgba(255,255,255,0.05)"); sheen.addColorStop(1, "rgba(255,255,255,0.14)"); ctx.fillStyle = sheen; ctx.fill(); ctx.strokeStyle = "rgba(255,255,255,0.22)"; ctx.lineWidth = 1.5; ctx.stroke(); // highlight streak ctx.save(); glassPath(); ctx.clip(); ctx.fillStyle = "rgba(255,255,255,0.13)"; const hx = cx - baseHalf * 0.45; ctx.beginPath(); ctx.moveTo(hx, glassTop + 8); ctx.lineTo(hx + baseHalf * 0.22, glassTop + 8); ctx.lineTo(hx + baseHalf * 0.34, glassBottom - 10); ctx.lineTo(hx + baseHalf * 0.12, glassBottom - 10); ctx.closePath(); ctx.fill(); ctx.restore(); } function drawBase() { const bw = baseHalf * 2 + 26; const bx = cx - bw / 2; const by = deskY - baseH + 14; // glow spill onto desk if (warmth > 0.02) { const spill = ctx.createRadialGradient(cx, deskY + 6, 4, cx, deskY + 6, bw * 1.6); spill.addColorStop(0, `rgba(255,140,60,${0.34 * warmth})`); spill.addColorStop(1, "rgba(255,140,60,0)"); ctx.fillStyle = spill; ctx.fillRect(cx - bw * 1.6, deskY - 40, bw * 3.2, 90); } const grad = ctx.createLinearGradient(0, by, 0, deskY + 10); grad.addColorStop(0, "#3c3348"); grad.addColorStop(0.35, "#241d30"); grad.addColorStop(1, "#100d18"); ctx.fillStyle = grad; roundRect(bx, by, bw, baseH + 8, 16); ctx.fill(); ctx.strokeStyle = "rgba(255,255,255,0.10)"; ctx.lineWidth = 1.5; ctx.stroke(); // neck ctx.fillStyle = "#171221"; roundRect(cx - baseHalf * 0.66, by - 14, baseHalf * 1.32, 22, 9); ctx.fill(); // light rim on neck if (warmth > 0.02) { ctx.fillStyle = `rgba(255,170,80,${0.8 * warmth})`; roundRect(cx - baseHalf * 0.5, by - 4, baseHalf, 4, 2); ctx.fill(); } } function roundRect(x, y, w, h, r) { ctx.beginPath(); ctx.moveTo(x + r, y); ctx.arcTo(x + w, y, x + w, y + h, r); ctx.arcTo(x + w, y + h, x, y + h, r); ctx.arcTo(x, y + h, x, y, r); ctx.arcTo(x, y, x + w, y, r); ctx.closePath(); } function draw() { ctx.clearRect(0, 0, W, H); drawBackground(); drawBlobs(); drawGlass(); drawBase(); // soft vignette const v = ctx.createRadialGradient(cx, H * 0.45, H * 0.3, cx, H * 0.5, H * 0.95); v.addColorStop(0, "rgba(0,0,0,0)"); v.addColorStop(1, "rgba(0,0,0,0.42)"); ctx.fillStyle = v; ctx.fillRect(0, 0, W, H); } let last = performance.now(); function frame(now) { let dt = (now - last) / 1000; last = now; if (dt > 0.05) dt = 0.05; // clamp after tab switch step(dt); draw(); requestAnimationFrame(frame); } requestAnimationFrame(frame);})();</script></body></html>