Lava lamp v1 · OpenCode21.11.2026 07:30
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"><meta name="theme-color" content="#17131f"><title>Lava Lamp</title><style> :root { --bg-top: #241d2e; --bg-bottom: #120e18; --accent: #ff8a3d; } * { box-sizing: border-box; } html, body { margin: 0; padding: 0; } body { min-height: 100svh; display: flex; align-items: center; justify-content: center; background: radial-gradient(120% 90% at 50% 0%, var(--bg-top), var(--bg-bottom)); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: #e8ded2; overflow-x: hidden; } .stage { width: min(100vw, 430px); height: 100svh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); } canvas { width: min(100%, calc((100svh - 130px) * 0.625)); aspect-ratio: 400 / 640; display: block; border-radius: 24px; box-shadow: 0 24px 60px rgba(0,0,0,0.55), 0 4px 14px rgba(0,0,0,0.4); touch-action: manipulation; cursor: pointer; background: #1b1624; } .controls { display: flex; align-items: center; gap: 14px; user-select: none; } .switch { position: relative; width: 66px; height: 34px; border-radius: 999px; border: 1px solid rgba(255,255,255,0.18); background: linear-gradient(180deg, #2c2536, #211b2a); box-shadow: inset 0 2px 6px rgba(0,0,0,0.6), 0 2px 8px rgba(0,0,0,0.35); cursor: pointer; transition: background 0.35s ease, box-shadow 0.35s ease, border-color 0.35s ease; -webkit-tap-highlight-color: transparent; padding: 0; } .switch .knob { position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fdf6ec, #cbb9a6 70%, #a99a88); box-shadow: 0 2px 5px rgba(0,0,0,0.5); transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.35s ease; } .switch[aria-checked="true"] { background: linear-gradient(180deg, #ff9a4d, #e0531f); border-color: rgba(255,180,110,0.6); box-shadow: inset 0 2px 5px rgba(120,40,0,0.45), 0 0 18px rgba(255,138,61,0.55); } .switch[aria-checked="true"] .knob { transform: translateX(32px); } .switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; } .status { font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; color: #b7a99c; min-width: 72px; } .status.on { color: #ffcf9e; } @media (prefers-reduced-motion: reduce) { .switch, .switch .knob { transition-duration: 0.01s; } }</style></head><body> <main class="stage"> <canvas id="scene" role="img" aria-label="A lava lamp on a desk"></canvas> <div class="controls"> <button class="switch" id="switch" role="switch" aria-checked="true" aria-label="Toggle lava lamp"> <span class="knob"></span> </button> <span class="status on" id="status">Lamp on</span> </div> </main><script>(() => { "use strict"; const canvas = document.getElementById("scene"); const ctx = canvas.getContext("2d"); const switchBtn = document.getElementById("switch"); const statusEl = document.getElementById("status"); // Logical coordinate space (everything drawn in this, scaled to canvas). const LW = 400, LH = 640; // Glass interior region (physics + clipping) const GLASS_TOP = 150; const GLASS_BOTTOM = 452; const CENTER_X = 200; function halfWidthAt(y) { const t = Math.min(1, Math.max(0, (y - GLASS_TOP) / (GLASS_BOTTOM - GLASS_TOP))); // Slight bulge: narrow at neck, wider toward base return 54 + 26 * t; } // ---------- state ---------- let lampOn = true; let light = 1; // smoothed 0..1 let time = 0; let lastT = 0; function makeBlob(x, y, r) { return { x, y, r, vy: 0, temp: 0.6, phase: Math.random() * Math.PI * 2, wobbleSpeed: 0.6 + Math.random() * 1.1, }; } let blobs = [ makeBlob(170, 300, 24), makeBlob(230, 380, 20), makeBlob(200, 420, 26), makeBlob(250, 240, 17), ]; const MIN_BLOB_R = 12; const MAX_BLOB_R = 44; const MERGE_FACTOR = 0.72; // ---------- sizing ---------- function resize() { const cssW = canvas.clientWidth || Math.min(window.innerWidth, 430); const cssH = cssW * (LH / LW); const dpr = Math.min(window.devicePixelRatio || 1, 2); canvas.width = Math.round(cssW * dpr); canvas.height = Math.round(cssH * dpr); } window.addEventListener("resize", resize); // ---------- helpers ---------- const lerp = (a, b, t) => a + (b - a) * t; const clamp = (v, a, b) => Math.min(b, Math.max(a, v)); function lerpColor(c1, c2, t) { return [ Math.round(lerp(c1[0], c2[0], t)), Math.round(lerp(c1[1], c2[1], t)), Math.round(lerp(c1[2], c2[2], t)), ]; } const rgb = (c, a = 1) => `rgba(${c[0]},${c[1]},${c[2]},${a})`; // ---------- glass path (visual) ---------- function glassPath() { const p = new Path2D(); const top = 128, bottom = 470, ns = 46; // neck half-width // rounded-trapezoid via curves p.moveTo(CENTER_X - ns, top + 14); p.quadraticCurveTo(CENTER_X - ns - 6, top, CENTER_X, top); p.quadraticCurveTo(CENTER_X + ns + 6, top, CENTER_X + ns, top + 14); p.quadraticCurveTo(CENTER_X + 88, 250, CENTER_X + 84, 402); p.quadraticCurveTo(CENTER_X + 82, bottom, CENTER_X + 40, bottom); p.lineTo(CENTER_X - 40, bottom); p.quadraticCurveTo(CENTER_X - 82, bottom, CENTER_X - 84, 402); p.quadraticCurveTo(CENTER_X - 88, 250, CENTER_X - ns, top + 14); p.closePath(); return p; } // ---------- physics ---------- function step(dt) { light += ((lampOn ? 1 : 0) - light) * Math.min(1, dt * 2.4); for (const b of blobs) { const depth = clamp((b.y - GLASS_TOP) / (GLASS_BOTTOM - GLASS_TOP), 0, 1); // warm target: high near the base, low near the neck; zero when lamp off const target = lampOn ? clamp(1.25 - depth * 1.15, 0.05, 1) : 0; b.temp += (target - b.temp) * Math.min(1, dt * 1.6); // rise when warm (y decreases), sink when cool const targetVy = (0.45 - b.temp) * 130; b.vy += (targetVy - b.vy) * Math.min(1, dt * 2.2); b.y += b.vy * dt; // gentle side-to-side sway b.x += Math.sin(time * b.wobbleSpeed + b.phase) * 22 * dt; b.x += Math.sin(time * 0.7 + b.phase * 2.1) * 8 * dt; // contain within glass interior const hw = halfWidthAt(b.y) - b.r * 0.55; const minX = CENTER_X - Math.max(10, hw); const maxX = CENTER_X + Math.max(10, hw); if (b.x < minX) { b.x = minX; } if (b.x > maxX) { b.x = maxX; } // keep inside vertically const minY = GLASS_TOP + b.r * 0.5; const maxY = GLASS_BOTTOM - b.r * 0.45; if (b.y < minY) { b.y = minY; if (b.vy < 0) b.vy = 0; } if (b.y > maxY) { b.y = maxY; if (b.vy > 0) b.vy = 0; } } // merge touching blobs let merged = true; while (merged) { merged = false; for (let i = 0; i < blobs.length; i++) { for (let j = i + 1; j < blobs.length; 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_FACTOR) { const area = a.r * a.r + b.r * b.r; const r = Math.sqrt(area); const nx = (a.x * a.r * a.r + b.x * b.r * b.r) / area; const ny = (a.y * a.r * a.r + b.y * b.r * b.r) / area; blobs.splice(j, 1); blobs.splice(i, 1); blobs.push({ x: nx, y: ny, r, vy: (a.vy + b.vy) * 0.5, temp: Math.max(a.temp, b.temp) * 0.92 + (a.temp + b.temp) * 0.08, phase: (a.phase + b.phase) * 0.5, wobbleSpeed: Math.max(0.4, (a.wobbleSpeed + b.wobbleSpeed) * 0.5 - 0.15), }); merged = true; break; } } if (merged) break; } } // split oversized blobs const toAdd = []; for (let i = 0; i < blobs.length; i++) { const b = blobs[i]; if (b.r > MAX_BLOB_R) { const r = Math.sqrt((b.r * b.r) / 2); const ang = Math.random() * Math.PI * 2; const off = b.r * 0.42; blobs.splice(i, 1); i--; toAdd.push( { ...b, x: b.x + Math.cos(ang) * off, y: b.y + Math.sin(ang) * off, r, vy: b.vy * 1.3, phase: Math.random() * 6.28 }, { ...b, x: b.x - Math.cos(ang) * off, y: b.y - Math.sin(ang) * off, r, vy: b.vy * 0.7, phase: Math.random() * 6.28 } ); } } blobs.push(...toAdd); // safety: keep minimum population by gentle nudge (never fully empty) if (blobs.length < 2) { blobs.push(makeBlob(CENTER_X, 380, 18)); } } // ---------- rendering ---------- function drawBackground() { const top = lerpColor([22, 18, 28], [58, 42, 54], light * 0.9); const bot = lerpColor([12, 10, 17], [34, 24, 30], light * 0.9); const g = ctx.createLinearGradient(0, 0, 0, LH); g.addColorStop(0, rgb(top)); g.addColorStop(1, rgb(bot)); ctx.fillStyle = g; ctx.fillRect(0, 0, LW, LH); } function drawDesk() { const top = 470; const g = ctx.createLinearGradient(0, top, 0, LH); g.addColorStop(0, rgb(lerpColor([52, 40, 34], [96, 62, 40], light))); g.addColorStop(1, rgb(lerpColor([24, 18, 15], [44, 26, 20], light))); ctx.fillStyle = g; ctx.fillRect(0, top, LW, LH - top); // desk back edge highlight ctx.fillStyle = rgb(lerpColor([70, 54, 44], [150, 96, 58], light), 0.9); ctx.fillRect(0, top, LW, 2); } function drawGlow() { if (light < 0.02) return; const g = ctx.createRadialGradient(CENTER_X, 500, 10, CENTER_X, 470, 300); g.addColorStop(0, `rgba(255,150,60,${0.5 * light})`); g.addColorStop(0.45, `rgba(255,110,40,${0.22 * light})`); g.addColorStop(1, "rgba(255,110,40,0)"); ctx.fillStyle = g; ctx.fillRect(0, 0, LW, LH); } function drawPool() { // wax pooling at the bottom of the glass const topY = 428; ctx.beginPath(); ctx.moveTo(CENTER_X - 80, GLASS_BOTTOM + 2); for (let x = -80; x <= 80; x += 8) { const y = topY + Math.sin(x * 0.09 + time * 1.4) * 3.5 + Math.sin(x * 0.23 - time * 0.9) * 1.6; ctx.lineTo(CENTER_X + x, y); } ctx.lineTo(CENTER_X + 80, GLASS_BOTTOM + 2); ctx.closePath(); const g = ctx.createLinearGradient(0, topY, 0, GLASS_BOTTOM); g.addColorStop(0, rgb(lerpColor([20, 12, 10], [255, 158, 64], light), 0.95)); g.addColorStop(1, rgb(lerpColor([12, 8, 8], [214, 70, 18], light), 0.98)); ctx.fillStyle = g; ctx.fill(); } function drawBlobs() { for (const b of blobs) { const rDraw = b.r * (1 + 0.05 * Math.sin(time * 2.1 + b.phase)); const g = ctx.createRadialGradient( b.x - rDraw * 0.25, b.y - rDraw * 0.3, rDraw * 0.1, b.x, b.y, rDraw ); g.addColorStop(0, rgb(lerpColor([60, 40, 34], [255, 214, 140], light))); g.addColorStop(0.45, rgb(lerpColor([48, 26, 22], [255, 134, 52], light))); g.addColorStop(1, rgb(lerpColor([18, 10, 10], [196, 52, 12], light))); ctx.fillStyle = g; ctx.beginPath(); ctx.arc(b.x, b.y, rDraw, 0, Math.PI * 2); ctx.fill(); // rim glow ctx.strokeStyle = `rgba(255,190,110,${0.25 * light})`; ctx.lineWidth = 1.5; ctx.stroke(); } } function drawGlassBack() { const g2 = ctx.createLinearGradient(0, GLASS_TOP, 0, GLASS_BOTTOM); g2.addColorStop(0, "rgba(255,255,255,0.08)"); g2.addColorStop(0.5, "rgba(255,255,255,0.02)"); g2.addColorStop(1, "rgba(255,255,255,0.06)"); ctx.save(); ctx.clip(glassPath()); // dark interior backing ctx.fillStyle = "rgba(8,6,12,0.6)"; ctx.fillRect(0, 0, LW, LH); ctx.fillStyle = g2; ctx.fillRect(0, 0, LW, LH); ctx.restore(); } function drawGlass() { const path = glassPath(); // edge stroke ctx.strokeStyle = "rgba(235,240,255,0.32)"; ctx.lineWidth = 2; ctx.stroke(path); // highlight strip on the left ctx.save(); ctx.clip(path); const hl = ctx.createLinearGradient(CENTER_X - 80, 0, CENTER_X - 20, 0); hl.addColorStop(0, "rgba(255,255,255,0.22)"); hl.addColorStop(0.5, "rgba(255,255,255,0.04)"); hl.addColorStop(1, "rgba(255,255,255,0)"); ctx.fillStyle = hl; ctx.fillRect(CENTER_X - 90, GLASS_TOP, 70, GLASS_BOTTOM - GLASS_TOP); ctx.restore(); // faint inner glow around the lower edge ctx.save(); ctx.clip(path); const ig = ctx.createLinearGradient(0, GLASS_BOTTOM - 60, 0, GLASS_BOTTOM); ig.addColorStop(0, "rgba(255,140,50,0)"); ig.addColorStop(1, `rgba(255,140,50,${0.22 * light})`); ctx.fillStyle = ig; ctx.fillRect(CENTER_X - 100, GLASS_BOTTOM - 60, 200, 60); ctx.restore(); } function drawHardware() { // floor shadow (behind everything else) ctx.fillStyle = `rgba(0,0,0,${0.38 - 0.1 * light})`; ctx.beginPath(); ctx.ellipse(CENTER_X, 556, 108, 14, 0, 0, Math.PI * 2); ctx.fill(); // top cap const capG = ctx.createLinearGradient(0, 108, 0, 150); capG.addColorStop(0, rgb(lerpColor([40, 36, 48], [78, 68, 88], light))); capG.addColorStop(1, rgb(lerpColor([22, 19, 28], [48, 40, 56], light))); ctx.fillStyle = capG; ctx.beginPath(); ctx.ellipse(CENTER_X, 124, 44, 16, 0, 0, Math.PI * 2); ctx.fill(); ctx.strokeStyle = "rgba(255,255,255,0.15)"; ctx.lineWidth = 1.5; ctx.stroke(); // base const baseG = ctx.createLinearGradient(0, 452, 0, 560); baseG.addColorStop(0, rgb(lerpColor([30, 26, 38], [94, 60, 46], light))); baseG.addColorStop(0.35, rgb(lerpColor([20, 17, 26], [62, 38, 30], light))); baseG.addColorStop(1, rgb(lerpColor([12, 10, 16], [30, 20, 18], light))); ctx.fillStyle = baseG; ctx.beginPath(); ctx.moveTo(CENTER_X - 48, 452); ctx.lineTo(CENTER_X + 48, 452); ctx.quadraticCurveTo(CENTER_X + 78, 470, CENTER_X + 88, 522); ctx.quadraticCurveTo(CENTER_X + 92, 548, CENTER_X + 60, 552); ctx.lineTo(CENTER_X - 60, 552); ctx.quadraticCurveTo(CENTER_X - 92, 548, CENTER_X - 88, 522); ctx.quadraticCurveTo(CENTER_X - 78, 470, CENTER_X - 48, 452); ctx.closePath(); ctx.fill(); ctx.strokeStyle = "rgba(255,255,255,0.14)"; ctx.lineWidth = 1.5; ctx.stroke(); // base glow strip when on if (light > 0.02) { ctx.save(); ctx.globalAlpha = light; const stripG = ctx.createLinearGradient(0, 468, 0, 486); stripG.addColorStop(0, "rgba(255,170,80,0)"); stripG.addColorStop(0.5, "rgba(255,180,90,0.9)"); stripG.addColorStop(1, "rgba(255,170,80,0)"); ctx.fillStyle = stripG; ctx.fillRect(CENTER_X - 46, 470, 92, 14); ctx.restore(); } } function draw() { const scale = canvas.width / LW; ctx.setTransform(scale, 0, 0, scale, 0, 0); drawBackground(); drawGlow(); drawDesk(); drawGlassBack(); // interior wax clipped to glass ctx.save(); ctx.clip(glassPath()); drawPool(); drawBlobs(); ctx.restore(); drawGlass(); drawHardware(); // vignette const vg = ctx.createRadialGradient(CENTER_X, LH * 0.42, LH * 0.2, CENTER_X, LH * 0.42, LH * 0.78); vg.addColorStop(0, "rgba(0,0,0,0)"); vg.addColorStop(1, "rgba(0,0,0,0.4)"); ctx.fillStyle = vg; ctx.fillRect(0, 0, LW, LH); } // ---------- loop ---------- function frame(t) { const dt = Math.min(0.05, lastT ? (t - lastT) / 1000 : 0.016); lastT = t; time += dt; step(dt); draw(); requestAnimationFrame(frame); } // ---------- controls ---------- function setLamp(on) { lampOn = on; switchBtn.setAttribute("aria-checked", String(on)); statusEl.textContent = on ? "Lamp on" : "Lamp off"; statusEl.classList.toggle("on", on); } switchBtn.addEventListener("click", () => setLamp(!lampOn)); canvas.addEventListener("click", () => setLamp(!lampOn)); resize(); // slight delay then size again (layout settled) requestAnimationFrame(resize); requestAnimationFrame(frame);})();</script></body></html>