Lava lamp v1 · OpenCode21.11.2026 07:38

Source Inkling 2 Mini, High effort

index.html · 21.6 KB · 484 lines. Exactly as the agent wrote it.

<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover, user-scalable=no"><meta name="theme-color" content="#141a26"><title>Lava Lamp</title><style>  html,body{margin:0;height:100%;overflow:hidden;background:#141a26;}  canvas{display:block;width:100vw;height:100vh;height:100dvh;touch-action:none;cursor:pointer;outline:none;}</style></head><body><canvas id="c" tabindex="0" role="button" aria-label="Lava lamp switch — press to turn the lamp on or off" aria-pressed="true"></canvas><script>'use strict';const TAU = Math.PI * 2;const clamp = (v, a, b) => v < a ? a : (v > b ? b : v);const lerp = (a, b, u) => a + (b - a) * u;const fract = x => x - Math.floor(x);const lerpC = (c1, c2, u) => [lerp(c1[0], c2[0], u) | 0, lerp(c1[1], c2[1], u) | 0, lerp(c1[2], c2[2], u) | 0];const rgb = c => `rgb(${c[0]},${c[1]},${c[2]})`;const canvas = document.getElementById('c');const ctx = canvas.getContext('2d');let W = 0, H = 0, DPR = 1;let L = null;                 // layoutlet blobs = [];let time = 0, last = performance.now();let lampOn = true, lampLight = 1;let hintAlpha = 1, hintDone = false;let bgLayer = null, fgLayer = null, bgCtx = null, fgCtx = null;function roundRect(c, x, y, w, h, r) {  r = Math.min(r, w / 2, h / 2);  if (c.roundRect) { c.beginPath(); c.roundRect(x, y, w, h, r); return; }  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 ellipse(c, x, y, rx, ry, fill) {  c.save(); c.beginPath(); c.ellipse(x, y, rx, ry, 0, 0, TAU); c.fillStyle = fill; c.fill(); c.restore();}// ---------- layout ----------function computeLayout() {  const deskTop = H * 0.775;  const baseHW = clamp(W * 0.215, 62, 108);  const baseH = clamp(H * 0.062, 34, 52);  const baseBottomY = H * 0.955;  const baseTopY = baseBottomY - baseH;  const bulbBottomY = baseTopY + 8;  const bulbTopY = H * 0.135;  const maxHw = clamp(W * 0.27, 54, 96);  const hwTop = clamp(W * 0.075, 20, 32);  const hwBottom = clamp(W * 0.115, 30, 46);  L = {    deskTop, baseHW, baseH, baseBottomY, baseTopY, bulbBottomY, bulbTopY,    maxHw, hwTop, hwBottom, cx: W / 2, bulbH: bulbBottomY - bulbTopY,    maxR: clamp(W * 0.105, 30, 46),    minR: clamp(W * 0.045, 14, 22),    switchY: baseTopY + baseH * 0.56,    switchW: clamp(baseHW * 0.56, 46, 58),    switchH: clamp(baseH * 0.46, 22, 30),    capHW: hwTop * 0.72,    collarHW: Math.max(hwBottom * 1.3, baseHW * 0.44)  };}function profile(t) {  const top = L.hwTop, mid = L.maxHw, bot = L.hwBottom;  if (t < 0.30) { const u = t / 0.30; return lerp(top, mid, u * u * (3 - 2 * u)); }  if (t < 0.74) return mid;  const u = (t - 0.74) / 0.26;  return lerp(mid, bot, u * u * (3 - 2 * u));}function lampPath(c) {  const N = 28, top = L.bulbTopY, bot = L.bulbBottomY, hw0 = profile(0);  c.beginPath();  c.moveTo(L.cx - hw0, top);  c.quadraticCurveTo(L.cx, top - hw0 * 1.12, L.cx + hw0, top);  for (let i = 1; i <= N; i++) { const t = i / N; c.lineTo(L.cx + profile(t), top + (bot - top) * t); }  c.lineTo(L.cx - profile(1), bot);  for (let i = N - 1; i >= 0; i--) { const t = i / N; c.lineTo(L.cx - profile(t), top + (bot - top) * t); }  c.closePath();}// ---------- physics ----------function spawnBlobs() {  const n = 7;  blobs = [];  for (let i = 0; i < n; i++) {    const tt = clamp(0.12 + 0.72 * (i / (n - 1)) + (Math.random() - 0.5) * 0.08, 0.1, 0.95);    const y = L.bulbTopY + L.bulbH * tt;    const hw = profile(clamp((y - L.bulbTopY) / L.bulbH, 0, 1));    const x = L.cx + (Math.random() * 2 - 1) * Math.max(0, hw - L.maxR - 6);    const r = clamp(L.maxR * (0.55 + Math.random() * 0.3), L.minR, L.maxR * 0.9);    blobs.push({ x, y, r, vx: 0, vy: 0, heat: 0.2 + Math.random() * 0.55, phase: Math.random() * TAU, splitCool: 0 });  }}function updateBlobs(dt) {  const on = lampLight;  for (const b of blobs) {    if (b.splitCool > 0) b.splitCool -= dt;    const t = clamp((b.y - L.bulbTopY) / L.bulbH, 0, 1);    const depth = t;    const heatIn = on * (1.15 * depth * depth + 0.24);    const cool = 0.10 + 0.34 * (1 - depth);    b.heat = clamp(b.heat + (heatIn - cool * 0.85) * dt, 0.02, 1);    const force = (0.40 - b.heat) * 640;    b.vy += force * dt;    b.vx += Math.sin(time * 1.6 + b.phase) * 30 * dt * (0.4 + b.heat);    b.vy *= Math.exp(-1.30 * dt);    b.vx *= Math.exp(-1.5 * dt);    const vmax = 240;    b.vx = clamp(b.vx, -vmax, vmax);    b.vy = clamp(b.vy, -vmax, vmax);    b.x += b.vx * dt;    b.y += b.vy * dt;  }  resolve();}function resolve() {  // merge on touch  for (let i = 0; i < blobs.length; i++) {    for (let j = i + 1; j < blobs.length; j++) {      const a = blobs[i], b = blobs[j];      if (a.splitCool > 0 || b.splitCool > 0) continue;      const dx = b.x - a.x, dy = b.y - a.y;      const d = Math.hypot(dx, dy) || 0.001;      const rr = (a.r + b.r) * 0.84;      if (d < rr) {        const ma = a.r * a.r, mb = b.r * b.r, m = ma + mb;        a.x = (a.x * ma + b.x * mb) / m; a.y = (a.y * ma + b.y * mb) / m;        a.vx = (a.vx * ma + b.vx * mb) / m; a.vy = (a.vy * ma + b.vy * mb) / m;        a.heat = (a.heat * ma + b.heat * mb) / m;        a.r = Math.sqrt(m); a.splitCool = 0.5;        blobs.splice(j, 1);        break;      }    }  }  // clamp inside glass  for (const b of blobs) {    const t = clamp((b.y - L.bulbTopY) / L.bulbH, 0, 1);    const hw = profile(t);    const effR = Math.min(b.r, Math.max(7, hw - 3));    const maxX = Math.max(0, hw - effR);    const dx = b.x - L.cx;    if (dx > maxX) { b.x = L.cx + maxX; b.vx = -Math.abs(b.vx) * 0.3; }    else if (dx < -maxX) { b.x = L.cx - maxX; b.vx = Math.abs(b.vx) * 0.3; }    const minY = L.bulbTopY + 6 + effR;    const maxY = L.bulbBottomY - 3 - effR;    if (b.y < minY) { b.y = minY; b.vy = Math.abs(b.vy) * 0.25; }    else if (b.y > maxY) { b.y = maxY; b.vy = -Math.abs(b.vy) * 0.25; }  }  // split oversized blobs  for (let i = blobs.length - 1; i >= 0; i--) {    const b = blobs[i];    if (b.r > L.maxR && b.splitCool <= 0 && blobs.length < 24) {      const newR = b.r / Math.sqrt(2);      const ang = Math.random() * TAU;      const d = newR * 0.85;      const b2 = { x: b.x + Math.cos(ang) * d, y: b.y + Math.sin(ang) * d, r: newR,        vx: b.vx * 0.6 + Math.cos(ang) * 46, vy: b.vy * 0.6 + Math.sin(ang) * 46,        heat: b.heat, phase: Math.random() * TAU, splitCool: 0.9 };      b.x -= Math.cos(ang) * d; b.y -= Math.sin(ang) * d; b.r = newR;      b.vx = b.vx * 0.6 - Math.cos(ang) * 46; b.vy = b.vy * 0.6 - Math.sin(ang) * 46;      b.splitCool = 0.9;      blobs.push(b2);    }  }}// ---------- static layers ----------function createLayer() {  const cv = document.createElement('canvas');  cv.width = Math.round(W * DPR); cv.height = Math.round(H * DPR);  const c = cv.getContext('2d');  c.setTransform(DPR, 0, 0, DPR, 0, 0);  return { cv, c };}function buildBg() {  const { cv, c } = createLayer();  // wall  let g = c.createLinearGradient(0, 0, 0, L.deskTop);  g.addColorStop(0, '#f7eddd'); g.addColorStop(0.55, '#ecdcc0'); g.addColorStop(1, '#dfc8a6');  c.fillStyle = g; c.fillRect(0, 0, W, L.deskTop + 2);  g = c.createRadialGradient(L.cx, H * 0.30, Math.min(W, H) * 0.22, L.cx, H * 0.30, Math.max(W, H) * 0.85);  g.addColorStop(0, 'rgba(0,0,0,0)'); g.addColorStop(1, 'rgba(84,54,28,0.22)');  c.fillStyle = g; c.fillRect(0, 0, W, L.deskTop + 2);  // desk  g = c.createLinearGradient(0, L.deskTop, 0, H);  g.addColorStop(0, '#d2986a'); g.addColorStop(0.10, '#c08557'); g.addColorStop(1, '#7c4f30');  c.fillStyle = g; c.fillRect(0, L.deskTop, W, H - L.deskTop);  c.fillStyle = 'rgba(70,40,20,0.20)';  for (let i = 1; i <= 3; i++) { c.fillRect(0, L.deskTop + (H - L.deskTop) * i / 4, W, 1.5); }  c.fillStyle = 'rgba(96,58,32,0.10)';  for (let i = 0; i < 26; i++) {    const y = L.deskTop + (H - L.deskTop) * fract(i * 0.618);    const x = fract(i * 0.317) * (W - 60);    c.fillRect(x, y, 24 + (i % 5) * 22, 1.4);  }  c.fillStyle = 'rgba(255,244,225,0.55)'; c.fillRect(0, L.deskTop, W, 2.2);  // props: books (left) & mug (right)  const planeY = L.baseBottomY;  const gap = clamp(W * 0.045, 10, 22);  // books  const bookW = clamp(W * 0.15, 52, 80), bookH = clamp(H * 0.020, 9, 13);  const bookX = L.cx - L.baseHW - gap - bookW;  ellipse(c, bookX + bookW / 2, planeY + 3, bookW * 0.62, 5, 'rgba(0,0,0,0.22)');  c.fillStyle = '#b95f45'; roundRect(c, bookX, planeY - bookH * 2, bookW, bookH * 2, 4); c.fill();  c.fillStyle = '#8a4232'; roundRect(c, bookX, planeY - bookH * 2, bookW, bookH * 0.42, 3); c.fill();  c.fillStyle = '#e9ded0'; roundRect(c, bookX + bookW * 0.72, planeY - bookH * 1.62, bookW * 0.2, bookH * 1.22, 2); c.fill();  const bw2 = bookW * 0.86, bx2 = bookX + bookW * 0.07;  ellipse(c, bx2 + bw2 / 2, planeY - bookH * 2 + 3, bw2 * 0.6, 4, 'rgba(0,0,0,0.20)');  c.fillStyle = '#4f6b74'; roundRect(c, bx2, planeY - bookH * 3.4, bw2, bookH * 1.4, 4); c.fill();  c.fillStyle = '#38525b'; roundRect(c, bx2, planeY - bookH * 3.4, bw2, bookH * 0.38, 3); c.fill();  c.fillStyle = '#e9ded0'; roundRect(c, bx2 + bw2 * 0.72, planeY - bookH * 3.08, bw2 * 0.2, bookH * 1.0, 2); c.fill();  // mug  const mugW = clamp(W * 0.075, 22, 32), mugH = mugW * 1.08;  const mugX = L.cx + L.baseHW + gap;  ellipse(c, mugX + mugW / 2, planeY + 3, mugW * 0.8, 4.5, 'rgba(0,0,0,0.22)');  c.strokeStyle = '#3f6b63'; c.lineWidth = 4.5;  c.beginPath(); c.arc(mugX + mugW + 4, planeY - mugH * 0.52, mugW * 0.27, -1.25, 1.25); c.stroke();  g = c.createLinearGradient(mugX, 0, mugX + mugW, 0);  g.addColorStop(0, '#5e8b80'); g.addColorStop(0.45, '#467165'); g.addColorStop(1, '#2f4f48');  c.fillStyle = g; roundRect(c, mugX, planeY - mugH, mugW, mugH, 5); c.fill();  c.fillStyle = 'rgba(255,255,255,0.30)'; roundRect(c, mugX + 2.5, planeY - mugH + 3, mugW * 0.2, mugH - 7, 3); c.fill();  // lamp shadow on desk  ellipse(c, L.cx, planeY + 4, L.baseHW * 1.42, L.baseH * 0.42, 'rgba(0,0,0,0.30)');  // glass liquid  lampPath(c);  g = c.createLinearGradient(0, L.bulbTopY, 0, L.bulbBottomY);  g.addColorStop(0, '#221019'); g.addColorStop(0.5, '#2c1424'); g.addColorStop(1, '#38131f');  c.fillStyle = g; c.fill();  // inner side shading  c.save(); lampPath(c); c.clip();  g = c.createLinearGradient(L.cx - L.maxHw, 0, L.cx - L.maxHw * 0.25, 0);  g.addColorStop(0, 'rgba(0,0,0,0.42)'); g.addColorStop(1, 'rgba(0,0,0,0)');  c.fillStyle = g; c.fillRect(L.cx - L.maxHw, L.bulbTopY, L.maxHw * 1.3, L.bulbH);  g = c.createLinearGradient(L.cx + L.maxHw, 0, L.cx + L.maxHw * 0.25, 0);  g.addColorStop(0, 'rgba(0,0,0,0.42)'); g.addColorStop(1, 'rgba(0,0,0,0)');  c.fillStyle = g; c.fillRect(L.cx + L.maxHw * 0.25, L.bulbTopY, L.maxHw * 1.3, L.bulbH);  c.restore();  // lamp base  const bTop = L.baseTopY, bBot = L.baseBottomY, hwB = L.baseHW;  const flare = hwB * 1.06;  c.beginPath();  c.moveTo(L.cx - hwB * 0.78, bTop);  c.lineTo(L.cx + hwB * 0.78, bTop);  c.lineTo(L.cx + flare, bBot - 6);  c.quadraticCurveTo(L.cx + flare, bBot, L.cx + flare - 6, bBot);  c.lineTo(L.cx - flare + 6, bBot);  c.quadraticCurveTo(L.cx - flare, bBot, L.cx - flare, bBot - 6);  c.closePath();  g = c.createLinearGradient(0, bTop, 0, bBot);  g.addColorStop(0, '#4b5163'); g.addColorStop(0.25, '#3a3f50'); g.addColorStop(1, '#1d2029');  c.fillStyle = g; c.fill();  roundRect(c, L.cx - hwB * 0.80, bTop - 2, hwB * 1.60, L.baseH * 0.30, 7);  g = c.createLinearGradient(0, bTop - 2, 0, bTop + L.baseH * 0.30);  g.addColorStop(0, '#5b6175'); g.addColorStop(1, '#343947');  c.fillStyle = g; c.fill();  c.strokeStyle = 'rgba(255,255,255,0.25)'; c.lineWidth = 1.2; c.stroke();  c.fillStyle = 'rgba(255,255,255,0.06)';  roundRect(c, L.cx - hwB * 0.55, bTop + L.baseH * 0.34, hwB * 0.36, L.baseH * 0.52, hwB * 0.18); c.fill();  // switch recess + indicator bezel  roundRect(c, L.cx - L.switchW / 2 - 5, L.switchY - L.switchH / 2 - 5, L.switchW + 10, L.switchH + 10, 12);  c.fillStyle = 'rgba(0,0,0,0.45)'; c.fill();  c.strokeStyle = 'rgba(255,255,255,0.12)'; c.lineWidth = 1; c.stroke();  c.beginPath(); c.arc(L.cx - L.baseHW * 0.52, L.switchY, 7, 0, TAU); c.fillStyle = 'rgba(0,0,0,0.45)'; c.fill();  bgLayer = cv;}function buildFg() {  const { cv, c } = createLayer();  c.lineJoin = 'round';  // glass edge  lampPath(c);  c.strokeStyle = 'rgba(20,10,26,0.40)'; c.lineWidth = 5; c.stroke();  c.strokeStyle = 'rgba(255,255,255,0.42)'; c.lineWidth = 1.8; c.stroke();  // sheen inside glass  c.save(); lampPath(c); c.clip();  const hw0 = L.hwTop;  c.save();  c.translate(L.cx - L.maxHw * 0.42, L.bulbTopY + L.bulbH * 0.42); c.rotate(0.04);  let sg = c.createLinearGradient(0, -L.bulbH * 0.34, 0, L.bulbH * 0.34);  sg.addColorStop(0, 'rgba(255,255,255,0)'); sg.addColorStop(0.4, 'rgba(255,255,255,0.24)');  sg.addColorStop(0.66, 'rgba(255,255,255,0.18)'); sg.addColorStop(1, 'rgba(255,255,255,0)');  c.fillStyle = sg;  roundRect(c, -L.maxHw * 0.13, -L.bulbH * 0.34, L.maxHw * 0.26, L.bulbH * 0.68, L.maxHw * 0.13); c.fill();  c.restore();  c.save();  c.translate(L.cx + L.maxHw * 0.38, L.bulbTopY + L.bulbH * 0.40); c.rotate(-0.045);  sg = c.createLinearGradient(0, -L.bulbH * 0.22, 0, L.bulbH * 0.22);  sg.addColorStop(0, 'rgba(255,255,255,0)'); sg.addColorStop(0.5, 'rgba(255,255,255,0.13)'); sg.addColorStop(1, 'rgba(255,255,255,0)');  c.fillStyle = sg;  roundRect(c, -L.maxHw * 0.075, -L.bulbH * 0.22, L.maxHw * 0.15, L.bulbH * 0.44, L.maxHw * 0.075); c.fill();  c.restore();  // dome highlight  c.strokeStyle = 'rgba(255,255,255,0.42)'; c.lineWidth = 2.2;  c.beginPath(); c.arc(L.cx, L.bulbTopY, hw0 * 0.82, Math.PI * 1.18, Math.PI * 1.82); c.stroke();  c.restore();  // bottom collar  let g = c.createLinearGradient(0, L.baseTopY - 6, 0, L.baseTopY + 13);  g.addColorStop(0, '#3d414e'); g.addColorStop(1, '#1b1e27');  c.fillStyle = g;  roundRect(c, L.cx - L.collarHW, L.baseTopY - 6, L.collarHW * 2, 19, 8); c.fill();  c.fillStyle = 'rgba(255,255,255,0.28)'; roundRect(c, L.cx - L.collarHW + 4, L.baseTopY - 5, L.collarHW * 2 - 8, 2.4, 2); c.fill();  fgLayer = cv;}// ---------- per-frame drawing ----------function drawBlob(b) {  const t = clamp((b.y - L.bulbTopY) / L.bulbH, 0, 1);  const hw = profile(t);  const effR = Math.min(b.r, Math.max(7, hw - 3));  const u = clamp((b.heat - 0.12) / 0.88, 0, 1);  const base = lerpC([150, 26, 26], [255, 105, 30], u);  const hi = lerpC([228, 110, 66], [255, 200, 96], u);  const edge = lerpC([108, 16, 22], [168, 50, 14], u);  if (lampLight > 0.03) {    ctx.globalCompositeOperation = 'lighter';    const gg = ctx.createRadialGradient(b.x, b.y, effR * 0.5, b.x, b.y, effR * 1.65);    gg.addColorStop(0, `rgba(255,120,40,${0.26 * lampLight})`);    gg.addColorStop(1, 'rgba(255,120,40,0)');    ctx.fillStyle = gg;    ctx.beginPath(); ctx.arc(b.x, b.y, effR * 1.65, 0, TAU); ctx.fill();    ctx.globalCompositeOperation = 'source-over';  }  ctx.beginPath();  const N = 18;  for (let i = 0; i <= N; i++) {    const a = i / N * TAU;    const w = 1 + 0.055 * Math.sin(a * 3 + time * 2.1 + b.phase) + 0.045 * Math.sin(a * 5 - time * 1.55 + b.phase * 1.9);    const rr = effR * w;    const x = b.x + Math.cos(a) * rr, y = b.y + Math.sin(a) * rr;    if (i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y);  }  ctx.closePath();  const g = ctx.createRadialGradient(b.x - effR * 0.3, b.y - effR * 0.38, effR * 0.12, b.x, b.y, effR * 1.12);  g.addColorStop(0, rgb(hi)); g.addColorStop(0.45, rgb(base)); g.addColorStop(1, rgb(edge));  ctx.fillStyle = g; ctx.fill();  ctx.save();  ctx.translate(b.x - effR * 0.30, b.y - effR * 0.42); ctx.rotate(-0.5);  ctx.fillStyle = 'rgba(255,235,210,0.30)';  ctx.beginPath(); ctx.ellipse(0, 0, effR * 0.34, effR * 0.20, 0, 0, TAU); ctx.fill();  ctx.restore();}function drawBlobs() {  ctx.save();  lampPath(ctx); ctx.clip();  if (lampLight > 0.02) {    ctx.globalCompositeOperation = 'lighter';    const g = ctx.createRadialGradient(L.cx, L.bulbBottomY - 12, 4, L.cx, L.bulbBottomY - 12, L.bulbH * 0.85);    g.addColorStop(0, `rgba(255,138,46,${(0.42 + 0.06 * Math.sin(time * 2.1)) * lampLight})`);    g.addColorStop(1, 'rgba(255,138,46,0)');    ctx.fillStyle = g;    ctx.fillRect(L.cx - L.maxHw, L.bulbTopY, L.maxHw * 2, L.bulbH);    ctx.globalCompositeOperation = 'source-over';  }  for (const b of blobs) drawBlob(b);  ctx.restore();}function drawSwitchAndIndicator() {  const indX = L.cx - L.baseHW * 0.52, indY = L.switchY;  if (lampLight > 0.03) {    ctx.globalCompositeOperation = 'lighter';    const g = ctx.createRadialGradient(indX, indY, 1, indX, indY, 12);    g.addColorStop(0, `rgba(255,190,90,${0.8 * lampLight})`);    g.addColorStop(1, 'rgba(255,190,90,0)');    ctx.fillStyle = g;    ctx.beginPath(); ctx.arc(indX, indY, 12, 0, TAU); ctx.fill();    ctx.globalCompositeOperation = 'source-over';  }  ctx.fillStyle = lampLight > 0.4 ? '#ffbe5a' : '#3f3b38';  ctx.beginPath(); ctx.arc(indX, indY, 4.2, 0, TAU); ctx.fill();  const x = L.cx - L.switchW / 2, y = L.switchY - L.switchH / 2;  const on = lampLight > 0.5;  roundRect(ctx, x - 2, y - 2, L.switchW + 4, L.switchH + 4, 8);  let g = ctx.createLinearGradient(0, y - 2, 0, y + L.switchH + 2);  if (on) { g.addColorStop(0, '#f7ecdb'); g.addColorStop(0.5, '#ddd2bd'); g.addColorStop(1, '#b0a48a'); }  else { g.addColorStop(0, '#5b5560'); g.addColorStop(0.5, '#453f49'); g.addColorStop(1, '#332f37'); }  ctx.fillStyle = g; ctx.fill();  const halfH = L.switchH / 2;  const pressedY = on ? y : y + halfH;  roundRect(ctx, x - 1.5, pressedY - 1.5, L.switchW + 3, halfH + 1, 6);  g = ctx.createLinearGradient(0, pressedY, 0, pressedY + halfH);  if (on) { g.addColorStop(0, '#c9b895'); g.addColorStop(1, '#a99b7c'); }  else { g.addColorStop(0, '#2a2630'); g.addColorStop(1, '#1e1b23'); }  ctx.fillStyle = g; ctx.fill();  ctx.fillStyle = on ? '#8a5a1a' : 'rgba(215,206,196,0.5)';  ctx.font = `700 ${Math.max(8, L.switchH * 0.27)}px system-ui, sans-serif`;  ctx.textAlign = 'center'; ctx.textBaseline = 'middle';  ctx.fillText('ON', L.cx, y + halfH * 0.5);  ctx.fillStyle = !on ? 'rgba(215,206,196,0.75)' : 'rgba(120,110,100,0.55)';  ctx.fillText('OFF', L.cx, y + halfH * 1.5);}function drawHint() {  if (hintAlpha <= 0.01) return;  ctx.save();  ctx.globalAlpha = hintAlpha * 0.9;  ctx.fillStyle = 'rgba(86,56,32,0.85)';  ctx.font = `600 ${Math.max(11, W * 0.030)}px system-ui, sans-serif`;  ctx.textAlign = 'center'; ctx.textBaseline = 'middle';  ctx.fillText('tap the switch', L.cx, H * 0.065);  ctx.restore();}function render(now) {  requestAnimationFrame(render);  const dt = clamp((now - last) / 1000, 0.001, 0.045);  last = now; time += dt;  lampLight += ((lampOn ? 1 : 0) - lampLight) * Math.min(1, dt * 4.2);  if (Math.abs(lampLight - (lampOn ? 1 : 0)) < 0.003) lampLight = lampOn ? 1 : 0;  if (hintDone && hintAlpha > 0) hintAlpha = Math.max(0, hintAlpha - dt * 1.6);  updateBlobs(dt);  ctx.drawImage(bgLayer, 0, 0, W, H);  if (lampLight > 0.02) {    ctx.globalCompositeOperation = 'lighter';    let g = ctx.createRadialGradient(L.cx, L.bulbTopY + L.bulbH * 0.5, 10, L.cx, L.bulbTopY + L.bulbH * 0.5, L.maxHw * 3.4);    g.addColorStop(0, `rgba(255,150,64,${0.26 * lampLight})`);    g.addColorStop(1, 'rgba(255,150,64,0)');    ctx.fillStyle = g; ctx.fillRect(0, 0, W, H);    g = ctx.createRadialGradient(L.cx, L.baseBottomY - 8, 8, L.cx, L.baseBottomY - 8, L.baseHW * 2.6);    g.addColorStop(0, `rgba(255,150,70,${0.20 * lampLight})`);    g.addColorStop(1, 'rgba(255,150,70,0)');    ctx.fillStyle = g; ctx.fillRect(0, L.deskTop, W, H - L.deskTop);    ctx.globalCompositeOperation = 'source-over';  }  drawBlobs();  ctx.drawImage(fgLayer, 0, 0, W, H);  if (lampLight < 0.98) {    ctx.fillStyle = `rgba(13,15,32,${(1 - lampLight) * 0.62})`;    ctx.fillRect(0, 0, W, H);  }  drawSwitchAndIndicator();  drawHint();}// ---------- interaction / resize / init ----------function toggleLamp() {  lampOn = !lampOn;  hintDone = true;  canvas.setAttribute('aria-pressed', String(lampOn));}canvas.addEventListener('pointerdown', e => {  const rect = canvas.getBoundingClientRect();  const x = e.clientX - rect.left, y = e.clientY - rect.top;  const hw = L.switchW * 0.72 + 10, hh = L.switchH * 0.72 + 12;  const dx = Math.abs(x - L.cx);  const onBase = dx < L.baseHW * 1.25 && y > L.baseTopY - 10 && y < L.baseBottomY + 8;  const onSwitch = dx < hw && Math.abs(y - L.switchY) < hh;  if (onBase || onSwitch) toggleLamp();});canvas.addEventListener('keydown', e => {  if (e.code === 'Space' || e.code === 'Enter') { e.preventDefault(); toggleLamp(); }});function resize() {  W = window.innerWidth; H = window.innerHeight;  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);  const old = L;  computeLayout();  buildBg(); buildFg();  const k = old ? L.maxHw / old.maxHw : 1;  if (blobs.length && old) {    for (const b of blobs) {      const t = clamp((b.y - old.bulbTopY) / old.bulbH, 0, 1);      b.r *= k; b.vx *= k; b.vy *= k;      b.y = L.bulbTopY + L.bulbH * t;      b.x = L.cx + (b.x - old.cx) * k;    }  } else {    spawnBlobs();  }}window.addEventListener('resize', resize);window.addEventListener('orientationchange', () => setTimeout(resize, 150));resize();requestAnimationFrame(render);</script></body></html>