Lava lamp v1 · Claude Code25.11.2026 10:40

Source Inkling 2 Mini, Medium effort

index.html · 17.8 KB · 537 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.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"><title>Lava Lamp</title><style>  * { margin: 0; padding: 0; box-sizing: border-box; }  html, body {    height: 100%;    overflow: hidden;    background: #17131c;    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;    -webkit-user-select: none;    user-select: none;    -webkit-tap-highlight-color: transparent;  }  #app {    position: fixed;    inset: 0;    display: flex;    flex-direction: column;  }  #scene {    flex: 1 1 auto;    position: relative;    min-height: 0;  }  canvas {    position: absolute;    inset: 0;    width: 100%;    height: 100%;    display: block;    touch-action: none;  }  #panel {    flex: 0 0 auto;    display: flex;    align-items: center;    justify-content: center;    gap: 14px;    padding: 12px 16px calc(14px + env(safe-area-inset-bottom, 0px));    background: linear-gradient(180deg, rgba(20,16,26,0) 0%, rgba(18,14,24,0.9) 45%);  }  #switchLabel {    font-size: 12px;    letter-spacing: 0.22em;    text-transform: uppercase;    color: #9d8fa8;    font-weight: 600;  }  #lampSwitch {    position: relative;    width: 76px;    height: 38px;    border-radius: 999px;    border: 1px solid rgba(255,255,255,0.14);    background: linear-gradient(180deg, #2a2433, #1c1723);    box-shadow: inset 0 2px 6px rgba(0,0,0,0.6), 0 1px 0 rgba(255,255,255,0.06);    cursor: pointer;    transition: background 0.3s, box-shadow 0.3s;    -webkit-appearance: none;    appearance: none;    outline: none;  }  #lampSwitch:focus-visible {    box-shadow: 0 0 0 3px rgba(255,170,80,0.45), inset 0 2px 6px rgba(0,0,0,0.6);  }  #lampSwitch .knob {    position: absolute;    top: 3px;    left: 4px;    width: 30px;    height: 30px;    border-radius: 50%;    background: linear-gradient(180deg, #f2ede6, #b9b0a6);    box-shadow: 0 2px 5px rgba(0,0,0,0.55), inset 0 1px 1px rgba(255,255,255,0.8);    transition: transform 0.28s cubic-bezier(0.34, 1.4, 0.64, 1);  }  #lampSwitch[aria-checked="true"] {    background: linear-gradient(180deg, #b3541e, #7a3510);    box-shadow: inset 0 2px 6px rgba(0,0,0,0.45), 0 0 18px rgba(255,130,40,0.45);  }  #lampSwitch[aria-checked="true"] .knob { transform: translateX(36px); }  #stateText {    font-size: 12px;    letter-spacing: 0.18em;    text-transform: uppercase;    color: #6f6379;    font-weight: 600;    min-width: 46px;  }</style></head><body><div id="app">  <div id="scene"><canvas id="cv"></canvas></div>  <div id="panel">    <span id="switchLabel">Lamp</span>    <button id="lampSwitch" role="switch" aria-checked="true" aria-label="Toggle lamp">      <span class="knob"></span>    </button>    <span id="stateText">On</span>  </div></div><script>(() => {  "use strict";  const canvas = document.getElementById("cv");  const ctx = canvas.getContext("2d");  const switchBtn = document.getElementById("lampSwitch");  const stateText = document.getElementById("stateText");  // ---------- sizing ----------  let W = 0, H = 0, DPR = 1;  function resize() {    DPR = Math.min(window.devicePixelRatio || 1, 2);    const rect = canvas.getBoundingClientRect();    W = rect.width; H = rect.height;    canvas.width = Math.round(W * DPR);    canvas.height = Math.round(H * DPR);    ctx.setTransform(DPR, 0, 0, DPR, 0, 0);    layout();  }  // ---------- scene layout ----------  // Lamp geometry derived from canvas size (portrait-friendly)  let lamp = {};  function layout() {    const unit = Math.min(W, H * 0.62);    const glassW = unit * 0.46;    const glassH = H * 0.52;    const baseW = glassW * 1.32;    const baseH = Math.max(26, H * 0.055);    const cx = W / 2;    const deskY = H * 0.86;               // horizon / desk line    const baseTop = deskY - baseH;    const glassBottom = baseTop + 4;    const glassTop = glassBottom - glassH;    lamp = { cx, deskY, baseW, baseH, glassW, glassH, glassTop, glassBottom, baseTop, unit };  }  // ---------- wax blobs ----------  const blobs = [];  const PB = {    maxBlobs: 9,    minR: 10,    maxR: 30,  };  function glassInterior() {    // inner (usable) glass region, slightly inset    return {      left: lamp.cx - lamp.glassW / 2 + 7,      right: lamp.cx + lamp.glassW / 2 - 7,      top: lamp.glassTop + 8,      bottom: lamp.glassBottom - 6,    };  }  function rand(a, b) { return a + Math.random() * (b - a); }  function spawnBlob(x, y, r, temp) {    return {      x, y,      vx: rand(-6, 6),      vy: 0,      r: r || rand(PB.minR, PB.maxR * 0.65),      temp: temp !== undefined ? temp : rand(0.2, 0.8),      phase: rand(0, Math.PI * 2),      wobble: rand(0.06, 0.12),      drift: rand(-0.6, 0.6),      wobSpeed: rand(0.7, 1.4),    };  }  function initBlobs() {    blobs.length = 0;    const g = glassInterior();    for (let i = 0; i < 5; i++) {      const b = spawnBlob(rand(g.left + 20, g.right - 20), rand(g.top + 20, g.bottom - 20));      blobs.push(b);    }  }  // ---------- state ----------  let lampOn = true;  let glow = 1;          // smoothed lamp brightness 0..1  let time = 0;  let last = 0;  function setLamp(on) {    lampOn = on;    switchBtn.setAttribute("aria-checked", String(on));    stateText.textContent = on ? "On" : "Off";  }  switchBtn.addEventListener("click", () => setLamp(!lampOn));  // ---------- physics ----------  function avgTemp() {    let s = 0;    for (const b of blobs) s += b.temp;    return blobs.length ? s / blobs.length : 0.5;  }  function step(dt) {    time += dt;    const g = glassInterior();    const midX = (g.left + g.right) / 2;    const avg = avgTemp();    const lampTarget = lampOn ? 1 : 0;    // lamp brightness easing    glow += (lampTarget - glow) * Math.min(1, dt * 1.6);    for (const b of blobs) {      // local heating: hotter near the base      const depth = 1 - (b.y - g.top) / (g.bottom - g.top); // 0 top, 1 bottom      const localTarget = lampOn ? Math.min(1, 0.35 + depth * 0.85) : 0.05;      const rate = lampOn ? 0.35 : 0.55;      b.temp += (localTarget - b.temp) * Math.min(1, dt * rate);      // buoyancy: warmer than the average rises      const buoy = (b.temp - avg) * 520; // px/s^2-ish      b.vy += buoy * dt;      // when lamp is off, gravity takes over: cold wax sinks      b.vy += (1 - glow) * 34 * dt;      // light damping + gravity pull toward neutral      b.vy *= (1 - Math.min(0.9, dt * 1.9));      // horizontal wander      b.vx += (Math.sin(time * 0.9 + b.phase) * 14 + b.drift * 8 - (b.x - midX) * 0.15) * dt;      b.vx *= (1 - Math.min(0.9, dt * 1.6));      b.x += b.vx * dt;      b.y += b.vy * dt;      // glass walls (capsule-ish: flat sides, rounded top)      const half = (g.right - g.left) / 2;      const r = b.r * 0.82;      const cxMid = (g.left + g.right) / 2;      // rounded top region      const topRadius = half - 2;      const topArcY = g.top + topRadius;      const dyTop = b.y - topArcY;      if (b.y < topArcY) {        // within the arc zone: keep inside circle        const dx = b.x - cxMid;        if (dx * dx + dyTop * dyTop > (topRadius - r) * (topRadius - r) && dyTop < 0) {          const d = Math.hypot(dx, dyTop) || 1;          const maxD = topRadius - r;          b.x = cxMid + (dx / d) * maxD;          b.y = topArcY + (dyTop / d) * maxD;          b.vy = Math.abs(b.vy) * 0.4;        }      }      // flat sides      if (b.x - r < g.left) { b.x = g.left + r; b.vx = Math.abs(b.vx) * 0.5; }      if (b.x + r > g.right) { b.x = g.right - r; b.vx = -Math.abs(b.vx) * 0.5; }      // bottom floor      if (b.y + r > g.bottom) { b.y = g.bottom - r; b.vy = -Math.abs(b.vy) * 0.3; }      // hard top clamp      if (b.y - r < g.top) { b.y = g.top + r; b.vy = Math.abs(b.vy) * 0.3; }      b.phase += dt * b.wobSpeed;    }    // merge pass (runs before split)    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 dist = Math.hypot(dx, dy);        const touch = (a.r + b.r) * 0.72;        if (dist < touch) {          const area = a.r * a.r + b.r * b.r;          const newR = Math.sqrt(area);          const tot = Math.max(0.001, a.r + b.r);          const nx = (a.x * a.r + b.x * b.r) / tot;          const ny = (a.y * a.r + b.y * b.r) / tot;          const nt = (a.temp + b.temp) / 2;          const merged = spawnBlob(nx, ny, newR, nt);          merged.vx = (a.vx + b.vx) / 2;          merged.vy = (a.vy + b.vy) / 2;          merged.phase = Math.max(a.phase, b.phase);          blobs.splice(j, 1);          blobs.splice(i, 1, merged);          i = -1; // restart outer loop safely          break;        }      }    }    // split pass    for (let i = blobs.length - 1; i >= 0; i--) {      const b = blobs[i];      if (b.r > PB.maxR && blobs.length < PB.maxBlobs) {        const g2 = glassInterior();        const newR = b.r / Math.sqrt(2) - 1;        const off = Math.min(newR * 0.9, (g2.right - g2.left) * 0.22);        const dir = b.x > (g2.left + g2.right) / 2 ? -1 : 1;        const s1 = spawnBlob(b.x + dir * off * 0.5, b.y - newR * 0.3, newR, b.temp + rand(-0.08, 0.08));        const s2 = spawnBlob(b.x - dir * off * 0.5, b.y + newR * 0.35, newR, b.temp + rand(-0.08, 0.08));        s1.vx = dir * rand(10, 26); s1.vy = rand(-8, 8);        s2.vx = -dir * rand(10, 26); s2.vy = rand(-8, 8);        blobs.splice(i, 1, s1, s2);      }    }    // keep population alive if everything merged into one    if (blobs.length < 3) {      const g2 = glassInterior();      blobs.push(spawnBlob(rand(g2.left + 24, g2.right - 24), rand(g2.top + 24, g2.bottom - 24)));    }  }  // ---------- drawing ----------  function glassPath(inflate) {    const { cx, glassTop, glassBottom, glassW } = lamp;    const w = glassW + (inflate || 0) * 2;    const left = cx - w / 2, right = cx + w / 2;    const top = glassTop - (inflate || 0);    const bottom = glassBottom + (inflate || 0);    const radius = w / 2;    ctx.beginPath();    ctx.moveTo(left, bottom - 6);    ctx.lineTo(left, top + radius);    ctx.arc(cx, top + radius, radius, Math.PI, 0, true);    ctx.lineTo(right, bottom - 6);    ctx.quadraticCurveTo(right, bottom, right - 6, bottom);    ctx.lineTo(left + 6, bottom);    ctx.quadraticCurveTo(left, bottom, left, bottom - 6);    ctx.closePath();  }  function lerp(a, b, t) { return a + (b - a) * t; }  function rgb(r, g, b) { return `rgb(${r|0},${g|0},${b|0})`; }  function drawBackground() {    // wall    const wallH = lamp.deskY;    const wallGrad = ctx.createLinearGradient(0, 0, 0, wallH);    const warm = glow;    wallGrad.addColorStop(0, rgb(lerp(24, 58, warm * 0.35), lerp(20, 34, warm * 0.35), lerp(30, 44, warm * 0.3)));    wallGrad.addColorStop(1, rgb(lerp(34, 84, warm * 0.45), lerp(28, 46, warm * 0.4), lerp(42, 52, warm * 0.3)));    ctx.fillStyle = wallGrad;    ctx.fillRect(0, 0, W, wallH);    // lamp glow on the wall    if (glow > 0.02) {      const glowR = lamp.unit * 0.95;      const lg = ctx.createRadialGradient(lamp.cx, lamp.glassTop + lamp.glassH * 0.35, 8, lamp.cx, lamp.glassTop + lamp.glassH * 0.35, glowR);      lg.addColorStop(0, `rgba(255,140,50,${0.34 * glow})`);      lg.addColorStop(0.55, `rgba(255,110,40,${0.12 * glow})`);      lg.addColorStop(1, "rgba(255,110,40,0)");      ctx.fillStyle = lg;      ctx.fillRect(0, 0, W, wallH);    }    // desk    const deskGrad = ctx.createLinearGradient(0, wallH, 0, H);    deskGrad.addColorStop(0, rgb(lerp(58, 82, warm * 0.3), lerp(42, 54, warm * 0.3), lerp(36, 40, warm * 0.3)));    deskGrad.addColorStop(1, rgb(lerp(26, 40, warm * 0.25), lerp(18, 26, warm * 0.25), lerp(18, 22, warm * 0.25)));    ctx.fillStyle = deskGrad;    ctx.fillRect(0, wallH, W, H - wallH);    // desk highlight line    ctx.fillStyle = `rgba(255,200,150,${0.10 + 0.12 * glow})`;    ctx.fillRect(0, wallH, W, 2);  }  function drawLampBase() {    const { cx, baseW, baseH, baseTop } = lamp;    const grad = ctx.createLinearGradient(cx - baseW / 2, 0, cx + baseW / 2, 0);    grad.addColorStop(0, "#241d2b");    grad.addColorStop(0.5, "#4a3d52");    grad.addColorStop(1, "#241d2b");    ctx.fillStyle = grad;    ctx.beginPath();    ctx.moveTo(cx - baseW / 2 + 6, baseTop);    ctx.lineTo(cx + baseW / 2 - 6, baseTop);    ctx.quadraticCurveTo(cx + baseW / 2, baseTop, cx + baseW / 2, baseTop + 10);    ctx.lineTo(cx + baseW / 2 - 8, baseTop + baseH - 6);    ctx.quadraticCurveTo(cx + baseW / 2 - 6, baseTop + baseH, cx + baseW / 2 - 14, baseTop + baseH);    ctx.lineTo(cx - baseW / 2 + 14, baseTop + baseH);    ctx.quadraticCurveTo(cx - baseW / 2 + 6, baseTop + baseH, cx - baseW / 2 + 8, baseTop + baseH - 6);    ctx.lineTo(cx - baseW / 2, baseTop + 10);    ctx.quadraticCurveTo(cx - baseW / 2, baseTop, cx - baseW / 2 + 6, baseTop);    ctx.closePath();    ctx.fill();    // base rim light from the lamp    ctx.fillStyle = `rgba(255,150,60,${0.45 * glow})`;    ctx.fillRect(cx - baseW / 2 + 8, baseTop + 3, baseW - 16, 3);    // feet shadow on desk    ctx.fillStyle = "rgba(0,0,0,0.35)";    ctx.beginPath();    ctx.ellipse(cx, baseTop + baseH + 4, baseW * 0.58, 6, 0, 0, Math.PI * 2);    ctx.fill();  }  function blobPath(b) {    const N = 12;    ctx.beginPath();    for (let i = 0; i <= N; i++) {      const a = (i / N) * Math.PI * 2;      const wobble = 1 + b.wobble * Math.sin(a * 3 + b.phase) + b.wobble * 0.5 * Math.sin(a * 5 - b.phase * 1.3);      const rr = b.r * wobble;      const px = b.x + Math.cos(a) * rr;      const py = b.y + Math.sin(a) * rr * 0.92;      if (i === 0) ctx.moveTo(px, py);      else {        // smooth curve through points        const pA = ((i - 1) / N) * Math.PI * 2;        const wobP = 1 + b.wobble * Math.sin(pA * 3 + b.phase) + b.wobble * 0.5 * Math.sin(pA * 5 - b.phase * 1.3);        const ppx = b.x + Math.cos(pA) * b.r * wobP;        const ppy = b.y + Math.sin(pA) * b.r * wobP * 0.92;        const mx = (ppx + px) / 2, my = (ppy + py) / 2;        ctx.quadraticCurveTo(ppx, ppy, mx, my);      }    }    ctx.closePath();  }  function drawBlob(b) {    const t = b.temp;               // 0..1    const lit = 0.25 + 0.75 * glow; // lamp lighting factor    const topC = [lerp(120, 255, t) * lit, lerp(60, 190, t) * lit, lerp(40, 60, t) * lit];    const botC = [lerp(70, 210, t) * lit, lerp(30, 70, t) * lit, lerp(45, 30, t) * lit];    const grad = ctx.createRadialGradient(b.x - b.r * 0.3, b.y - b.r * 0.35, b.r * 0.15, b.x, b.y, b.r * 1.15);    grad.addColorStop(0, rgb(topC[0], topC[1], topC[2]));    grad.addColorStop(1, rgb(botC[0], botC[1], botC[2]));    ctx.fillStyle = grad;    blobPath(b);    ctx.fill();    // inner shine    ctx.fillStyle = `rgba(255,235,200,${0.22 * lit * (0.4 + 0.6 * t)})`;    ctx.beginPath();    ctx.ellipse(b.x - b.r * 0.28, b.y - b.r * 0.38, b.r * 0.34, b.r * 0.2, -0.5, 0, Math.PI * 2);    ctx.fill();  }  function drawGlass() {    const { cx, glassW, glassTop, glassBottom, glassH } = lamp;    const w = glassW;    // glass fill (subtle tint)    glassPath(0);    ctx.fillStyle = "rgba(190,220,255,0.055)";    ctx.fill();    // left highlight stripe    ctx.save();    glassPath(0);    ctx.clip();    const hg = ctx.createLinearGradient(cx - w / 2, 0, cx + w / 2, 0);    hg.addColorStop(0, "rgba(255,255,255,0.20)");    hg.addColorStop(0.16, "rgba(255,255,255,0.05)");    hg.addColorStop(0.35, "rgba(255,255,255,0)");    hg.addColorStop(0.85, "rgba(255,255,255,0.06)");    hg.addColorStop(1, "rgba(255,255,255,0.16)");    ctx.fillStyle = hg;    ctx.fillRect(cx - w / 2, glassTop, w, glassH + 10);    ctx.restore();    // outline    glassPath(0);    ctx.strokeStyle = "rgba(230,240,255,0.35)";    ctx.lineWidth = 2;    ctx.stroke();    // top rim glow when on    if (glow > 0.02) {      ctx.save();      glassPath(0);      ctx.clip();      const botGlow = ctx.createRadialGradient(cx, glassBottom, 4, cx, glassBottom, glassH * 0.55);      botGlow.addColorStop(0, `rgba(255,150,60,${0.30 * glow})`);      botGlow.addColorStop(1, "rgba(255,150,60,0)");      ctx.fillStyle = botGlow;      ctx.fillRect(cx - w / 2, glassTop, w, glassH + 10);      ctx.restore();    }  }  function draw() {    ctx.clearRect(0, 0, W, H);    drawBackground();    drawLampBase();    // blobs clipped to glass interior    ctx.save();    glassPath(1);    ctx.clip();    // under-glow fill at bottom of glass    const g = glassInterior();    const fillG = ctx.createLinearGradient(0, g.top, 0, g.bottom);    fillG.addColorStop(0, `rgba(255,120,40,${0.02 + 0.05 * glow})`);    fillG.addColorStop(1, `rgba(255,120,40,${0.10 + 0.22 * glow})`);    ctx.fillStyle = fillG;    ctx.fillRect(g.left - 4, g.top - 4, g.right - g.left + 8, g.bottom - g.top + 8);    for (const b of blobs) drawBlob(b);    ctx.restore();    drawGlass();  }  // ---------- main loop ----------  function frame(ts) {    const dt = Math.min(0.033, last ? (ts - last) / 1000 : 0.016);    last = ts;    step(dt);    draw();    requestAnimationFrame(frame);  }  // ---------- boot ----------  function boot() {    resize();    initBlobs();    setLamp(true);    requestAnimationFrame(frame);  }  window.addEventListener("resize", resize);  window.addEventListener("orientationchange", () => setTimeout(resize, 120));  // wait one frame so CSS layout is settled before measuring  requestAnimationFrame(boot);})();</script></body></html>