<!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="#121525"> <title>Afterglow — Lava Lamp</title> <style> :root { color-scheme: dark; font-family: Inter, ui-rounded, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: #121525; color: #fff7ed; } * { box-sizing: border-box; } html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; background: #121525; } body { -webkit-tap-highlight-color: transparent; } .scene { position: fixed; inset: 0; isolation: isolate; } canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; } .masthead { position: absolute; top: max(20px, env(safe-area-inset-top)); left: max(20px, env(safe-area-inset-left)); display: flex; align-items: center; gap: 11px; pointer-events: none; user-select: none; text-shadow: 0 2px 16px rgba(0, 0, 0, .35); } .masthead .mark { width: 11px; height: 31px; border-radius: 999px; background: linear-gradient(to bottom, #ffbd72, #f05468); box-shadow: 0 0 22px rgba(255, 112, 79, .35); } .masthead h1 { margin: 0; font-size: 14px; line-height: 1.1; font-weight: 650; letter-spacing: .16em; text-transform: uppercase; } .masthead p { margin: 5px 0 0; color: rgba(255, 246, 235, .52); font-size: 10px; letter-spacing: .08em; } .edition { position: absolute; top: max(23px, env(safe-area-inset-top)); right: max(22px, env(safe-area-inset-right)); color: rgba(255, 255, 255, .34); font-size: 9px; letter-spacing: .2em; pointer-events: none; user-select: none; } .controls { position: absolute; z-index: 2; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); width: min(340px, calc(100% - 30px)); transform: translateX(-50%); } .power-switch { appearance: none; -webkit-appearance: none; width: 100%; min-height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 11px 14px 11px 18px; border: 1px solid rgba(255, 255, 255, .13); border-radius: 21px; outline: none; background: rgba(19, 20, 32, .72); box-shadow: 0 12px 36px rgba(0, 0, 0, .28), inset 0 1px rgba(255, 255, 255, .04); backdrop-filter: blur(16px) saturate(125%); -webkit-backdrop-filter: blur(16px) saturate(125%); color: inherit; font: inherit; text-align: left; cursor: pointer; touch-action: manipulation; user-select: none; transition: border-color .2s, background .2s, transform .2s; } .power-switch:hover { border-color: rgba(255, 255, 255, .24); } .power-switch:active { transform: scale(.985); } .power-switch:focus-visible { outline: 2px solid #ffb27a; outline-offset: 3px; } .control-copy { min-width: 0; } .control-title { display: flex; align-items: center; gap: 8px; font-size: 13px; line-height: 1.2; font-weight: 650; letter-spacing: .02em; } .status-dot { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: #ff9e68; box-shadow: 0 0 10px rgba(255, 137, 85, .8); transition: background .3s, box-shadow .3s; } .control-subtitle { display: block; margin-top: 5px; overflow: hidden; color: rgba(255, 248, 239, .45); font-size: 10px; line-height: 1.2; letter-spacing: .04em; text-overflow: ellipsis; white-space: nowrap; } .toggle-track { position: relative; width: 51px; height: 30px; flex: 0 0 auto; border-radius: 999px; background: #343642; box-shadow: inset 0 2px 5px rgba(0, 0, 0, .3); transition: background .25s; } .toggle-thumb { position: absolute; top: 4px; left: 4px; width: 22px; height: 22px; border-radius: 50%; background: #a7a7af; box-shadow: 0 2px 5px rgba(0, 0, 0, .3); transition: transform .25s cubic-bezier(.2, .8, .2, 1), background .25s; } .power-switch[aria-checked="true"] .toggle-track { background: linear-gradient(100deg, #e96651, #f2a15f); } .power-switch[aria-checked="true"] .toggle-thumb { transform: translateX(21px); background: #fff7e9; } .power-switch[aria-checked="false"] .status-dot { background: #686b76; box-shadow: none; } .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; } @media (max-width: 380px) { .masthead p { display: none; } .controls { bottom: calc(12px + env(safe-area-inset-bottom)); } } @media (max-height: 500px) and (orientation: landscape) { .masthead, .edition { display: none; } .controls { left: auto; right: max(16px, env(safe-area-inset-right)); bottom: calc(14px + env(safe-area-inset-bottom)); width: 280px; transform: none; } .power-switch { min-height: 58px; } .power-switch:active { transform: scale(.985); } } @media (prefers-reduced-motion: reduce) { .power-switch, .toggle-thumb, .toggle-track { transition-duration: .01ms; } } </style></head><body> <main class="scene"> <canvas id="scene" role="img" aria-label="An animated glass lava lamp standing on a wooden desk. Glowing wax blobs warm, rise, cool, and sink, merging and separating as they move." aria-describedby="scene-description"> Your browser needs Canvas support to display the lava lamp. </canvas> <p id="scene-description" class="sr-only">Use the lamp power switch to turn the lamp off and on. Wax cools and settles while the lamp is off.</p> <header class="masthead" aria-hidden="true"> <span class="mark"></span> <div> <h1>Afterglow</h1> <p>A little light. A little motion.</p> </div> </header> <span class="edition" aria-hidden="true">KINETIC OBJECT / 01</span> <div class="controls"> <button class="power-switch" id="power" type="button" role="switch" aria-checked="true" aria-label="Lamp power"> <span class="control-copy"> <span class="control-title"> <span class="status-dot" aria-hidden="true"></span> <span id="power-state">On</span> </span> <span class="control-subtitle" id="power-detail">Warming the wax</span> </span> <span class="toggle-track" aria-hidden="true"> <span class="toggle-thumb"></span> </span> </button> </div> </main> <script> (() => { "use strict"; const canvas = document.getElementById("scene"); const ctx = canvas.getContext("2d", { alpha: false, desynchronized: true }); const powerButton = document.getElementById("power"); const powerState = document.getElementById("power-state"); const powerDetail = document.getElementById("power-detail"); const TAU = Math.PI * 2; const VW = 200; const VH = 420; const FIELD_W = 160; const FIELD_H = 336; const FIELD_SCALE = 0.8; const FIXED_STEP = 1 / 60; const clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, v)); const lerp = (a, b, t) => a + (b - a) * t; const smoothstep = (a, b, v) => { const t = clamp((v - a) / (b - a), 0, 1); return t * t * (3 - 2 * t); }; let seed = 0x51a7c3; function random() { seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0; return seed / 4294967296; } // The vessel is simulated in a small fixed coordinate system. The // metaball field is also fixed-size, keeping mobile frame cost stable. const widthStops = [ [0.00, 43], [0.12, 46], [0.35, 56], [0.62, 70], [0.80, 79], [0.90, 75], [0.96, 61], [1.00, 45] ]; function vesselHalfWidth(t) { t = clamp(t, 0, 1); for (let i = 0; i < widthStops.length - 1; i++) { const a = widthStops[i]; const b = widthStops[i + 1]; if (t >= a[0] && t <= b[0]) { const f = (t - a[0]) / (b[0] - a[0]); return lerp(a[1], b[1], f * f * (3 - 2 * f)); } } return 45; } const blobs = []; for (let i = 0; i < 18; i++) { const r = i === 0 ? 29 : i === 1 ? 25 : 12 + random() * 13; const y = 17 + i * (378 / 17) + random() * 9; const temp = y < 90 ? 0.70 + random() * 0.18 : y > 305 ? 0.18 + random() * 0.17 : 0.40 + random() * 0.38; blobs.push({ x: (random() - 0.5) * 72, y, r, temp, vx: (random() - 0.5) * 2, vy: (temp - 0.47) * 25, phase: random() * TAU, stretch: 0 }); } let W = 1; let H = 1; let M = null; let lampOn = true; let power = 1; let time = 0; let accumulator = 0; let last = performance.now(); const background = document.createElement("canvas"); const fieldCanvas = document.createElement("canvas"); fieldCanvas.width = FIELD_W; fieldCanvas.height = FIELD_H; const fieldCtx = fieldCanvas.getContext("2d", { alpha: true }); const fieldImage = fieldCtx.createImageData(FIELD_W, FIELD_H); const density = new Float32Array(FIELD_W * FIELD_H); const heat = new Float32Array(FIELD_W * FIELD_H); function roundedRect(c, x, y, w, h, r) { r = Math.min(r, w / 2, h / 2); c.beginPath(); c.moveTo(x + r, y); c.arcTo(x + w, y, x + w, y + h, r); c.arcTo(x + w, y + h, x, y + h, r); c.arcTo(x, y + h, x, y, r); c.arcTo(x, y, x + w, y, r); c.closePath(); } function calculateMetrics() { const landscape = W > H && H < 520; const lampH = Math.min(600, H * (landscape ? 0.68 : 0.66), W * 1.35); const baseY = H * (landscape ? 0.83 : 0.785); const baseH = lampH * 0.215; const capH = lampH * 0.075; const top = baseY - lampH; const baseTop = baseY - baseH; const glassTop = top + capH * 0.78; const glassBottom = baseTop + baseH * 0.10; const glassH = glassBottom - glassTop; const scale = glassH / VH; const cx = landscape ? W * 0.36 : W * 0.5; return { landscape, cx, top, baseY, baseH, baseTop, capH, glassTop, glassBottom, glassH, scale, lampH, deskY: H * (landscape ? 0.64 : 0.70), baseTopW: lampH * 0.108, baseBottomW: lampH * 0.18, capTopW: lampH * 0.073, capBottomW: lampH * 0.103 }; } function traceVessel() { const { cx, glassBottom, glassH, scale } = M; ctx.beginPath(); for (let i = 0; i <= 48; i++) { const t = i / 48; const x = cx - vesselHalfWidth(t) * scale; const y = glassBottom - t * glassH; if (i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y); } for (let i = 48; i >= 0; i--) { const t = i / 48; ctx.lineTo(cx + vesselHalfWidth(t) * scale, glassBottom - t * glassH); } ctx.closePath(); } function makeGradients() { const { cx, glassTop, glassBottom, baseTop, baseY, baseBottomW } = M; const g = {}; g.fluidOff = ctx.createLinearGradient(0, glassTop, 0, glassBottom); g.fluidOff.addColorStop(0, "rgba(18,22,37,.94)"); g.fluidOff.addColorStop(0.55, "rgba(34,31,45,.86)"); g.fluidOff.addColorStop(1, "rgba(71,48,53,.74)"); g.fluidOn = ctx.createLinearGradient(0, glassTop, 0, glassBottom); g.fluidOn.addColorStop(0, "rgba(42,21,60,.92)"); g.fluidOn.addColorStop(0.52, "rgba(92,29,65,.76)"); g.fluidOn.addColorStop(1, "rgba(255,112,52,.26)"); g.sheen = ctx.createLinearGradient( cx - 82 * M.scale, 0, cx + 82 * M.scale, 0 ); g.sheen.addColorStop(0, "rgba(255,255,255,.20)"); g.sheen.addColorStop(0.08, "rgba(255,255,255,.10)"); g.sheen.addColorStop(0.25, "rgba(255,255,255,.015)"); g.sheen.addColorStop(0.60, "rgba(255,255,255,0)"); g.sheen.addColorStop(0.84, "rgba(8,9,24,.08)"); g.sheen.addColorStop(1, "rgba(5,8,20,.30)"); g.baseOff = ctx.createLinearGradient(cx - baseBottomW, 0, cx + baseBottomW, 0); g.baseOff.addColorStop(0, "#121620"); g.baseOff.addColorStop(0.23, "#30323a"); g.baseOff.addColorStop(0.46, "#5b5960"); g.baseOff.addColorStop(0.72, "#34333a"); g.baseOff.addColorStop(1, "#11151e"); g.baseOn = ctx.createLinearGradient(cx - baseBottomW, 0, cx + baseBottomW, 0); g.baseOn.addColorStop(0, "#211820"); g.baseOn.addColorStop(0.22, "#6f4035"); g.baseOn.addColorStop(0.45, "#d39a67"); g.baseOn.addColorStop(0.68, "#8a503c"); g.baseOn.addColorStop(1, "#211720"); g.capOff = ctx.createLinearGradient(cx - M.capBottomW, 0, cx + M.capBottomW, 0); g.capOff.addColorStop(0, "#151923"); g.capOff.addColorStop(0.45, "#605d64"); g.capOff.addColorStop(1, "#171923"); g.capOn = ctx.createLinearGradient(cx - M.capBottomW, 0, cx + M.capBottomW, 0); g.capOn.addColorStop(0, "#2b1b22"); g.capOn.addColorStop(0.43, "#c1865c"); g.capOn.addColorStop(1, "#321d25"); // Keep references alive for the lifetime of this canvas size. M.gradients = g; void baseTop; void baseY; } function drawDeskObjects(c) { const { cx, baseY, baseBottomW, lampH } = M; const bookW = clamp(W * 0.12, 52, 96); const bookX = cx - baseBottomW - bookW - 20; const bookY = baseY + 24; if (bookX > 8 && bookY + 22 < H) { c.save(); c.translate(bookX + bookW / 2, bookY); c.rotate(-0.035); c.shadowColor = "rgba(0,0,0,.24)"; c.shadowBlur = 8; c.shadowOffsetY = 4; roundedRect(c, -bookW / 2, 0, bookW, 10, 2); c.fillStyle = "#304c50"; c.fill(); c.shadowColor = "transparent"; roundedRect(c, -bookW * 0.44, -9, bookW * 0.91, 9, 2); c.fillStyle = "#9b6048"; c.fill(); c.fillStyle = "rgba(239,211,164,.55)"; c.fillRect(-bookW * 0.36, -7, bookW * 0.56, 1); c.fillStyle = "rgba(225,215,188,.42)"; c.fillRect(-bookW / 2 + 4, 3, bookW - 8, 1); c.restore(); } const mugX = cx + baseBottomW + 42; const mugY = baseY + 11; const mugR = clamp(lampH * 0.037, 16, 23); if (mugX + mugR + 12 < W && mugY + mugR < H) { c.save(); c.translate(mugX, mugY); c.shadowColor = "rgba(0,0,0,.25)"; c.shadowBlur = 8; c.shadowOffsetY = 4; c.beginPath(); c.arc(mugR * 0.82, 0, mugR * 0.55, -Math.PI / 2, Math.PI / 2); c.strokeStyle = "#8c8276"; c.lineWidth = 4; c.stroke(); c.shadowColor = "transparent"; const mugGradient = c.createLinearGradient(-mugR, 0, mugR, 0); mugGradient.addColorStop(0, "#655f5b"); mugGradient.addColorStop(0.48, "#b4a795"); mugGradient.addColorStop(1, "#615c58"); roundedRect(c, -mugR, -mugR * 0.62, mugR * 2, mugR * 1.55, 5); c.fillStyle = mugGradient; c.fill(); c.beginPath(); c.ellipse(0, -mugR * 0.62, mugR, mugR * 0.29, 0, 0, TAU); c.fillStyle = "#c4b9a6"; c.fill(); c.beginPath(); c.ellipse(0, -mugR * 0.61, mugR * 0.78, mugR * 0.18, 0, 0, TAU); c.fillStyle = "#382b29"; c.fill(); c.restore(); } } function buildBackground() { const dpr = Math.min(window.devicePixelRatio || 1, 2); background.width = Math.round(W * dpr); background.height = Math.round(H * dpr); const b = background.getContext("2d", { alpha: false }); b.setTransform(dpr, 0, 0, dpr, 0, 0); const { deskY, cx } = M; const wall = b.createLinearGradient(0, 0, 0, deskY); wall.addColorStop(0, "#111625"); wall.addColorStop(0.58, "#1d2030"); wall.addColorStop(1, "#302837"); b.fillStyle = wall; b.fillRect(0, 0, W, deskY + 1); const ambient = b.createRadialGradient( W * 0.78, H * 0.16, 0, W * 0.78, H * 0.16, Math.max(W, H) * 0.65 ); ambient.addColorStop(0, "rgba(102,119,157,.13)"); ambient.addColorStop(0.5, "rgba(62,69,102,.035)"); ambient.addColorStop(1, "rgba(10,12,24,0)"); b.fillStyle = ambient; b.fillRect(0, 0, W, deskY); const desk = b.createLinearGradient(0, deskY, 0, H); desk.addColorStop(0, "#67453b"); desk.addColorStop(0.16, "#51352f"); desk.addColorStop(1, "#281e22"); b.fillStyle = desk; b.fillRect(0, deskY, W, H - deskY); b.fillStyle = "rgba(238,175,125,.12)"; b.fillRect(0, deskY, W, 1); b.fillStyle = "rgba(22,14,20,.28)"; b.fillRect(0, deskY + 4, W, 5); b.save(); b.beginPath(); b.rect(0, deskY + 8, W, H - deskY - 8); b.clip(); b.strokeStyle = "rgba(30,17,21,.14)"; b.lineWidth = 1; for (let i = -5; i <= 5; i++) { b.beginPath(); b.moveTo(cx + i * 27, deskY); b.lineTo(cx + i * Math.max(130, W * 0.15), H); b.stroke(); } for (let i = 0; i < 8; i++) { const y = deskY + 23 + i * 31 + (i % 3) * 7; b.strokeStyle = `rgba(231,167,120,${0.025 + (i % 2) * 0.015})`; b.beginPath(); b.moveTo(0, y); b.bezierCurveTo(W * 0.3, y - 5, W * 0.66, y + 6, W, y - 2); b.stroke(); } b.restore(); drawDeskObjects(b); } function resize() { W = Math.max(1, window.innerWidth); H = Math.max(1, window.innerHeight); const dpr = Math.min(window.devicePixelRatio || 1, 2); canvas.width = Math.round(W * dpr); canvas.height = Math.round(H * dpr); ctx.setTransform(dpr, 0, 0, dpr, 0, 0); ctx.imageSmoothingEnabled = true; ctx.imageSmoothingQuality = "high"; M = calculateMetrics(); makeGradients(); buildBackground(); } function update(dt) { time += dt; const targetPower = lampOn ? 1 : 0; power += (targetPower - power) * (1 - Math.exp(-dt * 2.4)); if (Math.abs(power - targetPower) < 0.0005) power = targetPower; for (const b of blobs) { const bottomHeat = clamp(1 - b.y / 100, 0, 1); const topCooling = smoothstep(270, 410, b.y); b.temp += dt * ( 0.155 * bottomHeat * power - 0.005 - 0.049 * topCooling ); if (!lampOn) b.temp += (0.09 - b.temp) * dt * 0.12; b.temp = clamp(b.temp, 0.07, 0.96); const targetVY = (b.temp - 0.47) * 44; const response = b.temp > 0.47 ? 0.58 : 0.82; b.vy += (targetVY - b.vy) * Math.min(1, dt * response); const desiredStretch = Math.min(0.22, Math.abs(b.vy) / 75); b.stretch += (desiredStretch - b.stretch) * Math.min(1, dt * 2); const swirl = Math.sin(time * 0.43 + b.phase) * 0.75 + Math.sin(time * 0.17 + b.phase * 1.7) * 0.38; b.vx += swirl * dt * (0.45 + power * 0.55); b.vx += -b.x * dt * 0.003; b.vx *= Math.exp(-dt * 0.55); b.x += b.vx * dt; b.y += b.vy * dt; const minY = 7 + b.r * 0.15; const maxY = VH - 7 - b.r * 0.20; if (b.y < minY) { b.y = minY; if (b.vy < 0) b.vy *= 0.18; } else if (b.y > maxY) { b.y = maxY; if (b.vy > 0) b.vy *= 0.2; } const limit = Math.max(7, vesselHalfWidth(b.y / VH) - b.r * 0.55); if (b.x < -limit) { b.x = -limit; b.vx = Math.abs(b.vx) * 0.45; } else if (b.x > limit) { b.x = limit; b.vx = -Math.abs(b.vx) * 0.45; } } // Nearby blobs exchange heat and gently avoid occupying exactly the // same point. Their visible iso-surfaces merge and split naturally. for (let i = 0; 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) * 0.9; const reach = (a.r + b.r) * 1.12; const d2 = dx * dx + dy * dy; if (d2 >= reach * reach) continue; const exchange = (a.temp - b.temp) * dt * 0.11; a.temp -= exchange; b.temp += exchange; const minimum = (a.r + b.r) * 0.48; if (d2 < minimum * minimum) { const d = Math.sqrt(d2); const nx = d > 0.001 ? dx / d : (i % 2 ? 1 : -1); const ny = d > 0.001 ? dy / d : 0; const push = (minimum - d) * dt * 1.6; a.vx -= nx * push; b.vx += nx * push; a.vy -= ny * push * 0.12; b.vy += ny * push * 0.12; } } } } function updateWaxField() { density.fill(0); heat.fill(0); // Compact kernels are splatted only into their local bounds. Summing // these fields creates continuous merging and splitting at contacts. for (const b of blobs) { const fx = (b.x + VW / 2) * FIELD_SCALE; const fy = (VH - b.y) * FIELD_SCALE; const rx = b.r * 1.48 * FIELD_SCALE; const ry = b.r * (1.50 + b.stretch) * FIELD_SCALE; const x0 = Math.max(0, Math.floor(fx - rx)); const x1 = Math.min(FIELD_W - 1, Math.ceil(fx + rx)); const y0 = Math.max(0, Math.floor(fy - ry)); const y1 = Math.min(FIELD_H - 1, Math.ceil(fy + ry)); for (let y = y0; y <= y1; y++) { const ny = (y + 0.5 - fy) / ry; const ny2 = ny * ny; let index = y * FIELD_W + x0; for (let x = x0; x <= x1; x++, index++) { const nx = (x + 0.5 - fx) / rx; const q = nx * nx + ny2; if (q < 1) { const v = 1 - q; const contribution = v * v; density[index] += contribution; heat[index] += contribution * b.temp; } } } } const pixels = fieldImage.data; for (let y = 0; y < FIELD_H; y++) { const bottomness = y / FIELD_H; for (let x = 0; x < FIELD_W; x++) { const i = y * FIELD_W + x; const p = i * 4; const d = density[i]; if (d <= 0.205) { pixels[p] = 0; pixels[p + 1] = 0; pixels[p + 2] = 0; pixels[p + 3] = 0; continue; } let alpha = clamp((d - 0.205) / 0.09, 0, 1); alpha = alpha * alpha * (3 - 2 * alpha); const averageTemp = clamp(heat[i] / d, 0, 1); const mix = clamp(bottomness * 0.68 + averageTemp * 0.32, 0, 1); const core = clamp((d - 0.28) * 1.5, 0, 1); const onR = 211 + 44 * mix + core * 7; const onG = 40 + 83 * mix + core * 9; const onB = 94 - 43 * mix + core * 3; const offR = 67 + 29 * mix; const offG = 48 + 22 * mix; const offB = 63 + 14 * mix; const light = 0.88 + power * 0.12; pixels[p] = clamp(lerp(offR, onR, power) * light, 0, 255); pixels[p + 1] = clamp(lerp(offG, onG, power) * light, 0, 255); pixels[p + 2] = clamp(lerp(offB, onB, power) * light, 0, 255); pixels[p + 3] = Math.round(alpha * (0.91 + power * 0.09) * 255); } } fieldCtx.putImageData(fieldImage, 0, 0); } function drawGlass() { const { cx, glassTop, glassBottom, glassH, scale, gradients } = M; ctx.save(); traceVessel(); ctx.clip(); ctx.fillStyle = gradients.fluidOff; ctx.fillRect(cx - 100 * scale, glassTop, 200 * scale, glassH); if (power > 0.001) { ctx.globalAlpha = power; ctx.fillStyle = gradients.fluidOn; ctx.fillRect(cx - 100 * scale, glassTop, 200 * scale, glassH); ctx.globalAlpha = 1; } ctx.drawImage( fieldCanvas, 0, 0, FIELD_W, FIELD_H, cx - 100 * scale, glassTop, 200 * scale, glassH ); ctx.fillStyle = gradients.sheen; ctx.fillRect(cx - 100 * scale, glassTop, 200 * scale, glassH); const reflection = ctx.createLinearGradient(0, glassTop, 0, glassBottom); reflection.addColorStop(0, "rgba(255,255,255,.20)"); reflection.addColorStop(0.4, "rgba(255,255,255,.06)"); reflection.addColorStop(1, "rgba(255,255,255,0)"); ctx.strokeStyle = reflection; ctx.lineWidth = Math.max(1.2, scale * 1.8); ctx.lineCap = "round"; ctx.beginPath(); ctx.moveTo(cx - 46 * scale, glassTop + glassH * 0.15); ctx.bezierCurveTo( cx - 65 * scale, glassTop + glassH * 0.38, cx - 48 * scale, glassTop + glassH * 0.68, cx - 34 * scale, glassTop + glassH * 0.85 ); ctx.stroke(); ctx.restore(); traceVessel(); ctx.strokeStyle = `rgba(231,224,231,${0.20 + power * 0.08})`; ctx.lineWidth = 1; ctx.stroke(); } function basePath() { const { cx, baseTop, baseY, baseH, baseTopW, baseBottomW } = M; ctx.beginPath(); ctx.moveTo(cx - baseTopW, baseTop); ctx.bezierCurveTo( cx - baseTopW * 1.04, baseTop + baseH * 0.34, cx - baseBottomW * 0.97, baseY - baseH * 0.20, cx - baseBottomW, baseY - 8 ); ctx.quadraticCurveTo(cx - baseBottomW, baseY + 1, cx - baseBottomW + 12, baseY + 2); ctx.lineTo(cx + baseBottomW - 12, baseY + 2); ctx.quadraticCurveTo(cx + baseBottomW, baseY + 1, cx + baseBottomW, baseY - 8); ctx.bezierCurveTo( cx + baseBottomW * 0.97, baseY - baseH * 0.20, cx + baseTopW * 1.04, baseTop + baseH * 0.34, cx + baseTopW, baseTop ); ctx.closePath(); } function drawBase() { const { cx, baseTop, baseY, baseH, baseTopW, gradients } = M; ctx.save(); basePath(); ctx.fillStyle = gradients.baseOff; ctx.fill(); if (power > 0.001) { ctx.globalAlpha = power; ctx.fillStyle = gradients.baseOn; ctx.fill(); ctx.globalAlpha = 1; } ctx.save(); basePath(); ctx.clip(); ctx.strokeStyle = "rgba(255,238,215,.055)"; ctx.lineWidth = 0.6; for (let y = baseTop + 5; y < baseY; y += 5) { ctx.beginPath(); ctx.moveTo(cx - M.baseBottomW, y); ctx.lineTo(cx + M.baseBottomW, y + 1); ctx.stroke(); } ctx.restore(); basePath(); ctx.strokeStyle = "rgba(242,208,172,.17)"; ctx.lineWidth = 1; ctx.stroke(); ctx.beginPath(); ctx.ellipse(cx, baseTop, baseTopW, 7 * M.scale + 2, 0, 0, TAU); ctx.fillStyle = gradients.baseOff; ctx.fill(); if (power > 0.001) { ctx.globalAlpha = power; ctx.fillStyle = gradients.baseOn; ctx.fill(); ctx.globalAlpha = 1; } ctx.strokeStyle = "rgba(255,228,194,.20)"; ctx.stroke(); const ledY = baseTop + baseH * 0.48; ctx.beginPath(); ctx.arc(cx, ledY, 2.1, 0, TAU); ctx.fillStyle = power > 0.05 ? "#ffd3a0" : "#171920"; ctx.shadowColor = "rgba(255,151,84,.9)"; ctx.shadowBlur = power * 8; ctx.fill(); ctx.restore(); } function drawCap() { const { cx, top, capH, capTopW, capBottomW, gradients } = M; const bottom = M.glassTop + capH * 0.30; ctx.save(); ctx.beginPath(); ctx.moveTo(cx - capTopW, top); ctx.quadraticCurveTo(cx, top - capH * 0.16, cx + capTopW, top); ctx.lineTo(cx + capBottomW, bottom - 4); ctx.quadraticCurveTo(cx, bottom + 5, cx - capBottomW, bottom - 4); ctx.closePath(); ctx.fillStyle = gradients.capOff; ctx.fill(); if (power > 0.001) { ctx.globalAlpha = power; ctx.fillStyle = gradients.capOn; ctx.fill(); ctx.globalAlpha = 1; } ctx.strokeStyle = "rgba(255,227,192,.18)"; ctx.lineWidth = 0.9; ctx.stroke(); ctx.beginPath(); ctx.ellipse(cx, top, capTopW, capTopW * 0.25, 0, Math.PI, TAU); ctx.strokeStyle = "rgba(255,241,216,.25)"; ctx.stroke(); ctx.restore(); } function drawLighting() { if (power < 0.999) { ctx.fillStyle = `rgba(4,7,16,${(1 - power) * 0.46})`; ctx.fillRect(0, 0, W, H); } if (power <= 0.001) return; const { cx, glassTop, glassH, baseY, lampH } = M; ctx.save(); ctx.globalCompositeOperation = "screen"; const glow = ctx.createRadialGradient( cx, glassTop + glassH * 0.57, 0, cx, glassTop + glassH * 0.57, lampH * 0.72 ); glow.addColorStop(0, `rgba(255,107,65,${0.19 * power})`); glow.addColorStop(0.34, `rgba(236,75,81,${0.085 * power})`); glow.addColorStop(1, "rgba(80,30,70,0)"); ctx.fillStyle = glow; ctx.fillRect(0, 0, W, H); const deskGlow = ctx.createRadialGradient( cx, baseY, 0, cx, baseY, lampH * 0.40 ); deskGlow.addColorStop(0, `rgba(255,147,81,${0.16 * power})`); deskGlow.addColorStop(1, "rgba(255,100,60,0)"); ctx.fillStyle = deskGlow; ctx.fillRect(0, M.deskY, W, H - M.deskY); ctx.restore(); } function drawShadow() { const { cx, baseY, baseBottomW } = M; ctx.save(); ctx.translate(cx, baseY + 7); ctx.scale(1, 0.18); const shadow = ctx.createRadialGradient(0, 0, 0, 0, 0, baseBottomW * 1.35); shadow.addColorStop(0, "rgba(5,7,12,.48)"); shadow.addColorStop(0.55, "rgba(5,7,12,.25)"); shadow.addColorStop(1, "rgba(5,7,12,0)"); ctx.fillStyle = shadow; ctx.beginPath(); ctx.arc(0, 0, baseBottomW * 1.35, 0, TAU); ctx.fill(); ctx.restore(); } function render() { ctx.drawImage(background, 0, 0, background.width, background.height, 0, 0, W, H); drawLighting(); drawShadow(); updateWaxField(); drawGlass(); drawBase(); drawCap(); } function frame(now) { const elapsed = Math.min(0.05, Math.max(0, (now - last) / 1000)); last = now; accumulator += elapsed; let steps = 0; while (accumulator >= FIXED_STEP && steps < 3) { update(FIXED_STEP); accumulator -= FIXED_STEP; steps++; } if (steps === 3) accumulator = 0; render(); requestAnimationFrame(frame); } function setPower(on) { lampOn = on; powerButton.setAttribute("aria-checked", String(on)); powerState.textContent = on ? "On" : "Off"; powerDetail.textContent = on ? "Warming the wax" : "Cooling · wax at rest"; } powerButton.addEventListener("click", () => setPower(!lampOn)); window.addEventListener("keydown", event => { if (event.key.toLowerCase() === "l" && !event.metaKey && !event.ctrlKey && !event.altKey) { setPower(!lampOn); } }); window.addEventListener("resize", resize, { passive: true }); document.addEventListener("visibilitychange", () => { last = performance.now(); accumulator = 0; }); resize(); requestAnimationFrame(frame); })(); </script></body></html>