Lava lamp v1 · OpenCode25.11.2026 09:57

Source Inkling 2 Mini, Medium effort

index.html · 17.2 KB · 498 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"><meta name="theme-color" content="#14101b"><title>Lava Lamp</title><style>  * { box-sizing: border-box; margin: 0; padding: 0; }  html, body { height: 100%; }  body {    overflow: hidden;    background: #14101b;    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;    -webkit-user-select: none; user-select: none;    -webkit-tap-highlight-color: transparent;  }  #stage { position: fixed; inset: 0; }  canvas { display: block; width: 100%; height: 100%; }  .caption {    position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 0; right: 0;    text-align: center; color: rgba(235,228,248,.34);    font-size: 11px; font-weight: 600; letter-spacing: .42em; text-indent: .42em;    pointer-events: none;  }  .switch {    position: fixed; z-index: 2; left: 50%;    bottom: calc(18px + env(safe-area-inset-bottom));    transform: translateX(-50%);    display: flex; align-items: center; gap: 12px;    padding: 11px 18px; border-radius: 999px; cursor: pointer;    background: rgba(24,19,34,.62);    border: 1px solid rgba(255,255,255,.10);    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);    box-shadow: 0 6px 24px rgba(0,0,0,.4);    transition: border-color .3s;  }  .switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }  .track {    position: relative; width: 62px; height: 32px; border-radius: 999px;    background: #2b2836; border: 1px solid rgba(255,255,255,.14);    transition: background .35s, box-shadow .35s;  }  .thumb {    position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;    background: linear-gradient(180deg,#d7d7e0,#9a9aa8);    transition: transform .3s cubic-bezier(.5,1.6,.4,1), background .3s;  }  .switch input:checked ~ .track {    background: linear-gradient(180deg,#ff8a2a,#ff5d1f);    box-shadow: 0 0 18px 2px rgba(255,140,50,.55), inset 0 1px 2px rgba(255,255,255,.35);    border-color: rgba(255,190,120,.7);  }  .switch input:checked ~ .track .thumb {    transform: translateX(30px);    background: linear-gradient(180deg,#ffffff,#ffe9c9);    box-shadow: 0 0 10px 2px rgba(255,190,90,.8);  }  .switch input:focus-visible ~ .track { outline: 2px solid #ffd23f; outline-offset: 3px; }  .switch-label {    min-width: 36px; text-align: left;    color: #f2ead9; font-size: 12px; font-weight: 700; letter-spacing: .22em; text-indent: 0;    transition: color .3s;  }  .switch-label.off { color: rgba(230,225,240,.45); }</style></head><body><div id="stage"><canvas id="lamp"></canvas></div><div class="caption">LAVA LAMP</div><label class="switch" for="power">  <input type="checkbox" id="power" checked>  <span class="track"><span class="thumb"></span></span>  <span class="switch-label" id="stateLabel">ON</span></label><script>(() => {  'use strict';  const canvas = document.getElementById('lamp');  const ctx = canvas.getContext('2d');  const power = document.getElementById('power');  const stateLabel = document.getElementById('stateLabel');  let W = 0, H = 0, t = 0;  let geom = null;  // --- lamp thermal state ---  let lampOn = true;  let lampHeat = 0.55;          // 0 (off) .. 1 (full bloom)  const HEAT_RATE = 2.4;        // lamp warms up/cools down smoothly  const BLOB_HEAT_RATE = 1.05;  // blobs respond with thermal inertia  // --- blobs ---  let blobs = [];  const MAX_BLOBS = 9;  const BLOBS_INITIAL = 6;  // --- ripple rings on merge/split ---  let ripples = [];  const clamp = (v, a, b) => v < a ? a : v > b ? b : v;  const rand = (a, b) => a + Math.random() * (b - a);  const lerp = (a, b, k) => a + (b - a) * k;  function computeGeometry() {    const deskY = Math.round(H * 0.80);    const baseH = clamp(H * 0.085, 52, 92);    const tubeW = clamp(W * 0.44, 126, 228);    const tubeH = clamp(H * 0.46, 230, 470);    const tubeCX = W / 2;    const tubeBottom = deskY - baseH + 12;    const tubeTop = tubeBottom - tubeH;    geom = {      deskY, baseH, tubeW, tubeH, tubeCX, tubeTop, tubeBottom,      baseTop: deskY - baseH,      inner: {        x0: tubeCX - tubeW / 2 + 9, x1: tubeCX + tubeW / 2 - 9,        y0: tubeTop + 9, y1: tubeBottom - 7      }    };  }  function tubeMaxRadius() { return geom.tubeW * 0.19; }  function glassPath(inset) {    const { tubeW, tubeTop, tubeBottom, tubeCX } = geom;    const w = tubeW - (inset || 0) * 2;    const x = tubeCX - w / 2, y = tubeTop + (inset || 0);    const h = tubeBottom - tubeTop - (inset || 0);    const cap = w / 2;    ctx.beginPath();    ctx.moveTo(x, y + cap);    ctx.lineTo(x, y + h);    ctx.lineTo(x + w, y + h);    ctx.lineTo(x + w, y + cap);    ctx.arc(tubeCX, y + cap, cap, 0, Math.PI, true);    ctx.closePath();  }  function spawnBlobs() {    blobs = [];    for (let i = 0; i < BLOBS_INITIAL; i++) {      const r = rand(11, 20) * (geom.tubeW / 185);      blobs.push({        x: rand(geom.inner.x0 + r, geom.inner.x1 - r),        y: rand(geom.inner.y0 + r, geom.inner.y1 - r),        r,        heat: 0.4 + Math.random() * 0.3,        vy: 0,        phase: Math.random() * Math.PI * 2      });    }  }  function clampBlob(b) {    const maxR = tubeMaxRadius();    b.r = clamp(b.r, 9, maxR * 1.2);    b.x = clamp(b.x, geom.inner.x0 + b.r, geom.inner.x1 - b.r);    b.y = clamp(b.y, geom.inner.y0 + b.r, geom.inner.y1 - b.r);  }  function addRipple(x, y, type) {    ripples.push({ x, y, type, age: 0 });    if (ripples.length > 8) ripples.shift();  }  function step(dt) {    // thermal state of lamp    lampHeat += ((lampOn ? 1 : 0) - lampHeat) * Math.min(1, dt * HEAT_RATE);    // ripples decay    for (const r of ripples) r.age += dt;    ripples = ripples.filter(r => r.age < 0.6);    for (const b of blobs) {      // blob heat eases toward lamp heat      b.heat += (lampHeat - b.heat) * Math.min(1, dt * BLOB_HEAT_RATE);      // buoyancy: warm blobs rise, cool blobs sink      const buoyancy = b.heat - 0.38;      const vyTarget = -buoyancy * geom.tubeH * 0.62;      b.vy += (vyTarget - b.vy) * Math.min(1, dt * 2.0);      b.y += b.vy * dt;      // gentle side-to-side drift      b.x += Math.sin(t * 0.85 + b.phase) * geom.tubeW * 0.05 * dt;      clampBlob(b);    }    // merge overlapping blobs    let merged;    do {      merged = false;      outer:      for (let i = 0; i < blobs.length; i++) {        for (let j = i + 1; j < blobs.length; j++) {          const a = blobs[i], c = blobs[j];          const d = Math.hypot(a.x - c.x, a.y - c.y);          if (d < (a.r + c.r) * 0.72) {            const R = Math.sqrt(a.r * a.r + c.r * c.r);            const weight = a.r * a.r + c.r * c.r;            const nx = (a.x * a.r * a.r + c.x * c.r * c.r) / weight;            const ny = (a.y * a.r * a.r + c.y * c.r * c.r) / weight;            blobs[i] = {              x: nx, y: ny, r: R,              heat: Math.max(a.heat, c.heat),              vy: (a.vy + c.vy) / 2,              phase: Math.random() * Math.PI * 2            };            blobs.splice(j, 1);            addRipple(nx, ny, 'merge');            merged = true;            break outer;          }        }      }    } while (merged && blobs.length > 1);    // split blobs that grew too big    const maxR = tubeMaxRadius();    const splitters = blobs.filter(b => b.r > maxR);    if (splitters.length) {      for (const b of splitters) {        const half = b.r / Math.SQRT2;        const ang = b.vy > 0 ? Math.PI / 2 : -Math.PI / 2; // split along the axis of travel        const off = b.r * 0.55;        const nx = clamp(b.x + Math.cos(ang) * off, geom.inner.x0 + half, geom.inner.x1 - half);        const ny1 = clamp(b.y + Math.sin(ang) * off, geom.inner.y0 + half, geom.inner.y1 - half);        const ny2 = clamp(b.y - Math.sin(ang) * off, geom.inner.y0 + half, geom.inner.y1 - half);        blobs.push({          x: nx + rand(-3, 3), y: ny1, r: half,          heat: b.heat, vy: b.vy * 0.5 + rand(-26, 26), phase: Math.random() * Math.PI * 2        });        blobs.push({          x: nx + rand(-3, 3), y: ny2, r: half,          heat: b.heat, vy: b.vy * 0.5 + rand(-26, 26), phase: Math.random() * Math.PI * 2        });        addRipple(b.x, b.y, 'split');        b.dead = true;      }      blobs = blobs.filter(b => !b.dead);      // keep count in sane range: merge overflow pairs if too many      while (blobs.length > MAX_BLOBS) {        for (let i = 0; i < blobs.length; i++) {          for (let j = i + 1; j < blobs.length; j++) {            const a = blobs[i], c = blobs[j];            const d = Math.hypot(a.x - c.x, a.y - c.y);            if (d < (a.r + c.r) * 1.05) {              const R = Math.sqrt(a.r * a.r + c.r * c.r);              const weight = a.r * a.r + c.r * c.r;              blobs[i] = {                x: (a.x * a.r * a.r + c.x * c.r * c.r) / weight,                y: (a.y * a.r * a.r + c.y * c.r * c.r) / weight,                r: R, heat: Math.max(a.heat, c.heat), vy: (a.vy + c.vy) / 2,                phase: Math.random() * Math.PI * 2              };              blobs.splice(j, 1);              break;            }          }          if (blobs.length <= MAX_BLOBS) break;        }        if (blobs.length > MAX_BLOBS) {          // last resort: drop the smallest blob          let minI = 0;          for (let i = 1; i < blobs.length; i++) if (blobs[i].r < blobs[minI].r) minI = i;          blobs.splice(minI, 1);        }        if (blobs.length <= MAX_BLOBS) break;      }    }  }  function heatColor(h) {    // cold magenta -> hot orange -> bright yellow    let r, g, b;    if (h < 0.5) {      const k = h / 0.5;      r = lerp(150, 255, k); g = lerp(42, 118, k); b = lerp(88, 38, k);    } else {      const k = (h - 0.5) / 0.5;      r = 255; g = lerp(118, 214, k); b = lerp(38, 86, k);    }    return [r | 0, g | 0, b | 0];  }  function render() {    // room wall    let g = ctx.createLinearGradient(0, 0, 0, H);    g.addColorStop(0, '#0c0a14');    g.addColorStop(0.55, '#191327');    g.addColorStop(1, '#241a2e');    ctx.fillStyle = g;    ctx.fillRect(0, 0, W, H);    const { deskY, tubeW, tubeTop, tubeBottom, tubeCX, baseH, baseTop } = geom;    const flicker = 1 + Math.sin(t * 6.3) * 0.045 + Math.sin(t * 11.7) * 0.03;    const glow = lampHeat * flicker;    // desk    g = ctx.createLinearGradient(0, deskY, 0, H);    g.addColorStop(0, '#6d4a2e');    g.addColorStop(0.12, '#59391f');    g.addColorStop(1, '#2c1b12');    ctx.fillStyle = g;    ctx.fillRect(0, deskY, W, H - deskY);    ctx.fillStyle = 'rgba(255,220,170,0.18)';    ctx.fillRect(0, deskY, W, 2);    // lamp shadow on desk    ctx.fillStyle = 'rgba(0,0,0,0.45)';    ctx.beginPath();    ctx.ellipse(tubeCX, baseTop + baseH - 4, tubeW * 0.78, baseH * 0.28, 0, 0, Math.PI * 2);    ctx.fill();    // warm pool of light on the desk    if (glow > 0.02) {      g = ctx.createRadialGradient(tubeCX, baseTop + baseH * 0.4, 4, tubeCX, baseTop + baseH * 0.4, tubeW * 1.5);      g.addColorStop(0, `rgba(255,150,60,${0.34 * glow})`);      g.addColorStop(1, 'rgba(255,150,60,0)');      ctx.fillStyle = g;      ctx.fillRect(tubeCX - tubeW * 1.6, baseTop - baseH * 0.5, tubeW * 3.2, Math.max(1, H - baseTop + baseH * 0.5));    }    // base    g = ctx.createLinearGradient(0, baseTop, 0, deskY);    g.addColorStop(0, '#3a3542');    g.addColorStop(0.35, '#26222e');    g.addColorStop(1, '#141118');    ctx.fillStyle = g;    roundRect(tubeCX - tubeW * 0.62, baseTop, tubeW * 1.24, baseH, [16, 16, 8, 8]);    ctx.fill();    // base rim    g = ctx.createLinearGradient(0, baseTop, 0, baseTop + 10);    g.addColorStop(0, 'rgba(255,255,255,0.30)');    g.addColorStop(1, 'rgba(255,255,255,0.02)');    ctx.fillStyle = g;    roundRect(tubeCX - tubeW * 0.62, baseTop, tubeW * 1.24, 9, [16, 16, 0, 0]);    ctx.fill();    // base label    ctx.fillStyle = `rgba(255,205,140,${0.5 * glow + 0.18})`;    ctx.font = `700 ${Math.max(9, baseH * 0.17)}px system-ui, sans-serif`;    ctx.textAlign = 'center';    ctx.textBaseline = 'middle';    ctx.fillText('L A V A', tubeCX, baseTop + baseH * 0.58);    // glass back    glassPath(0);    g = ctx.createLinearGradient(0, tubeTop, 0, tubeBottom);    g.addColorStop(0, 'rgba(255,255,255,0.05)');    g.addColorStop(0.6, 'rgba(255,255,255,0.02)');    g.addColorStop(1, 'rgba(255,255,255,0.06)');    ctx.fillStyle = g;    ctx.fill();    // everything inside the glass    ctx.save();    glassPath(9);    ctx.clip();    // interior bottom glow    if (glow > 0.02) {      g = ctx.createRadialGradient(tubeCX, tubeBottom - 6, 4, tubeCX, tubeBottom - 6, tubeW * 1.35);      g.addColorStop(0, `rgba(255,138,40,${0.62 * glow})`);      g.addColorStop(0.6, `rgba(210,70,30,${0.30 * glow})`);      g.addColorStop(1, 'rgba(210,70,30,0)');      ctx.fillStyle = g;      ctx.fillRect(tubeCX - tubeW, tubeTop, tubeW * 2, tubeBottom - tubeTop + 8);    } else {      g = ctx.createLinearGradient(0, tubeTop, 0, tubeBottom);      g.addColorStop(0, 'rgba(40,30,52,0.55)');      g.addColorStop(1, 'rgba(22,16,30,0.55)');      ctx.fillStyle = g;      ctx.fillRect(tubeCX - tubeW, tubeTop, tubeW * 2, tubeBottom - tubeTop + 8);    }    // blobs (halo first, then core)    for (const b of blobs) {      const [r, gr, bl] = heatColor(b.heat);      const halo = ctx.createRadialGradient(b.x, b.y, b.r * 0.2, b.x, b.y, b.r * 1.65);      halo.addColorStop(0, `rgba(${r},${gr},${bl},0.34)`);      halo.addColorStop(1, `rgba(${r},${gr},${bl},0)`);      ctx.fillStyle = halo;      ctx.beginPath();      ctx.arc(b.x, b.y, b.r * 1.65, 0, Math.PI * 2);      ctx.fill();    }    for (const b of blobs) {      const [r, gr, bl] = heatColor(b.heat);      const core = ctx.createRadialGradient(b.x - b.r * 0.25, b.y - b.r * 0.35, b.r * 0.1, b.x, b.y, b.r);      core.addColorStop(0, `rgba(255,236,170,0.98)`);      core.addColorStop(0.45, `rgba(${r},${gr},${bl},0.97)`);      core.addColorStop(1, `rgba(${Math.round(r * 0.55)},${Math.round(gr * 0.4)},${Math.round(bl * 0.55)},0.92)`);      ctx.fillStyle = core;      ctx.beginPath();      ctx.arc(b.x, b.y, b.r, 0, Math.PI * 2);      ctx.fill();    }    // glass specular highlight (front, clipped)    g = ctx.createLinearGradient(0, tubeTop, 0, tubeBottom);    g.addColorStop(0, 'rgba(255,255,255,0.30)');    g.addColorStop(1, 'rgba(255,255,255,0.04)');    ctx.fillStyle = g;    const hw = tubeW * 0.13;    roundRect(tubeCX - tubeW * 0.31, tubeTop + tubeW * 0.28, hw, tubeBottom - tubeTop - tubeW * 0.38, hw / 2);    ctx.fill();    ctx.restore();    // glass outline    glassPath(0);    ctx.strokeStyle = 'rgba(255,255,255,0.35)';    ctx.lineWidth = 2;    ctx.stroke();    glassPath(2);    ctx.strokeStyle = 'rgba(0,0,0,0.35)';    ctx.lineWidth = 1;    ctx.stroke();    // ripples (merge/split)    for (const rp of ripples) {      const k = rp.age / 0.6;      ctx.strokeStyle = rp.type === 'merge'        ? `rgba(255,225,150,${0.55 * (1 - k)})`        : `rgba(255,170,220,${0.55 * (1 - k)})`;      ctx.lineWidth = 2;      ctx.beginPath();      ctx.arc(rp.x, rp.y, 6 + k * 42, 0, Math.PI * 2);      ctx.stroke();    }    // vignette    g = ctx.createRadialGradient(W / 2, H * 0.42, H * 0.25, W / 2, H * 0.42, H * 0.85);    g.addColorStop(0, 'rgba(0,0,0,0)');    g.addColorStop(1, 'rgba(0,0,0,0.5)');    ctx.fillStyle = g;    ctx.fillRect(0, 0, W, H);  }  function roundRect(x, y, w, h, radii) {    const [tl, tr, br, bl] = radii;    ctx.beginPath();    ctx.moveTo(x + tl, y);    ctx.lineTo(x + w - tr, y);    if (tr) ctx.arcTo(x + w, y, x + w, y + tr, tr); else ctx.lineTo(x + w, y);    ctx.lineTo(x + w, y + h - br);    if (br) ctx.arcTo(x + w, y + h, x + w - br, y + h, br); else ctx.lineTo(x + w, y + h);    ctx.lineTo(x + bl, y + h);    if (bl) ctx.arcTo(x, y + h, x, y + h - bl, bl); else ctx.lineTo(x, y + h);    ctx.lineTo(x, y + tl);    if (tl) ctx.arcTo(x, y, x + tl, y, tl); else ctx.lineTo(x, y);    ctx.closePath();  }  function resize() {    const 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);    ctx.setTransform(dpr, 0, 0, dpr, 0, 0);    computeGeometry();    for (const b of blobs) clampBlob(b);  }  let last = performance.now();  function frame(now) {    const dt = Math.min(0.05, (now - last) / 1000);    last = now;    t += dt;    step(dt);    render();    requestAnimationFrame(frame);  }  power.addEventListener('change', () => {    lampOn = power.checked;    stateLabel.textContent = lampOn ? 'ON' : 'OFF';    stateLabel.classList.toggle('off', !lampOn);  });  window.addEventListener('resize', resize);  window.addEventListener('orientationchange', () => setTimeout(resize, 100));  resize();  spawnBlobs();  requestAnimationFrame(frame);})();</script></body></html>