Lava lamp v1 · Claude Code25.11.2026 12:39

Source Inkling 2 Mini, Medium effort

index.html · 18.9 KB · 582 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"><title>Lava Lamp</title><style>  :root {    --on: #ff9a3c;    --on-glow: rgba(255, 138, 50, 0.55);    --off-track: #2a2b36;  }  * { box-sizing: border-box; }  html, body {    margin: 0;    height: 100%;    overflow: hidden;    background: #0d0e14;    overscroll-behavior: none;    -webkit-user-select: none;    user-select: none;    -webkit-tap-highlight-color: transparent;  }  #scene {    position: fixed;    inset: 0;    width: 100vw;    height: 100vh;    height: 100dvh;    display: block;    touch-action: none;  }  #switch {    position: fixed;    left: 50%;    bottom: max(18px, env(safe-area-inset-bottom));    transform: translateX(-50%);    display: flex;    align-items: center;    gap: 10px;    padding: 9px 16px 9px 10px;    border-radius: 999px;    border: 1px solid rgba(255,255,255,0.09);    background: rgba(20,20,28,0.72);    backdrop-filter: blur(6px);    -webkit-backdrop-filter: blur(6px);    box-shadow: 0 6px 22px rgba(0,0,0,0.5);    cursor: pointer;    font: 600 12px/1 -apple-system, system-ui, "Segoe UI", sans-serif;    letter-spacing: 0.08em;    text-transform: uppercase;    color: #d8d3c8;    touch-action: manipulation;    z-index: 2;    -webkit-appearance: none;    appearance: none;  }  #switch:focus-visible {    outline: 2px solid var(--on);    outline-offset: 3px;  }  .track {    position: relative;    width: 58px;    height: 30px;    border-radius: 999px;    background: var(--off-track);    border: 1px solid rgba(255,255,255,0.08);    transition: background 0.3s ease, box-shadow 0.3s ease;    flex: none;  }  .knob {    position: absolute;    top: 2px;    left: 2px;    width: 24px;    height: 24px;    border-radius: 50%;    background: linear-gradient(180deg, #f4f1ea, #c9c4b8);    box-shadow: 0 2px 5px rgba(0,0,0,0.55);    transition: transform 0.28s cubic-bezier(0.34, 1.45, 0.64, 1);  }  #switch[aria-checked="true"] .track {    background: linear-gradient(180deg, #ff7a1e, #e8550a);    box-shadow: 0 0 14px var(--on-glow), inset 0 1px 2px rgba(255,255,255,0.35);  }  #switch[aria-checked="true"] .knob { transform: translateX(28px); }  #label { min-width: 34px; text-align: left; transition: color 0.3s ease; }  #switch[aria-checked="true"] #label { color: #ffc98f; }</style></head><body><canvas id="scene"></canvas><button id="switch" role="switch" aria-checked="true" aria-label="Toggle lamp">  <span class="track"><span class="knob"></span></span>  <span id="label">On</span></button><script>(function () {  'use strict';  var canvas = document.getElementById('scene');  var ctx = canvas.getContext('2d', { alpha: false });  var btn = document.getElementById('switch');  var label = document.getElementById('label');  var W = 0, H = 0, dpr = 1;  var tube = { x: 0, y: 0, w: 0, h: 0, r: 0 };   // glass tube  var base = { x: 0, y: 0, w: 0, h: 0 };          // lamp base  var cap  = { x: 0, y: 0, w: 0, h: 0 };          // top cap  var deskY = 0;                                   // desk top line  var LAMP_ON = true;  var light = 1;          // eased 0..1 glow intensity  var time = 0;  // ---------- helpers ----------  function rand(a, b) { return a + Math.random() * (b - a); }  function clamp(v, a, b) { return v < a ? a : (v > b ? b : v); }  function lerp(a, b, t) { return a + (b - a) * t; }  // ---------- blobs ----------  var blobs = [];  var BASE_R_FRAC = 0.16;   // radius as fraction of tube width  var MAX_R_FRAC = 0.40;    // splitting threshold (fraction of tube width)  function makeBlob(nx, ny, rFrac) {    return {      x: tube.x + tube.w * nx,      y: tube.y + tube.h * ny,      r: tube.w * rFrac,      vx: rand(-14, 14),      vy: rand(-8, 8),      temp: rand(0.3, 0.9),      phase: rand(0, Math.PI * 2),      wob: rand(2.2, 3.6),      cool: 0    };  }  function seedBlobs() {    blobs.length = 0;    var n = 9;    for (var i = 0; i < n; i++) {      blobs.push(makeBlob(        0.20 + 0.60 * (i / (n - 1)) + rand(-0.04, 0.04),        rand(0.2, 0.85),        BASE_R_FRAC * rand(0.8, 1.25)      ));    }  }  function resize() {    var oldTube = { x: tube.x, y: tube.y, w: tube.w, h: tube.h };    var hadGeom = tube.w > 0;    dpr = Math.min(window.devicePixelRatio || 1, 1.75);    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);    // layout (responsive, phone-first)    deskY = H * 0.76;    tube.w = clamp(W * 0.44, 96, 210);    tube.h = clamp(H * 0.50, 190, 430);    tube.r = tube.w / 2;    base.w = tube.w * 1.55;    base.h = clamp(H * 0.085, 46, 78);    base.x = W / 2 - base.w / 2;    base.y = deskY - base.h;              // base sits on the desk    tube.y = base.y + base.h * 0.22 - tube.h;   // tube rises from inside the base    tube.x = W / 2 - tube.w / 2;    cap.w = tube.w * 0.52;    cap.h = clamp(H * 0.022, 12, 20);    cap.x = W / 2 - cap.w / 2;    cap.y = tube.y - cap.h * 1.05;    // rescale existing blobs into new geometry    if (blobs.length) {      for (var i = 0; i < blobs.length; i++) {        var b = blobs[i];        if (hadGeom) {          var nx = clamp((b.x - oldTube.x) / oldTube.w, 0, 1);          var ny = clamp((b.y - oldTube.y) / oldTube.h, 0, 1);          var nr = clamp(b.r / oldTube.w, 0.08, MAX_R_FRAC);          b.x = tube.x + tube.w * nx;          b.y = tube.y + tube.h * ny;          b.r = tube.w * nr;        } else {          b.r = tube.w * BASE_R_FRAC;        }      }    }  }  // ---------- simulation ----------  function updateBlob(b, dt) {    var ny = (b.y - tube.y) / tube.h;           // 0 top .. 1 bottom    var target = LAMP_ON ? lerp(0.12, 1.0, ny * ny * 0.9 + ny * 0.1) : 0.16;    b.temp += (target - b.temp) * Math.min(1, dt * (LAMP_ON ? 1.6 : 1.0));    // buoyancy: warmer than ambient => rises    var buoy = (b.temp - 0.42) * 300;           // px/s^2    b.vy += (-buoy) * dt;                         // canvas y down: positive buoy => upward    b.vy += Math.sin(time * 1.7 + b.phase) * 6 * dt;   // gentle horizontal wander    b.vx += Math.sin(time * b.wob + b.phase) * 26 * dt;    b.vx *= (1 - Math.min(1, dt * 2.2));    b.vy *= (1 - Math.min(1, dt * 1.9));    b.vx = clamp(b.vx, -90, 90);    b.vy = clamp(b.vy, -240, 240);    b.x += b.vx * dt;    b.y += b.vy * dt;    // soft walls    var left = tube.x + 4 + b.r * 0.75;    var right = tube.x + tube.w - 4 - b.r * 0.75;    if (b.x < left) { b.x = left; b.vx = Math.abs(b.vx) * 0.55; }    if (b.x > right) { b.x = right; b.vx = -Math.abs(b.vx) * 0.55; }    // floor/ceiling (rounded ends: allow slight squish)    var top = tube.y + 3 + b.r * 0.7;    var floor = tube.y + tube.h - 3 - b.r * 0.7;    if (b.y < top) { b.y = top; b.vy = Math.abs(b.vy) * 0.4; }    if (b.y > floor) { b.y = floor; b.vy = -Math.abs(b.vy) * 0.35; }    if (b.cool > 0) b.cool -= dt;  }  function mass(b) { return b.r * b.r; }  function mergePair(a, b) {    var m = mass(a) + mass(b);    var nx = (a.x * mass(a) + b.x * mass(b)) / m;    var ny = (a.y * mass(a) + b.y * mass(b)) / m;    var nvx = (a.vx * mass(a) + b.vx * mass(b)) / m;    var nvy = (a.vy * mass(a) + b.vy * mass(b)) / m;    var ntemp = (a.temp * mass(a) + b.temp * mass(b)) / m;    var r = Math.sqrt(m);    var merged = {      x: nx, y: ny, r: r,      vx: nvx, vy: nvy, temp: ntemp,      phase: rand(0, Math.PI * 2),      wob: rand(2.2, 3.6),      cool: 0.55    };    return merged;  }  function splitBlob(b) {    // split one blob into two halves, preserving total area    var newR = b.r / Math.SQRT2;    var ang = Math.atan2(b.vy, b.vx || 0.01);    var off = newR * 0.95;    var ux = Math.cos(ang + Math.PI / 2), uy = Math.sin(ang + Math.PI / 2);    var c = { x: b.x + ux * off, y: b.y + uy * off, r: newR };    var d = { x: b.x - ux * off, y: b.y - uy * off, r: newR };    // nudge apart and split velocities    var s = clamp(b.vy * 0.6, -60, 60);    c.vx = clamp(b.vx - uy * s * 0.4 + rand(-18, 18), -120, 120);    c.vy = clamp(b.vy + ux * s * 0.4 + rand(-18, 18), -120, 120);    d.vx = clamp(b.vx + uy * s * 0.4 + rand(-18, 18), -120, 120);    d.vy = clamp(b.vy - ux * s * 0.4 + rand(-18, 18), -120, 120);    var kids = [      { x: c.x, y: c.y, r: c.r, vx: c.vx, vy: c.vy, temp: clamp(b.temp + rand(-0.15, 0.15), 0.1, 1), phase: rand(0, Math.PI * 2), wob: rand(2.2, 3.6), cool: 0.8 },      { x: d.x, y: d.y, r: d.r, vx: d.vx, vy: d.vy, temp: clamp(b.temp + rand(-0.15, 0.15), 0.1, 1), phase: rand(0, Math.PI * 2), wob: rand(2.2, 3.6), cool: 0.8 }    ];    return kids;  }  function resolveCollisions() {    var i, j;    for (i = 0; i < blobs.length; i++) {      var a = blobs[i];      if (a.cool > 0) continue;      for (j = i + 1; j < blobs.length; j++) {        var b = blobs[j];        if (b.cool > 0) continue;        var dx = b.x - a.x, dy = b.y - a.y;        var rr = (a.r + b.r) * 0.92;        var d2 = dx * dx + dy * dy;        if (d2 < rr * rr) {          // separate overlapping ones slightly (soft push)          var d = Math.sqrt(d2) || 0.01;          var push = (rr - d) * 0.5;          var ux = dx / d, uy = dy / d;          a.x -= ux * push * 0.5; a.y -= uy * push * 0.5;          b.x += ux * push * 0.5; b.y += uy * push * 0.5;          // merge this pair          var merged = mergePair(a, b);          var kids = (merged.r > tube.w * MAX_R_FRAC) ? splitBlob(merged) : [merged];          blobs.splice(j, 1);          blobs.splice.apply(blobs, [i, 1].concat(kids));          i--; // re-check current index after splice          break;        }      }    }  }  function update(dt) {    time += dt;    for (var i = 0; i < blobs.length; i++) updateBlob(blobs[i], dt);    resolveCollisions();  }  // ---------- drawing ----------  function roundRectPath(x, y, w, h, r) {    ctx.beginPath();    if (ctx.roundRect) {      ctx.roundRect(x, y, w, h, r);      return;    }    // fallback    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();  }  function heatColor(temp) {    // hsl interpolation: cool deep red -> warm orange -> hot gold    var t = clamp(temp, 0, 1);    var hue = lerp(4, 42, t);    var sat = lerp(68, 96, t);    var li  = lerp(20, 56, t);    return {      core: 'hsl(' + (hue + 8) + ',' + Math.min(100, sat + 6) + '%,' + Math.min(72, li + 18) + '%)',      mid:  'hsl(' + hue + ',' + sat + '%,' + li + '%)',      edge: 'hsl(' + lerp(2, 18, t) + ',' + lerp(60, 90, t) + '%,' + Math.max(10, li - 14) + '%)'    };  }  function drawScene() {    // wall    var wall = ctx.createLinearGradient(0, 0, 0, deskY);    wall.addColorStop(0, '#191a26');    wall.addColorStop(0.6, '#14151f');    wall.addColorStop(1, '#101118');    ctx.fillStyle = wall;    ctx.fillRect(0, 0, W, deskY + 1);    // wall glow behind lamp (warm ambience when on)    if (light > 0.01) {      var glow = ctx.createRadialGradient(W / 2, tube.y + tube.h * 0.45, 10, W / 2, tube.y + tube.h * 0.45, tube.w * 2.5);      glow.addColorStop(0, 'rgba(255,140,60,' + (0.30 * light) + ')');      glow.addColorStop(0.55, 'rgba(255,110,40,' + (0.12 * light) + ')');      glow.addColorStop(1, 'rgba(255,110,40,0)');      ctx.fillStyle = glow;      ctx.fillRect(0, 0, W, deskY);    }    // desk    var desk = ctx.createLinearGradient(0, deskY, 0, H);    desk.addColorStop(0, '#3b2a1d');    desk.addColorStop(0.08, '#33241a');    desk.addColorStop(1, '#1c120c');    ctx.fillStyle = desk;    ctx.fillRect(0, deskY, W, H - deskY);    // desk edge highlight    ctx.fillStyle = 'rgba(255,205,150,' + (0.10 + 0.16 * light) + ')';    ctx.fillRect(0, deskY, W, 2);    // lamp shadow on desk    ctx.save();    ctx.fillStyle = 'rgba(0,0,0,0.45)';    ctx.beginPath();    ctx.ellipse(W / 2, deskY + 8, base.w * 0.72, 12, 0, 0, Math.PI * 2);    ctx.fill();    ctx.restore();    // light pool on desk when on    if (light > 0.01) {      var pool = ctx.createRadialGradient(W / 2, deskY, 4, W / 2, deskY, base.w * 1.5);      pool.addColorStop(0, 'rgba(255,150,70,' + (0.34 * light) + ')');      pool.addColorStop(1, 'rgba(255,150,70,0)');      ctx.save();      ctx.translate(0, deskY);      ctx.scale(1, 0.32);      ctx.translate(0, -deskY);      ctx.fillStyle = pool;      ctx.fillRect(0, deskY, W, H - deskY);      ctx.restore();    }  }  function drawLamp() {    var bw = base.w, bh = base.h, bx = base.x, by = base.y;    // base body    var baseG = ctx.createLinearGradient(bx, by, bx, by + bh);    baseG.addColorStop(0, '#2c2c33');    baseG.addColorStop(0.5, '#1d1d24');    baseG.addColorStop(1, '#121218');    ctx.fillStyle = baseG;    roundRectPath(bx, by, bw, bh, 9);    ctx.fill();    ctx.strokeStyle = 'rgba(255,255,255,0.07)';    ctx.lineWidth = 1;    ctx.stroke();    // base glow slit    ctx.save();    ctx.globalAlpha = 0.25 + 0.75 * light;    var slitG = ctx.createLinearGradient(bx, by + bh * 0.52, bx, by + bh * 0.72);    slitG.addColorStop(0, 'rgba(255,170,80,0)');    slitG.addColorStop(0.5, 'rgba(255,190,110,' + (0.95 * light) + ')');    slitG.addColorStop(1, 'rgba(255,170,80,0)');    ctx.fillStyle = slitG;    roundRectPath(bx + bw * 0.16, by + bh * 0.5, bw * 0.68, bh * 0.22, 6);    ctx.fill();    ctx.restore();    // cap at top    var capG = ctx.createLinearGradient(cap.x, cap.y, cap.x, cap.y + cap.h);    capG.addColorStop(0, '#33333c');    capG.addColorStop(1, '#1b1b22');    ctx.fillStyle = capG;    roundRectPath(cap.x, cap.y, cap.w, cap.h, cap.h / 2);    ctx.fill();    // glass tube interior (wax fill)    ctx.save();    roundRectPath(tube.x, tube.y, tube.w, tube.h, tube.r);    ctx.clip();    var wax = ctx.createLinearGradient(0, tube.y, 0, tube.y + tube.h);    wax.addColorStop(0, '#22132a');    wax.addColorStop(0.65, '#2a1624');    wax.addColorStop(1, '#33131f');    ctx.fillStyle = wax;    ctx.fillRect(tube.x, tube.y, tube.w, tube.h);    // warm interior glow from bottom    if (light > 0.01) {      var ig = ctx.createRadialGradient(W / 2, tube.y + tube.h + 8, 6, W / 2, tube.y + tube.h + 8, tube.h * 1.05);      ig.addColorStop(0, 'rgba(255,140,50,' + (0.5 * light) + ')');      ig.addColorStop(0.45, 'rgba(255,100,40,' + (0.20 * light) + ')');      ig.addColorStop(1, 'rgba(255,100,40,0)');      ctx.globalCompositeOperation = 'lighter';      ctx.fillStyle = ig;      ctx.fillRect(tube.x, tube.y, tube.w, tube.h);      ctx.globalCompositeOperation = 'source-over';    }    // blobs    for (var i = 0; i < blobs.length; i++) drawBlob(blobs[i]);    // glass reflection streaks    ctx.globalCompositeOperation = 'screen';    var streak = ctx.createLinearGradient(tube.x, 0, tube.x + tube.w, 0);    streak.addColorStop(0, 'rgba(255,255,255,0.16)');    streak.addColorStop(0.18, 'rgba(255,255,255,0.03)');    streak.addColorStop(0.55, 'rgba(255,255,255,0.0)');    streak.addColorStop(0.85, 'rgba(255,255,255,0.05)');    streak.addColorStop(1, 'rgba(255,255,255,0.12)');    ctx.fillStyle = streak;    ctx.fillRect(tube.x, tube.y, tube.w, tube.h);    ctx.globalCompositeOperation = 'source-over';    ctx.restore();    // glass outline    roundRectPath(tube.x, tube.y, tube.w, tube.h, tube.r);    ctx.strokeStyle = 'rgba(235,240,255,0.28)';    ctx.lineWidth = 2.5;    ctx.stroke();    roundRectPath(tube.x + 3, tube.y + 3, tube.w - 6, tube.h - 6, tube.r - 3);    ctx.strokeStyle = 'rgba(235,240,255,0.10)';    ctx.lineWidth = 1;    ctx.stroke();    // bright highlight stripe on glass    ctx.save();    roundRectPath(tube.x, tube.y, tube.w, tube.h, tube.r);    ctx.clip();    var hl = ctx.createLinearGradient(0, tube.y, 0, tube.y + tube.h);    hl.addColorStop(0, 'rgba(255,255,255,0.34)');    hl.addColorStop(0.35, 'rgba(255,255,255,0.05)');    hl.addColorStop(1, 'rgba(255,255,255,0.10)');    ctx.fillStyle = hl;    roundRectPath(tube.x + tube.w * 0.16, tube.y + tube.h * 0.06, tube.w * 0.12, tube.h * 0.85, tube.w * 0.06);    ctx.fill();    ctx.restore();  }  function drawBlob(b) {    var wobT = time * b.wob + b.phase;    var sx = 1 + 0.12 * Math.sin(wobT);    var sy = 1 - 0.12 * Math.sin(wobT);    // stretch along vertical motion    var stretch = 1 + clamp(Math.abs(b.vy) / 420, 0, 0.28);    sy *= stretch; sx /= Math.sqrt(stretch);    var c = heatColor(b.temp);    var rx = b.r * sx, ry = b.r * sy;    ctx.save();    ctx.translate(b.x, b.y);    var g = ctx.createRadialGradient(-rx * 0.28, -ry * 0.30, ry * 0.1, 0, 0, rx * 1.05);    g.addColorStop(0, c.core);    g.addColorStop(0.55, c.mid);    g.addColorStop(1, c.edge);    ctx.fillStyle = g;    ctx.beginPath();    ctx.ellipse(0, 0, rx, ry, 0, 0, Math.PI * 2);    ctx.fill();    // specular highlight    ctx.globalAlpha = 0.5;    var hg = ctx.createRadialGradient(-rx * 0.34, -ry * 0.42, 1, -rx * 0.34, -ry * 0.42, rx * 0.5);    hg.addColorStop(0, 'rgba(255,240,210,0.85)');    hg.addColorStop(1, 'rgba(255,240,210,0)');    ctx.fillStyle = hg;    ctx.beginPath();    ctx.ellipse(0, 0, rx, ry, 0, 0, Math.PI * 2);    ctx.fill();    ctx.restore();  }  function draw() {    ctx.clearRect(0, 0, W, H);    drawScene();    drawLamp();    // dark overlay when off (scene dims)    if (light < 0.98) {      ctx.fillStyle = 'rgba(6,7,12,' + ((1 - light) * 0.5) + ')';      ctx.fillRect(0, 0, W, H);    }  }  // ---------- loop ----------  var last = performance.now();  function frame(now) {    var dt = (now - last) / 1000;    last = now;    if (dt > 0.05) dt = 0.05;    if (dt <= 0) { requestAnimationFrame(frame); return; }    var targetLight = LAMP_ON ? 1 : 0;    light += (targetLight - light) * Math.min(1, dt * 5);    if (Math.abs(targetLight - light) < 0.001) light = targetLight;    update(dt);    draw();    requestAnimationFrame(frame);  }  // ---------- switch ----------  function setLamp(on) {    LAMP_ON = on;    btn.setAttribute('aria-checked', String(on));    label.textContent = on ? 'On' : 'Off';  }  btn.addEventListener('click', function () { setLamp(!LAMP_ON); });  document.addEventListener('keydown', function (e) {    if (e.code === 'Space' && e.target === document.body) {      e.preventDefault();      setLamp(!LAMP_ON);    }  });  resize();  seedBlobs();  window.addEventListener('resize', resize);  window.addEventListener('orientationchange', function () {    setTimeout(resize, 60);  });  requestAnimationFrame(frame);})();</script></body></html>