Lava lamp v1 · OpenCode25.11.2026 12:33

Source Inkling 2 Mini, Medium effort

index.html · 16.4 KB · 488 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, viewport-fit=cover, user-scalable=no"><title>Lava Lamp</title><style>  * { margin: 0; padding: 0; box-sizing: border-box; }  html, body {    height: 100%;    overflow: hidden;    background: #0d0b16;    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;    -webkit-user-select: none;    user-select: none;    -webkit-tap-highlight-color: transparent;  }  #scene {    position: fixed;    inset: 0;    display: block;    touch-action: none;  }  #lamp-switch {    position: fixed;    left: 50%;    bottom: max(18px, env(safe-area-inset-bottom, 0px) + 14px);    transform: translateX(-50%);    width: 96px;    height: 44px;    border-radius: 22px;    border: 1px solid rgba(255,255,255,0.22);    background: linear-gradient(180deg, #2b2438 0%, #1b1626 100%);    cursor: pointer;    box-shadow: 0 4px 14px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.12);    display: flex;    align-items: center;    justify-content: space-between;    padding: 5px 10px;    z-index: 10;    touch-action: manipulation;  }  #lamp-switch .knob {    position: absolute;    top: 4px;    left: 4px;    width: 36px;    height: 36px;    border-radius: 50%;    background: linear-gradient(180deg, #e8e2f0 0%, #b9aec7 100%);    box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0 -2px 3px rgba(0,0,0,0.25);    transition: left 0.22s cubic-bezier(.6,.1,.3,1.3), background 0.22s;  }  #lamp-switch .label {    font-size: 11px;    letter-spacing: 0.14em;    font-weight: 700;    color: #8d829f;    transition: color 0.22s;  }  #lamp-switch .label.on { color: #ffd9a0; }  #lamp-switch .label.off { color: #6d6478; }  #lamp-switch[aria-pressed="true"] .knob { left: calc(100% - 40px); background: linear-gradient(180deg, #fff2d8 0%, #ffb84d 100%); box-shadow: 0 0 14px rgba(255,170,60,0.65), 0 2px 6px rgba(0,0,0,0.5); }  #lamp-switch[aria-pressed="true"] { box-shadow: 0 4px 14px rgba(0,0,0,0.55), 0 0 22px rgba(255,160,60,0.35), inset 0 1px 0 rgba(255,255,255,0.12); }</style></head><body><canvas id="scene"></canvas><button id="lamp-switch" aria-pressed="true" aria-label="Toggle lava lamp">  <span class="label on" id="lbl-on">ON</span>  <span class="label off" id="lbl-off">OFF</span>  <span class="knob"></span></button><script>(() => {  'use strict';  const canvas = document.getElementById('scene');  const ctx = canvas.getContext('2d');  const btn = document.getElementById('lamp-switch');  const lblOn = document.getElementById('lbl-on');  const lblOff = document.getElementById('lbl-off');  let W = 0, H = 0, DPR = 1;  let lamp = null; // layout object  function resize() {    DPR = Math.min(2, window.devicePixelRatio || 1);    W = window.innerWidth;    H = window.innerHeight;    canvas.width = Math.round(W * DPR);    canvas.height = Math.round(H * DPR);    canvas.style.width = W + 'px';    canvas.style.height = H + 'px';    ctx.setTransform(DPR, 0, 0, DPR, 0, 0);    computeLayout();    // dock the switch on the lamp base    btn.style.bottom = Math.max(8, H - (lamp.glassBottom - 4 + lamp.baseH / 2) - 22) + 'px';  }  function computeLayout() {    const baseW = Math.min(W * 0.62, 260);    const glassW = baseW * 0.82;    const glassH = Math.min(H * 0.66, 560);    const cx = W / 2;    const deskY = H * 0.90;                 // desk surface line    const glassBottom = deskY - H * 0.035;  // where glass meets base    const glassTop = glassBottom - glassH;    lamp = {      cx, baseW, glassW, glassH, glassTop, glassBottom, deskY,      baseH: H * 0.055,      maxHalf: glassW / 2,    };  }  // Half-width of the glass at t in [0,1] (0=top,1=bottom)  function halfW(t) {    const hw = lamp.maxHalf;    let f;    if (t < 0.14) {      f = lerp(0.44, 0.52, smooth(t / 0.14));    } else if (t < 0.30) {      f = lerp(0.52, 1.00, smooth((t - 0.14) / 0.16));    } else if (t < 0.74) {      f = 1.00;    } else {      f = lerp(1.00, 0.66, smooth((t - 0.74) / 0.26));    }    return hw * f;  }  function smooth(x) { x = Math.max(0, Math.min(1, x)); return x * x * (3 - 2 * x); }  function lerp(a, b, t) { return a + (b - a) * t; }  function rand(a, b) { return a + Math.random() * (b - a); }  function glassPath(inset) {    const p = new Path2D();    const steps = 40;    for (let i = 0; i <= steps; i++) {      const t = i / steps;      const y = lamp.glassTop + t * lamp.glassH;      const hw = Math.max(6, halfW(t) - (inset || 0));      const x = lamp.cx - hw;      if (i === 0) p.moveTo(x, y); else p.lineTo(x, y);    }    for (let i = steps; i >= 0; i--) {      const t = i / steps;      const y = lamp.glassTop + t * lamp.glassH;      const hw = Math.max(6, halfW(t) - (inset || 0));      const x = lamp.cx + hw;      p.lineTo(x, y);    }    p.closePath();    return p;  }  // ---------- state ----------  let lampOn = true;          // target state  let onFactor = 1;           // animated 0..1  const time = { t: 0 };  let blobs = [];  function spawnBlob(x, y, r, temp) {    return {      x, y, r,      vy: 0,      vx: rand(-6, 6),      temp: temp !== undefined ? temp : rand(0.2, 0.6),      phase: rand(0, Math.PI * 2),      wobble: rand(0.7, 1.3),    };  }  function initBlobs() {    blobs = [];    const n = 12;    for (let i = 0; i < n; i++) {      const t = (i + 0.5) / n;      const y = lamp.glassTop + t * lamp.glassH;      const hw = halfW(t) - 20;      blobs.push(spawnBlob(lamp.cx + rand(-hw * 0.5, hw * 0.5), y, rand(14, 24), rand(0.1, 0.9)));    }  }  function heatBias(t) {    // t: 0 top, 1 bottom — base heats the wax from below    return smooth((t - 0.18) / 0.62);  }  function update(dt) {    time.t += dt;    onFactor += ((lampOn ? 1 : 0) - onFactor) * Math.min(1, dt * 2.6);    const g = lamp;    for (const b of blobs) {      const tNorm = (b.y - g.glassTop) / g.glassH;      const targetTemp = onFactor * heatBias(tNorm);      b.temp += (targetTemp - b.temp) * Math.min(1, dt * 0.55);      // buoyancy: warm blob rises, cool blob sinks      const buoyancy = (b.temp - 0.38) * 95; // px/s upward when hot      b.vy += (-buoyancy - b.vy) * Math.min(1, dt * 2.1);      b.vx += Math.sin(time.t * 0.6 + b.phase) * dt * 10;      b.vx *= 1 - Math.min(1, dt * 1.6);      b.y += b.vy * dt;      b.x += b.vx * dt;      // keep inside glass      const tn = Math.max(0, Math.min(1, (b.y - g.glassTop) / g.glassH));      const hw = Math.max(4, halfW(tn) - b.r * 0.72);      const minY = g.glassTop + b.r * 0.72;      const maxY = g.glassBottom - b.r * 0.62;      if (b.y < minY) { b.y = minY; b.vy = Math.abs(b.vy) * 0.2; }      if (b.y > maxY) { b.y = maxY; b.vy = -Math.abs(b.vy) * 0.25; }      const dx = b.x - g.cx;      if (dx > hw) b.x = g.cx + hw;      else if (dx < -hw) b.x = g.cx - hw;      if (Math.abs(b.vx) > 30) b.vx *= 0.98;    }    // merge overlapping blobs    for (let i = 0; i < blobs.length; i++) {      for (let j = blobs.length - 1; j > i; j--) {        const a = blobs[i], c = blobs[j];        const dx = c.x - a.x, dy = c.y - a.y;        const d = Math.hypot(dx, dy);        const rr = (a.r + c.r) * 0.92;        if (d < rr) {          const tot = a.r * a.r + c.r * c.r;          const nr = Math.sqrt(tot);          const mx = (a.x * a.r * a.r + c.x * c.r * c.r) / tot;          const my = (a.y * a.r * a.r + c.y * c.r * c.r) / tot;          const nt = (a.temp * a.r * a.r + c.temp * c.r * c.r) / tot;          a.r = nr; a.x = mx; a.y = my; a.temp = nt;          a.vy = (a.vy + c.vy) * 0.5;          a.vx = (a.vx + c.vx) * 0.5;          a.phase = rand(0, Math.PI * 2);          blobs.splice(j, 1);        }      }    }    // split too-large blobs / keep a healthy population    const maxR = lamp.maxHalf * 0.62;    const out = [];    for (const b of blobs) {      if (b.r > maxR) {        const nr = Math.sqrt(b.r * b.r * 0.5);        const sign = Math.random() < 0.5 ? -1 : 1;        const b1 = spawnBlob(b.x - nr * 0.35, b.y - nr * 0.15, nr, b.temp);        const b2 = spawnBlob(b.x + nr * 0.35, b.y + nr * 0.15, nr, b.temp * rand(0.85, 1));        b1.vy = b.vy - 12; b2.vy = b.vy + 10;        b1.vx = -14 * sign; b2.vx = 14 * sign;        b1.phase = rand(0, 6.28); b2.phase = rand(0, 6.28);        out.push(b1, b2);      } else {        out.push(b);      }    }    blobs = out;    while (blobs.length < 10) {      // recover from merges by splitting a large blob      let biggest = blobs[0];      for (const b of blobs) if (b.r > biggest.r) biggest = b;      if (biggest.r < 15) break;      const nr = biggest.r * 0.72;      const b1 = spawnBlob(biggest.x + rand(-6, 6), biggest.y - nr * 0.2, nr, biggest.temp);      const b2 = spawnBlob(biggest.x + rand(-6, 6), biggest.y + nr * 0.2, nr, biggest.temp * rand(0.8, 1));      const sd = Math.random() < 0.5 ? -1 : 1;      b1.vx = -rand(8, 26) * sd; b1.vy = rand(-20, -8);      b2.vx = rand(8, 26) * sd;  b2.vy = rand(8, 20);      b1.phase = rand(0, 6.28); b2.phase = rand(0, 6.28);      const idx = blobs.indexOf(biggest);      blobs[idx] = b1;      blobs.push(b2);    }    if (blobs.length > 22) {      // compress if something got extreme: keep biggest 20      blobs.sort((a, b) => b.r - a.r);      blobs.length = 20;    }  }  // ---------- rendering ----------  function waxColor(temp) {    // cold dull red -> hot bright orange-yellow    const t = Math.max(0, Math.min(1, temp));    const r = Math.round(lerp(120, 255, t));    const g = Math.round(lerp(34, lerp(110, 175, t), t));    const b = Math.round(lerp(18, 26, t));    return [r, g, b];  }  function css(c, a) {    return `rgba(${c[0]},${c[1]},${c[2]},${a === undefined ? 1 : a})`;  }  function draw() {    const g = lamp;    ctx.clearRect(0, 0, W, H);    // wall background    let bg = ctx.createLinearGradient(0, 0, 0, H);    bg.addColorStop(0, '#151021');    bg.addColorStop(0.55, '#1d1628');    bg.addColorStop(1, '#0c0a13');    ctx.fillStyle = bg;    ctx.fillRect(0, 0, W, H);    // ambient glow behind lamp    const glowR = Math.max(W, H) * 0.62;    const glow = ctx.createRadialGradient(g.cx, g.glassTop + g.glassH * 0.55, 10, g.cx, g.glassTop + g.glassH * 0.55, glowR);    glow.addColorStop(0, `rgba(255,150,50,${0.34 * onFactor})`);    glow.addColorStop(0.4, `rgba(255,110,40,${0.16 * onFactor})`);    glow.addColorStop(1, 'rgba(255,110,40,0)');    ctx.fillStyle = glow;    ctx.fillRect(0, 0, W, H);    // desk    const deskGrad = ctx.createLinearGradient(0, g.deskY, 0, H);    deskGrad.addColorStop(0, '#241a2e');    deskGrad.addColorStop(0.12, '#1a1322');    deskGrad.addColorStop(1, '#0b0810');    ctx.fillStyle = deskGrad;    ctx.fillRect(0, g.deskY, W, H - g.deskY);    ctx.fillStyle = 'rgba(255,190,120,0.10)';    ctx.fillRect(0, g.deskY, W, 2);    // lamp shadow on desk    ctx.save();    ctx.translate(g.cx, g.deskY + 6);    ctx.scale(1, 0.22);    const sh = ctx.createRadialGradient(0, 0, 2, 0, 0, g.baseW * 0.78);    sh.addColorStop(0, `rgba(0,0,0,${0.55 - 0.18 * onFactor})`);    sh.addColorStop(1, 'rgba(0,0,0,0)');    ctx.fillStyle = sh;    ctx.beginPath();    ctx.arc(0, 0, g.baseW * 0.78, 0, Math.PI * 2);    ctx.fill();    ctx.restore();    // glass back    const back = ctx.createLinearGradient(g.cx - g.maxHalf, 0, g.cx + g.maxHalf, 0);    back.addColorStop(0, 'rgba(150,140,180,0.10)');    back.addColorStop(0.5, 'rgba(210,190,220,0.05)');    back.addColorStop(1, 'rgba(150,140,180,0.12)');    ctx.fillStyle = back;    ctx.fill(glassPath(2));    // blobs, clipped to glass    ctx.save();    ctx.clip(glassPath(4));    // interior warmth glow at bottom    if (onFactor > 0.01) {      const ig = ctx.createLinearGradient(0, g.glassBottom - g.glassH * 0.35, 0, g.glassBottom);      ig.addColorStop(0, 'rgba(255,120,30,0)');      ig.addColorStop(1, `rgba(255,120,30,${0.34 * onFactor})`);      ctx.fillStyle = ig;      ctx.fillRect(g.cx - g.maxHalf, g.glassBottom - g.glassH * 0.35, g.glassW, g.glassH * 0.35);    }    for (const b of blobs) {      drawBlob(b);    }    ctx.restore();    // glass front shading & highlights    const front = ctx.createLinearGradient(g.cx - g.maxHalf, 0, g.cx + g.maxHalf, 0);    front.addColorStop(0, 'rgba(255,255,255,0.16)');    front.addColorStop(0.12, 'rgba(255,255,255,0.03)');    front.addColorStop(0.5, 'rgba(255,255,255,0.0)');    front.addColorStop(0.85, 'rgba(255,255,255,0.04)');    front.addColorStop(1, 'rgba(255,255,255,0.14)');    ctx.fillStyle = front;    ctx.fill(glassPath(2));    // glass outline    ctx.strokeStyle = 'rgba(230,220,245,0.35)';    ctx.lineWidth = 1.6;    ctx.stroke(glassPath(1));    // left specular streak    ctx.save();    ctx.clip(glassPath(4));    const streak = ctx.createLinearGradient(g.cx - g.maxHalf, 0, g.cx - g.maxHalf * 0.3, 0);    streak.addColorStop(0, 'rgba(255,255,255,0.22)');    streak.addColorStop(1, 'rgba(255,255,255,0)');    ctx.fillStyle = streak;    ctx.fillRect(g.cx - g.maxHalf * 0.92, g.glassTop + 6, g.maxHalf * 0.5, g.glassH - 12);    ctx.restore();    // neck cap    const neckW = halfW(0) * 2;    ctx.fillStyle = '#171221';    roundRect(g.cx - neckW / 2 - 7, g.glassTop - 14, neckW + 14, 16, 6);    ctx.fill();    ctx.fillStyle = 'rgba(255,255,255,0.10)';    roundRect(g.cx - neckW / 2 - 7, g.glassTop - 14, neckW + 14, 5, 4);    ctx.fill();    // base    const baseY = g.glassBottom - 4;    const baseGrad = ctx.createLinearGradient(0, baseY, 0, baseY + g.baseH);    baseGrad.addColorStop(0, '#3a3049');    baseGrad.addColorStop(0.35, '#221b2e');    baseGrad.addColorStop(1, '#120e1a');    ctx.fillStyle = baseGrad;    roundRect(g.cx - g.baseW / 2, baseY, g.baseW, g.baseH, 10);    ctx.fill();    ctx.strokeStyle = 'rgba(255,255,255,0.14)';    ctx.lineWidth = 1;    roundRect(g.cx - g.baseW / 2, baseY, g.baseW, g.baseH, 10);    ctx.stroke();    ctx.fillStyle = `rgba(255,190,110,${0.55 * onFactor})`;    roundRect(g.cx - g.baseW / 2 + 10, baseY + 4, g.baseW - 20, 3, 2);    ctx.fill();  }  function drawBlob(b) {    const pts = 16;    const [r, gg, bb] = waxColor(b.temp);    const wob = b.wobble * 0.06;    ctx.beginPath();    for (let i = 0; i <= pts; i++) {      const a = (i / pts) * Math.PI * 2;      const rad = b.r * (1 + Math.sin(a * 3 + time.t * 2.2 + b.phase) * wob + Math.sin(a * 5 - time.t * 1.4 + b.phase * 2) * wob * 0.5);      const x = b.x + Math.cos(a) * rad;      const y = b.y + Math.sin(a) * rad * 0.94;      if (i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y);    }    ctx.closePath();    const grad = ctx.createRadialGradient(b.x - b.r * 0.25, b.y - b.r * 0.3, b.r * 0.1, b.x, b.y, b.r * 1.15);    grad.addColorStop(0, css([Math.min(255, r + 55), Math.min(255, gg + 45), bb + 10]));    grad.addColorStop(0.55, css([r, gg, bb]));    grad.addColorStop(1, css([Math.max(0, r - 45), Math.max(0, gg - 18), Math.max(0, bb - 6)]));    ctx.fillStyle = grad;    ctx.fill();    // specular    ctx.fillStyle = `rgba(255,235,210,${0.28 + 0.22 * b.temp})`;    ctx.beginPath();    ctx.ellipse(b.x - b.r * 0.34, b.y - b.r * 0.4, b.r * 0.26, b.r * 0.14, -0.6, 0, Math.PI * 2);    ctx.fill();  }  function roundRect(x, y, w, h, r) {    ctx.beginPath();    ctx.moveTo(x + r, y);    ctx.arcTo(x + w, y, x + w, y + h, r);    ctx.arcTo(x + w, y + h, x, y + h, r);    ctx.arcTo(x, y + h, x, y, r);    ctx.arcTo(x, y, x + w, y, r);    ctx.closePath();  }  // ---------- loop ----------  let last = performance.now();  function frame(now) {    let dt = (now - last) / 1000;    last = now;    if (dt > 0.05) dt = 0.05;    update(dt);    draw();    requestAnimationFrame(frame);  }  // ---------- events ----------  btn.addEventListener('click', () => {    lampOn = !lampOn;    btn.setAttribute('aria-pressed', String(lampOn));    lblOn.style.opacity = lampOn ? '1' : '0.45';    lblOff.style.opacity = lampOn ? '0.45' : '1';  });  window.addEventListener('resize', resize);  window.addEventListener('orientationchange', () => setTimeout(resize, 60));  resize();  initBlobs();  btn.setAttribute('aria-pressed', 'true');  lblOn.style.opacity = '1';  lblOff.style.opacity = '0.45';  requestAnimationFrame(frame);})();</script></body></html>