Lava lamp v1 · OpenCode25.11.2026 11:54

Source Inkling 2 Mini, Medium effort

index.html · 15.8 KB · 502 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" /><title>Lava Lamp</title><style>  :root { color-scheme: dark; }  * { margin: 0; padding: 0; box-sizing: border-box; }  html, body {    height: 100%;    overflow: hidden;    background: #14101d;    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;    -webkit-user-select: none;    user-select: none;    touch-action: manipulation;  }  #stage {    position: fixed;    inset: 0;  }  canvas {    display: block;    width: 100%;    height: 100%;  }  #switch-wrap {    position: fixed;    right: max(18px, env(safe-area-inset-right));    bottom: max(88px, env(safe-area-inset-bottom));    display: flex;    flex-direction: column;    align-items: center;    gap: 8px;    z-index: 10;  }  #switch-label {    font-size: 11px;    letter-spacing: 0.22em;    color: #e9d8ff;    opacity: 0.75;    text-shadow: 0 1px 2px rgba(0,0,0,0.6);    font-weight: 700;  }  #lamp-switch {    width: 58px;    height: 88px;    border-radius: 12px;    border: 2px solid #3a2f4d;    background: linear-gradient(180deg, #241c33, #171221);    box-shadow:      inset 0 2px 6px rgba(0,0,0,0.75),      0 4px 10px rgba(0,0,0,0.55);    cursor: pointer;    position: relative;    padding: 0;    -webkit-tap-highlight-color: transparent;  }  #lamp-switch .rocker {    position: absolute;    left: 6px; right: 6px;    top: 6px;    height: 38px;    border-radius: 8px;    background: linear-gradient(180deg, #f5d76e 0%, #e8a33d 55%, #c96a1e 100%);    box-shadow:      inset 0 2px 3px rgba(255,255,255,0.55),      inset 0 -3px 4px rgba(90,40,0,0.55),      0 2px 4px rgba(0,0,0,0.5);    transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;    transform: translateY(0);  }  #lamp-switch[aria-pressed="false"] .rocker {    transform: translateY(36px);    background: linear-gradient(180deg, #6d6478 0%, #4b4258 55%, #332b40 100%);    box-shadow:      inset 0 2px 3px rgba(255,255,255,0.25),      inset 0 -3px 4px rgba(0,0,0,0.6),      0 2px 4px rgba(0,0,0,0.5);  }  #lamp-switch:focus-visible {    outline: 2px solid #ffd76e;    outline-offset: 3px;  }  .glow-dot {    position: absolute;    top: 8px;    left: 50%;    width: 8px;    height: 8px;    border-radius: 50%;    transform: translateX(-50%);    background: #3a3345;    transition: background 0.25s ease, box-shadow 0.25s ease;  }  #lamp-switch[aria-pressed="true"] .glow-dot {    background: #ffe08a;    box-shadow: 0 0 10px 2px rgba(255, 214, 110, 0.85);  }</style></head><body><div id="stage"><canvas id="cv"></canvas></div><div id="switch-wrap">  <div id="switch-label">LAMP</div>  <button id="lamp-switch" aria-pressed="true" aria-label="Toggle lava lamp">    <span class="glow-dot"></span>    <span class="rocker"></span>  </button></div><script>(() => {  "use strict";  const canvas = document.getElementById("cv");  const ctx = canvas.getContext("2d");  const sw = document.getElementById("lamp-switch");  let W = 0, H = 0, DPR = 1;  let deskY = 0, lamp = null;  function resize() {    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);    canvas.style.width = W + "px";    canvas.style.height = H + "px";    ctx.setTransform(DPR, 0, 0, DPR, 0, 0);    deskY = H * 0.78;    const baseH = Math.min(74, H * 0.10);    const baseW = Math.min(W * 0.52, 240);    const tubeHalfW = Math.min(W * 0.20, 92);    const tubeTop = H * 0.10;    const tubeBottom = deskY - baseH * 0.55;    lamp = {      cx: W * 0.42,                 // lamp center x (switchd right side)      baseY: deskY,      baseW, baseH,      tubeHalfW,      tubeTop,      tubeBottom,      neckTop: tubeTop + (tubeBottom - tubeTop) * 0.06,    };    // keep blobs inside new bounds    if (blobs) {      for (const b of blobs) {        b.x = clamp(b.x, lamp.cx - tubeHalfW + b.r * 0.7, lamp.cx + tubeHalfW - b.r * 0.7);        b.y = clamp(b.y, tubeTop + b.r * 0.7, tubeBottom - b.r * 0.7);      }    }  }  const clamp = (v, a, b) => Math.max(a, Math.min(b, v));  const lerp = (a, b, t) => a + (b - a) * t;  const rand = (a, b) => a + Math.random() * (b - a);  // ---------- blobs ----------  let blobs = [];  let lampOn = true;  function maxR() { return Math.min(56, Math.min(W, H) * 0.085); }  function minR() { return maxR() * 0.34; }  function newBlob(x, y, r, w) {    return {      x, y, r,      w: w,                 // warmth 0..1      vy: 0,      vx: rand(-6, 6),      phase: rand(0, Math.PI * 2),      wobble: rand(0.8, 1.4),      id: Math.random(),    };  }  function seedBlobs() {    blobs = [];    const n = 9;    for (let i = 0; i < n; i++) {      const y = rand(lamp.tubeTop + 30, lamp.tubeBottom - 30);      const r = rand(minR(), maxR() * 0.85);      const x = rand(lamp.cx - lamp.tubeHalfW + r, lamp.cx + lamp.tubeHalfW - r);      blobs.push(newBlob(x, y, r, rand(0.2, 0.95)));    }  }  function init() {    resize();    seedBlobs();  }  // colors  function lerpColor(c1, c2, t) {    return [      Math.round(lerp(c1[0], c2[0], t)),      Math.round(lerp(c1[1], c2[1], t)),      Math.round(lerp(c1[2], c2[2], t)),    ];  }  const rgb = c => `rgb(${c[0]},${c[1]},${c[2]})`;  const rgba = (c, a) => `rgba(${c[0]},${c[1]},${c[2]},${a})`;  const COOL_CORE = [178, 34, 74];   // cool deep red/pink  const WARM_CORE = [255, 226, 128]; // warm yellow  const COOL_MID  = [122, 22, 52];  const WARM_MID  = [255, 138, 40];  function drawBlob(b, time) {    const wob = Math.sin(time * 1.7 * b.wobble + b.phase);    const r = b.r * (1 + 0.06 * wob);    const core = lerpColor(COOL_CORE, WARM_CORE, b.w);    const mid  = lerpColor(COOL_MID, WARM_MID, b.w);    const g = ctx.createRadialGradient(      b.x - r * 0.25, b.y - r * 0.3, r * 0.1,      b.x, b.y, r    );    g.addColorStop(0, rgba(core, 0.98));    g.addColorStop(0.55, rgba(lerpColor(mid, core, 0.35), 0.96));    g.addColorStop(1, rgba(mid, 0.0));    ctx.fillStyle = g;    ctx.beginPath();    ctx.arc(b.x, b.y, r, 0, Math.PI * 2);    ctx.fill();    // highlight    ctx.fillStyle = `rgba(255,255,255,${0.18 + 0.22 * b.w})`;    ctx.beginPath();    ctx.ellipse(b.x - r * 0.32, b.y - r * 0.38, r * 0.26, r * 0.16, -0.6, 0, Math.PI * 2);    ctx.fill();  }  function step(dt, time) {    const tubeH = lamp.tubeBottom - lamp.tubeTop;    const heatZoneBottom = lamp.tubeBottom - tubeH * 0.34;    for (const b of blobs) {      // heating / cooling      if (lampOn) {        if (b.y > heatZoneBottom) b.w = clamp(b.w + dt * 0.55, 0, 1);        else b.w = clamp(b.w - dt * 0.16, 0, 1);      } else {        b.w = clamp(b.w - dt * 0.22, 0, 1);      }      // buoyancy: warm rises, cool sinks      const targetVy = (0.5 - b.w) * (Math.min(W, H) * 0.11);      b.vy += (targetVy - b.vy) * Math.min(1, dt * 1.6);      // gentle horizontal wander      b.vx += Math.sin(time * 0.9 * b.wobble + b.phase) * dt * 26;      b.vx *= (1 - Math.min(1, dt * 1.4));      b.vy *= (1 - Math.min(1, dt * 0.35));      b.x += b.vx * dt;      b.y += b.vy * dt;      // walls      const halfW = lamp.tubeHalfW - b.r * 0.42;      const left = lamp.cx - halfW, right = lamp.cx + halfW;      if (b.x < left) { b.x = left; b.vx = Math.abs(b.vx) * 0.7; }      if (b.x > right) { b.x = right; b.vx = -Math.abs(b.vx) * 0.7; }      // floor / ceiling      const top = lamp.tubeTop + b.r * 0.5;      const bot = lamp.tubeBottom - b.r * 0.28;      if (b.y < top) { b.y = top; b.vy = Math.abs(b.vy) * 0.6; }      if (b.y > bot) { b.y = bot; b.vy = -Math.abs(b.vy) * 0.5; }    }    // merge + split    const mr = maxR();    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 = b.x - a.x, dy = b.y - a.y;        const d = Math.hypot(dx, dy);        const rr = (a.r + b.r) * 0.74;        if (d < rr) {          const areaA = Math.PI * a.r * a.r, areaB = Math.PI * b.r * b.r;          const total = areaA + areaB;          const nr = Math.sqrt(total / Math.PI);          const nw = (a.w * areaA + b.w * areaB) / total;          const nx = (a.x * areaA + b.x * areaB) / total;          const ny = (a.y * areaA + b.y * areaB) / total;          const nvy = (a.vy * areaA + b.vy * areaB) / total;          const nvx = (a.vx * areaA + b.vx * areaB) / total;          blobs[i] = newBlob(nx, ny, nr, nw);          blobs[i].vy = nvy;          blobs[i].vx = nvx;          blobs.splice(j, 1);          j--;        }      }    }    // split big blobs    const toSplit = blobs.filter(b => b.r > mr);    for (const b of toSplit) {      const nr = Math.sqrt((b.r * b.r) / 2);      const ang = rand(0, Math.PI * 2);      const off = nr * 0.55;      const p1 = newBlob(b.x + Math.cos(ang) * off, b.y + Math.sin(ang) * off, nr, clamp(b.w + rand(-0.08, 0.08), 0, 1));      const p2 = newBlob(b.x - Math.cos(ang) * off, b.y - Math.sin(ang) * off, nr, clamp(b.w + rand(-0.08, 0.08), 0, 1));      p1.vy = b.vy * 0.6 - 30;      p2.vy = b.vy * 0.6 + 30;      blobs.push(p1, p2);      const idx = blobs.indexOf(b);      if (idx >= 0) blobs.splice(idx, 1);    }    // maintain a healthy population    while (blobs.length < 6) {      const r = rand(minR(), maxR() * 0.7);      const y = rand(lamp.tubeTop + 30, lamp.tubeBottom - 30);      const x = rand(lamp.cx - lamp.tubeHalfW + r, lamp.cx + lamp.tubeHalfW - r);      blobs.push(newBlob(x, y, r, lampOn ? rand(0.35, 0.95) : rand(0.05, 0.3)));    }  }  // ---------- drawing ----------  function draw(time) {    ctx.clearRect(0, 0, W, H);    // wall background    const wall = ctx.createLinearGradient(0, 0, 0, deskY);    wall.addColorStop(0, "#221a30");    wall.addColorStop(1, "#171221");    ctx.fillStyle = wall;    ctx.fillRect(0, 0, W, deskY);    // average warmth for ambient glow    let avgW = 0;    for (const b of blobs) avgW += b.w;    avgW = blobs.length ? avgW / blobs.length : 0;    // ambient glow behind lamp    if (avgW > 0.02) {      const flick = 1 + Math.sin(time * 7.3) * 0.02 + Math.sin(time * 13.7) * 0.015;      const gr = Math.min(W, H) * 0.62 * flick;      const glow = ctx.createRadialGradient(lamp.cx, (lamp.tubeTop + lamp.tubeBottom) / 2, 10,                                            lamp.cx, (lamp.tubeTop + lamp.tubeBottom) / 2, gr);      glow.addColorStop(0, `rgba(255,150,50,${0.34 * avgW})`);      glow.addColorStop(0.6, `rgba(220,80,30,${0.16 * avgW})`);      glow.addColorStop(1, "rgba(220,80,30,0)");      ctx.fillStyle = glow;      ctx.fillRect(0, 0, W, deskY);    }    // desk    const desk = ctx.createLinearGradient(0, deskY, 0, H);    desk.addColorStop(0, "#6b4a2f");    desk.addColorStop(0.12, "#553823");    desk.addColorStop(1, "#2c1d12");    ctx.fillStyle = desk;    ctx.fillRect(0, deskY, W, H - deskY);    ctx.fillStyle = "rgba(255,220,170,0.14)";    ctx.fillRect(0, deskY, W, 2);    // plank lines    ctx.strokeStyle = "rgba(0,0,0,0.22)";    ctx.lineWidth = 1.5;    for (let i = 1; i < 4; i++) {      const y = deskY + (H - deskY) * (i / 4);      ctx.beginPath();      ctx.moveTo(0, y);      ctx.lineTo(W, y);      ctx.stroke();    }    // shadow on desk    ctx.fillStyle = "rgba(0,0,0,0.45)";    ctx.beginPath();    ctx.ellipse(lamp.cx, lamp.baseY + 6, lamp.baseW * 0.62, 12, 0, 0, Math.PI * 2);    ctx.fill();    // ---- lamp base ----    const bw = lamp.baseW, bh = lamp.baseH;    const bx = lamp.cx - bw / 2, by = lamp.baseY - bh;    const baseGrad = ctx.createLinearGradient(bx, 0, bx + bw, 0);    baseGrad.addColorStop(0, "#2c2438");    baseGrad.addColorStop(0.5, "#4a3f5c");    baseGrad.addColorStop(1, "#241d31");    ctx.fillStyle = baseGrad;    roundRect(bx, by, bw, bh, 10);    ctx.fill();    ctx.fillStyle = "rgba(255,255,255,0.10)";    roundRect(bx + 6, by + 4, bw - 12, bh * 0.22, 6);    ctx.fill();    // base emblem dot    ctx.fillStyle = lampOn ? "#ffd76e" : "#4a4257";    ctx.beginPath();    ctx.arc(lamp.cx, by + bh * 0.62, 4, 0, Math.PI * 2);    ctx.fill();    // ---- tube ----    const tW = lamp.tubeHalfW;    const tTop = lamp.tubeTop, tBot = lamp.tubeBottom;    // wax interior    const waxGrad = ctx.createLinearGradient(0, tTop, 0, tBot);    const waxTop   = lerpColor([58, 22, 44], [120, 26, 60], avgW);    const waxMid   = lerpColor([92, 30, 30], [230, 70, 32], avgW);    const waxBottom= lerpColor([130, 44, 22], [255, 158, 44], avgW);    waxGrad.addColorStop(0, rgb(waxTop));    waxGrad.addColorStop(0.55, rgb(waxMid));    waxGrad.addColorStop(1, rgb(waxBottom));    ctx.fillStyle = waxGrad;    roundRect(lamp.cx - tW, tTop, tW * 2, tBot - tTop, 26);    ctx.fill();    // wax blobs (clipped to tube)    ctx.save();    roundRect(lamp.cx - tW + 3, tTop + 3, tW * 2 - 6, tBot - tTop - 6, 22);    ctx.clip();    for (const b of blobs) drawBlob(b, time);    // subtle top-down cool shading inside wax    const shade = ctx.createLinearGradient(0, tTop, 0, tBot);    shade.addColorStop(0, "rgba(20,8,20,0.35)");    shade.addColorStop(0.35, "rgba(20,8,20,0)");    shade.addColorStop(1, "rgba(0,0,0,0.22)");    ctx.fillStyle = shade;    ctx.fillRect(lamp.cx - tW, tTop, tW * 2, tBot - tTop);    ctx.restore();    // glass tube outline    ctx.strokeStyle = "rgba(225,235,255,0.35)";    ctx.lineWidth = 2;    roundRect(lamp.cx - tW, tTop, tW * 2, tBot - tTop, 26);    ctx.stroke();    // glass highlight    ctx.fillStyle = "rgba(255,255,255,0.20)";    ctx.beginPath();    ctx.roundRect(lamp.cx - tW + 8, tTop + 14, 7, (tBot - tTop) * 0.6, 4);    ctx.fill();    ctx.fillStyle = "rgba(255,255,255,0.10)";    ctx.beginPath();    ctx.roundRect(lamp.cx + tW - 16, tTop + 20, 5, (tBot - tTop) * 0.45, 3);    ctx.fill();    // neck band over tube base    ctx.fillStyle = "#241d31";    roundRect(lamp.cx - tW - 4, tBot - 6, tW * 2 + 8, 12, 5);    ctx.fill();    ctx.fillStyle = "rgba(255,255,255,0.08)";    roundRect(lamp.cx - tW - 4, tBot - 6, tW * 2 + 8, 4, 2);    ctx.fill();  }  function roundRect(x, y, w, h, r) {    const rr = Math.min(r, w / 2, h / 2);    ctx.beginPath();    ctx.moveTo(x + rr, y);    ctx.arcTo(x + w, y, x + w, y + h, rr);    ctx.arcTo(x + w, y + h, x, y + h, rr);    ctx.arcTo(x, y + h, x, y, rr);    ctx.arcTo(x, y, x + w, y, rr);    ctx.closePath();  }  // ---------- loop ----------  let last = performance.now();  let time = 0;  function frame(now) {    const dt = Math.min(0.033, (now - last) / 1000);    last = now;    time += dt;    step(dt, time);    draw(time);    requestAnimationFrame(frame);  }  // ---------- switch ----------  function setLamp(on) {    lampOn = on;    sw.setAttribute("aria-pressed", String(on));  }  sw.addEventListener("click", () => setLamp(!lampOn));  // use roundRect polyfill fallback for CanvasRenderingContext2D  if (!CanvasRenderingContext2D.prototype.roundRect) {    CanvasRenderingContext2D.prototype.roundRect = function (x, y, w, h, r) {      const rr = Math.min(r, w / 2, h / 2);      this.moveTo(x + rr, y);      this.arcTo(x + w, y, x + w, y + h, rr);      this.arcTo(x + w, y + h, x, y + h, rr);      this.arcTo(x, y + h, x, y, rr);      this.arcTo(x, y, x + w, y, rr);      this.closePath();      return this;    };  }  window.addEventListener("resize", resize);  init();  requestAnimationFrame(frame);})();</script></body></html>