Lava lamp v1 · Codex CLI29.11.2026 13:09
<!doctype html><html lang="en"><head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="theme-color" content="#eee4d6"> <title>Lava Lamp</title> <link rel="icon" href="data:,"> <style> :root { color-scheme: light; font-family: "Helvetica Neue", Arial, sans-serif; color: #32231d; background: #eee4d6; } * { box-sizing: border-box; } body { min-width: 280px; min-height: 100vh; min-height: 100svh; margin: 0; padding: clamp(16px, 4vw, 64px); display: grid; place-items: center; background: radial-gradient(ellipse at 24% 0%, #faf3e7, #eee4d6 70%, #e7dac9); } .display { display: grid; grid-template-columns: minmax(290px, 33%) minmax(0, 1fr); width: min(100%, 1256px); height: clamp(480px, 80vh, 748px); height: clamp(480px, 80svh, 748px); padding: 12px; border: 1px solid #d8c8b5; border-radius: 24px; background: #f9f0e4; box-shadow: 0 24px 66px -33px #60402a68, inset 0 1px #fffaf2; } .panel { display: grid; align-content: center; justify-items: start; gap: 40px; padding: 24px clamp(25px, 4.1vw, 61px); } .introduction { min-width: 0; } .mark { display: grid; place-items: center; width: 44px; height: 44px; margin-bottom: 34px; border: 1px solid #dfc4ae; border-radius: 50%; background: #f3e4d3; } .drop { width: 11px; height: 16px; margin: -3px 0 0 -3px; transform: rotate(37deg); border-radius: 70% 35% 63% 55%; background: linear-gradient(145deg, #d17d54, #a54c33); box-shadow: 7px 3px 0 -3px #c66e48; } h1 { margin: 0 0 24px; font-family: Baskerville, "Times New Roman", serif; font-size: clamp(75px, 8.1vw, 120px); font-weight: 400; line-height: .86; letter-spacing: -.065em; } h1 em { display: block; color: #a34b32; font-weight: inherit; } .caption { max-width: 210px; margin: 0; color: #705b4f; font-size: 15px; line-height: 1.6; } .power { display: flex; width: 100%; max-width: 245px; align-items: center; justify-content: space-between; gap: 16px; padding-top: 20px; border-top: 1px solid #e4d4c4; } .power-text { display: grid; gap: 5px; font-size: 14px; font-weight: 600; } .power-state { display: flex; align-items: center; gap: 6px; color: #735d50; font-size: 12px; font-weight: 400; } .power-state::before { width: 6px; height: 6px; border-radius: 50%; background: #a3988a; content: ""; transition: background .25s, box-shadow .25s; } [data-powered="true"] .power-state::before { background: #b85834; box-shadow: 0 0 0 3px #b858341b; } .switch { position: relative; width: 67px; height: 44px; padding: 0; flex: none; border: 0; border-radius: 23px; background: transparent; cursor: pointer; touch-action: manipulation; } .switch::before, .switch::after { position: absolute; content: ""; } .switch::before { inset: 4px 0; border: 1px solid #857468; border-radius: 100px; background: #9a897b; box-shadow: inset 0 2px 4px #3b261d43, 0 1px #fff9ed; transition: background .25s, border-color .25s; } .switch::after { top: 8px; left: 5px; width: 28px; height: 28px; border: 1px solid #ffead3; border-radius: 50%; background: linear-gradient(#fff5e5, #e8c9ae); box-shadow: 0 1px 3px #3a1b1660; transition: transform .25s cubic-bezier(.3, .7, .3, 1); } .switch[aria-checked="true"]::before { border-color: #9d4a32; background: #bb603f; } .switch[aria-checked="true"]::after { transform: translateX(29px); } .switch:hover::after { background: linear-gradient(#fffaf1, #f0d3b8); } .switch:focus-visible { outline: 2px solid #9d4a32; outline-offset: 4px; } .studio { position: relative; min-height: 0; overflow: hidden; isolation: isolate; border-radius: 15px; background: #2a1b18; } .studio::after { position: absolute; inset: 0; pointer-events: none; border-radius: inherit; box-shadow: inset 0 0 0 1px #fff0d31a; content: ""; } .studio canvas { position: absolute; top: 0; left: 0; display: block; width: 100%; height: 100%; pointer-events: none; } .emissive { opacity: 0; transition: opacity .8s ease-in-out; } [data-powered="true"] .emissive { opacity: 1; } .lamp { position: absolute; top: 0; left: 0; width: 200px; height: 522px; transform-origin: top left; } .bottle { position: absolute; top: 68px; left: 14px; width: 172px; height: 328px; } @media (max-width: 760px) and (orientation: portrait), (max-width: 459px) { body { padding: 12px; } .display { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); width: min(100%, 530px); height: calc(100vh - 24px); height: calc(100svh - 24px); min-height: 400px; padding: 8px; border-radius: 20px; } .panel { grid-template-columns: 1fr auto; grid-template-areas: "heading power" "caption caption"; align-items: center; gap: 7px 8px; padding: 14px 10px 15px; } .introduction { display: contents; } .mark { display: none; } h1 { grid-area: heading; margin: 0; font-size: clamp(34px, 11vw, 62px); line-height: .96; white-space: nowrap; } h1 em { display: inline; } .caption { grid-area: caption; max-width: none; font-size: 13px; line-height: 1.45; } .power { grid-area: power; gap: 9px; padding: 0; border: 0; } .power-text { gap: 3px; font-size: 12px; } .power-state { font-size: 11px; } .switch { width: 55px; } .switch::before { inset-block: 7px; } .switch::after { top: 10px; width: 24px; height: 24px; } .switch[aria-checked="true"]::after { transform: translateX(21px); } .studio { border-radius: 13px; } } @media (max-width: 345px) { .panel { padding-inline: 6px; } .power { gap: 6px; } h1 { font-size: 10.6vw; } } @media (min-width: 460px) and (max-height: 540px) and (orientation: landscape) { body { padding: 10px; } .display { grid-template-columns: minmax(202px, 32%) minmax(0, 1fr); height: calc(100vh - 20px); height: calc(100svh - 20px); min-height: 275px; padding: 8px; } .panel { gap: 17px; padding: 12px 23px; } .mark { display: none; } h1 { margin-bottom: 11px; font-size: clamp(52px, 10vw, 78px); } .caption { font-size: 13px; line-height: 1.4; } .power { padding-top: 8px; } } @media (prefers-reduced-motion: reduce) { .switch::before, .switch::after, .power-state::before, .emissive { transition: none; } } </style></head><body> <main class="display" data-powered="true"> <div class="panel"> <div class="introduction"> <div class="mark" aria-hidden="true"><span class="drop"></span></div> <h1>Lava <em>Lamp</em></h1> <p class="caption">Wax rises as it warms and sinks as it cools.</p> </div> <div class="power"> <div class="power-text" aria-hidden="true"> <span>Power</span> <span class="power-state" id="power-state">On</span> </div> <button class="switch" id="power" type="button" role="switch" aria-label="Lamp power" aria-checked="true"></button> </div> </div> <div class="studio" role="img" aria-label="An amber glass lava lamp on a walnut desk"> <canvas id="room"></canvas> <canvas id="room-light" class="emissive"></canvas> <div class="lamp"> <div class="bottle"> <canvas id="glass"></canvas> <canvas id="glass-light" class="emissive"></canvas> <canvas id="wax" width="172" height="328"></canvas> <canvas id="glass-shine"></canvas> </div> <canvas id="metal"></canvas> </div> </div> </main> <script> 'use strict'; const display = document.querySelector('.display'); const studio = document.querySelector('.studio'); const lamp = document.querySelector('.lamp'); const power = document.querySelector('#power'); const powerState = document.querySelector('#power-state'); const room = document.querySelector('#room'); const roomLight = document.querySelector('#room-light'); const wax = document.querySelector('#wax'); const waxContext = wax.getContext('2d'); const glassWidth = wax.width; const glassHeight = wax.height; const glassHalf = glassWidth / 2; const deskBack = 551; const deskFront = 656; const glassPath = new Path2D( 'M 49 1 Q 86 -4 123 1 C 125 23 128 42 132 60 L 162 253 ' + 'Q 170 292 161 313 Q 158 322 143 325 Q 86 331 29 325 ' + 'Q 14 322 11 313 Q 2 292 10 253 L 40 60 Q 46 26 49 1 Z' ); const clamp = (n, min, max) => Math.min(max, Math.max(min, n)); const lerp = (a, b, t) => a + (b - a) * t; function smoothstep(min, max, n) { const t = clamp((n - min) / (max - min), 0, 1); return t * t * (3 - 2 * t); } function randomSequence(seed) { return () => { seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0; return seed / 4294967296; }; } function linear(context, x0, y0, x1, y1, stops) { const gradient = context.createLinearGradient(x0, y0, x1, y1); for (const [distance, color] of stops) gradient.addColorStop(distance, color); return gradient; } function oval(context, x, y, width, height, stops) { context.save(); context.translate(x, y); context.scale(width, height); const gradient = context.createRadialGradient(0, 0, 0, 0, 0, 1); for (const [distance, color] of stops) gradient.addColorStop(distance, color); context.fillStyle = gradient; context.fillRect(-1, -1, 2, 2); context.restore(); } function stroke(context, path, color, width = 1) { context.strokeStyle = color; context.lineWidth = width; context.stroke(new Path2D(path)); } function grainPattern(context) { const tile = document.createElement('canvas'); tile.width = tile.height = 128; const tileContext = tile.getContext('2d'); const grain = tileContext.createImageData(128, 128); const next = randomSequence(27); for (let pixel = 0; pixel < grain.data.length; pixel += 4) { const value = next(); grain.data[pixel] = grain.data[pixel + 1] = grain.data[pixel + 2] = value < .48 ? 0 : 255; grain.data[pixel + 3] = Math.abs(value - .48) * 35; } tileContext.putImageData(grain, 0, 0); return context.createPattern(tile, 'repeat'); } function drawBooks(context, x) { context.save(); context.translate(x, 0); oval(context, 25, 586, 116, 19, [[0, '#140a09ca'], [.58, '#180c0b77'], [1, '#180c0b00']]); const bottomCover = new Path2D('M -12 543 L 93 543 L 159 568 L 159 583 L 35 588 L -12 563 Z'); context.fillStyle = '#281b19'; context.fill(bottomCover); context.fillStyle = linear(context, 38, 566, 40, 587, [ [0, '#5b4435'], [.28, '#ac8c69'], [.64, '#856a50'], [1, '#4b382d'] ]); context.fill(new Path2D('M 35 573 L 156 569 L 156 582 L 35 586 Z')); for (let line = 0; line < 5; line++) { stroke(context, `M 38 ${575 + line * 1.8} L 155 ${571 + line * 1.8}`, '#3c292329', .65); } context.fillStyle = '#3a2924'; context.fill(new Path2D('M -14 542 L 94 542 L 162 569 L 35 574 Z')); stroke(context, 'M -13 542 L 35 574 L 162 569', '#93705c', .8); context.fillStyle = linear(context, 0, 535, 32, 573, [ [0, '#75452f'], [.5, '#512d23'], [1, '#2c1b18'] ]); context.fill(new Path2D('M 4 532 L 102 530 L 144 554 L 144 565 L 41 570 L 4 549 Z')); context.fillStyle = linear(context, 43, 553, 45, 568, [ [0, '#674c38'], [.43, '#b09575'], [1, '#75523d'] ]); context.fill(new Path2D('M 41 558 L 142 554 L 142 564 L 41 568 Z')); stroke(context, 'M 42 561 L 140 557 M 42 564 L 141 560 M 42 566 L 141 562', '#422c2540', .7); context.fillStyle = linear(context, 20, 532, 103, 558, [ [0, '#976047'], [.43, '#704334'], [1, '#523029'] ]); context.fill(new Path2D('M 3 532 L 102 529 L 147 554 L 41 560 Z')); stroke(context, 'M 6 533 L 101 530 L 144 554 L 42 559 Z', '#d8a17e4d', .9); stroke(context, 'M 12 535 L 47 556', '#40271fb8', .85); context.restore(); } function drawRoom(context, left, top, right, bottom) { const width = right - left; const height = bottom - top; context.fillStyle = linear(context, left, top, right, deskBack, [ [0, '#3f2e29'], [.41, '#382823'], [1, '#211714'] ]); context.fillRect(left, top, width, height); oval(context, -212, 122, 488, 433, [[0, '#ae795539'], [.57, '#9d694a16'], [1, '#9d694a00']]); oval(context, 151, 348, 448, 370, [[0, '#170b091d'], [1, '#170b0900']]); // Soft window light on the plaster wall. context.save(); context.beginPath(); context.rect(left, top, width, deskBack - top); context.clip(); const windowLight = linear(context, -250, 83, -53, 454, [ [0, '#c89a7240'], [.52, '#cb996929'], [1, '#d5a07200'] ]); context.fillStyle = windowLight; context.filter = 'blur(13px)'; context.fill(new Path2D('M -556 -90 L -421 -90 L -88 485 L -182 520 Z')); context.fill(new Path2D('M -385 -90 L -288 -90 L 43 447 L -51 490 Z')); context.filter = 'none'; context.restore(); context.fillStyle = linear(context, 0, deskBack, 0, deskFront, [ [0, '#493024'], [.15, '#583a2a'], [.58, '#684431'], [1, '#503126'] ]); context.fillRect(left, deskBack, width, deskFront - deskBack); stroke(context, `M ${left} ${deskBack + .5} H ${right}`, '#c78c632d'); const next = randomSequence(86); for (let line = 0; line < 195; line++) { const y = lerp(deskBack + 2, deskFront - 1, next()); const x = lerp(left - 265, right, next()); const length = 85 + next() * 340; const bend = (next() - .5) * 5; const path = `M ${x} ${y} q ${length * .22} ${bend} ${length * .51} ${bend * .22} t ${length * .49} ${-bend * .22}`; stroke(context, path, line % 3 === 0 ? '#d69b6b22' : '#2a191628', .3 + next() * .9); } context.fillStyle = linear(context, 0, deskFront, 0, bottom, [ [0, '#67422e'], [.07, '#906044'], [.21, '#513124'], [1, '#251915'] ]); context.fillRect(left, deskFront, width, bottom - deskFront); stroke(context, `M ${left} ${deskFront} H ${right}`, '#bd805149'); context.fillStyle = grainPattern(context); context.fillRect(left, top, width, height); oval(context, 31, 594, 163, 29, [[0, '#1a0e0adf'], [.5, '#1d110eb1'], [1, '#1d110e00']]); oval(context, 0, 594, 100, 13, [[0, '#110806ed'], [.75, '#160b08a0'], [1, '#160b0800']]); const cable = 'M 47 585 C 104 587 121 563 163 560 C 238 553 280 559 445 553'; stroke(context, cable, '#2215119c', 5); stroke(context, cable, '#30221c', 2.8); stroke(context, 'M 96 581 C 121 571 139 562 162 559 C 239 552 283 558 445 552', '#8d685231', .75); drawBooks(context, clamp(right - 145, 125, 223)); const vignette = context.createRadialGradient(-15, 338, 235, -15, 338, Math.max(455, width * .69)); vignette.addColorStop(0, '#170f0c00'); vignette.addColorStop(1, '#170f0c82'); context.fillStyle = vignette; context.fillRect(left, top, width, height); } function drawRoomLight(context, left, top, right) { context.save(); context.beginPath(); context.rect(left, top, right - left, deskBack - top); context.clip(); oval(context, 0, 365, 295, 321, [ [0, '#de6a2c55'], [.35, '#ce632838'], [.69, '#bd532418'], [1, '#bc512300'] ]); oval(context, -6, 422, 152, 213, [[0, '#ed833435'], [.58, '#da661f12'], [1, '#da661f00']]); context.restore(); context.save(); context.beginPath(); context.rect(left, deskBack, right - left, deskFront - deskBack); context.clip(); oval(context, -2, 602, 225, 51, [ [0, '#ff9e483c'], [.39, '#e9813524'], [.71, '#d0712811'], [1, '#d0712800'] ]); context.restore(); } function prepareSurface(canvas, width, height, density) { canvas.width = Math.round(width * density); canvas.height = Math.round(height * density); const context = canvas.getContext('2d'); context.setTransform(canvas.width / width, 0, 0, canvas.height / height, 0, 0); return context; } function layoutStudio() { const { width, height } = studio.getBoundingClientRect(); if (!width || !height) return; const scale = Math.min(height / 700, width / 330); const center = width * (width / height > 1 ? .471 : .5); const offset = height * .783 - deskBack * scale; const density = Math.min(devicePixelRatio || 1, 2); const left = -center / scale; const right = (width - center) / scale; const top = -offset / scale; const bottom = (height - offset) / scale; for (const [canvas, paint] of [[room, drawRoom], [roomLight, drawRoomLight]]) { const context = prepareSurface(canvas, width, height, density); context.translate(center, offset); context.scale(scale, scale); paint(context, left, top, right, bottom); } lamp.style.transform = `translate(${center - 100 * scale}px, ${offset + 76 * scale}px) scale(${scale})`; } function drawGlass(context, lit) { context.save(); context.clip(glassPath); context.fillStyle = linear(context, 0, 4, 0, glassHeight, lit ? [ [0, '#432124'], [.18, '#642d25'], [.57, '#823722'], [.85, '#b5572a'], [.96, '#e69041'], [1, '#f7af5b'] ] : [ [0, '#261a1c'], [.22, '#372121'], [.72, '#452921'], [.94, '#563225'], [1, '#67402b'] ]); context.fillRect(0, 0, glassWidth, glassHeight); oval(context, 86, 278, 83, 265, lit ? [ [0, '#f47b2c4e'], [.69, '#ef63252c'], [1, '#ee632500'] ] : [ [0, '#ba7c4f2b'], [.68, '#9b604222'], [1, '#9b604200'] ]); context.fillStyle = linear(context, 8, 0, 165, 0, [ [0, '#231317a8'], [.13, '#2c13183f'], [.35, '#43181b00'], [.71, '#2b101413'], [.87, '#28141745'], [1, '#1b1117b2'] ]); context.fillRect(0, 0, glassWidth, glassHeight); if (lit) { oval(context, 85, 325, 75, 46, [[0, '#ffce776b'], [.42, '#ffb35943'], [1, '#fda74100']]); } context.restore(); } function drawGlassShine(context) { context.save(); context.clip(glassPath); context.lineWidth = 3.2; context.strokeStyle = '#341e21a1'; context.stroke(glassPath); context.lineWidth = 1.6; context.strokeStyle = linear(context, 0, 14, 0, glassHeight, [ [0, '#e4b68991'], [.45, '#c88c7173'], [.79, '#e0a7729f'], [1, '#ffd193b5'] ]); context.stroke(glassPath); context.fillStyle = linear(context, 0, 15, 0, 310, [ [0, '#ffe3b379'], [.19, '#ffe8c370'], [.48, '#ffd6ae2c'], [.82, '#ffe4bb15'], [1, '#ffe6c153'] ]); context.fill(new Path2D('M 52 9 C 50 39 42 76 37 111 L 16 267 Q 12 299 24 313 ' + 'Q 17 302 21 268 L 48 111 Q 52 54 57 10 Z')); stroke(context, 'M 50 32 Q 45 76 38 110 L 18 257', '#fff0d962', 1); context.fillStyle = linear(context, 135, 0, 161, 0, [ [0, '#f4ab7d00'], [.65, '#f6c09030'], [1, '#ffe0b14a'] ]); context.fill(new Path2D('M 120 2 L 129 5 L 162 253 Q 168 294 155 310 ' + 'L 145 314 Q 157 294 152 256 Z')); stroke(context, 'M 45 31 Q 85 40 127 31', '#f5c79c4a', .95); stroke(context, 'M 46 30 Q 85 23 126 30', '#dd9a7533', .8); stroke(context, 'M 17 299 Q 24 318 64 319 Q 115 324 151 311', '#ffd7a669', 1.15); stroke(context, 'M 22 304 Q 30 314 56 316 M 135 314 Q 148 310 152 302', '#fff0c894', .75); const next = randomSequence(102); for (let i = 0; i < 43; i++) { const y = 30 + next() * 288; const side = i % 2 === 0 ? 1 : -1; const x = 86 + side * (26 + y * .119 - next() * 14); context.beginPath(); context.arc(x, y, .28 + next() * .78, 0, Math.PI * 2); context.fillStyle = i % 3 === 0 ? '#ffdfb45a' : '#e7a07b43'; context.fill(); } context.restore(); } function drawMetal(context) { const cap = new Path2D('M 76 7 Q 77 2 85 1 Q 100 -1 115 1 Q 123 2 124 7 ' + 'L 140 67 Q 142 74 137 76 Q 100 85 63 76 Q 58 75 60 67 Z'); const base = new Path2D('M 21 391 Q 99 401 179 391 C 173 413 155 436 144 455 ' + 'Q 136 468 153 485 L 179 509 Q 182 512 181 516 Q 100 529 19 516 Q 18 512 21 509 ' + 'L 47 485 Q 63 468 56 455 C 45 436 27 413 21 391 Z'); const bronze = [ [0, '#261c19'], [.07, '#574033'], [.17, '#ad8160'], [.25, '#89644e'], [.43, '#6a4d3f'], [.61, '#503931'], [.82, '#352622'], [.92, '#725442'], [1, '#2d211d'] ]; context.save(); context.clip(cap); context.fillStyle = linear(context, 60, 57, 140, 49, bronze); context.fillRect(57, 0, 86, 85); oval(context, 101, 0, 45, 48, [[0, '#ffd5a755'], [1, '#edb77f00']]); context.fillStyle = linear(context, 0, 47, 0, 78, [[0, '#2b191500'], [1, '#2012106d']]); context.fillRect(58, 40, 84, 42); context.fillStyle = grainPattern(context); context.fillRect(58, 0, 84, 81); stroke(context, 'M 63 71 Q 100 80 138 71', '#e2ae815c', 1); stroke(context, 'M 61 74 Q 100 83 139 74', '#241817a8', 1.4); context.restore(); stroke(context, 'M 77 7 Q 79 1 99 1 Q 117 1 122 5', '#e5ba905b', .95); context.save(); context.clip(base); context.fillStyle = linear(context, 18, 450, 182, 463, bronze); context.fillRect(18, 388, 166, 135); context.fillStyle = linear(context, 0, 390, 0, 522, [ [0, '#ffba8055'], [.12, '#40241921'], [.48, '#28191746'], [.65, '#2917141c'], [.9, '#ffbd8335'], [1, '#2417178f'] ]); context.fillRect(15, 388, 170, 139); oval(context, 64, 404, 47, 85, [[0, '#eec39748'], [.67, '#f7c59920'], [1, '#f7c59900']]); oval(context, 54, 499, 33, 34, [[0, '#dca67956'], [1, '#f9c99700']]); context.fillStyle = grainPattern(context); context.fillRect(18, 387, 166, 135); stroke(context, 'M 25 398 C 35 422 48 439 58 457 Q 63 470 48 487 L 24 511', '#ffcc9d73', 1.45); stroke(context, 'M 172 404 C 160 429 149 445 144 456 Q 138 471 151 484 L 178 511', '#dbab7e47', 1.15); stroke(context, 'M 20 510 Q 99 525 180 510', '#2e211d9f', 2); stroke(context, 'M 20 512 Q 100 528 180 512', '#c8976d7b', .9); context.restore(); const collar = new Path2D('M 21 390 Q 99 400 179 390 L 177 398 Q 100 412 23 398 Z'); context.fillStyle = linear(context, 19, 390, 180, 399, [ [0, '#42302a'], [.14, '#b48360'], [.33, '#b78969'], [.61, '#754e3a'], [.82, '#51372d'], [1, '#6c4937'] ]); context.fill(collar); stroke(context, 'M 22 391 Q 99 402 178 391', '#f5be8c97', 1.2); stroke(context, 'M 23 398 Q 100 412 177 398', '#251815b0', 1.1); } const glassDensity = 2; drawGlass(prepareSurface(document.querySelector('#glass'), glassWidth, glassHeight, glassDensity), false); drawGlass(prepareSurface(document.querySelector('#glass-light'), glassWidth, glassHeight, glassDensity), true); drawGlassShine(prepareSurface(document.querySelector('#glass-shine'), glassWidth, glassHeight, glassDensity)); drawMetal(prepareSurface(document.querySelector('#metal'), 200, 522, glassDensity)); layoutStudio(); new ResizeObserver(layoutStudio).observe(studio); // Heat exchange is strongest near the bulb and at the glass crown. let powered = true; let brightness = 1; let time = 0; const maxMergedArea = 38 ** 2; const nextBlob = randomSequence(61); function makeBlob(x, y, radius, heat, vy, stretch = 1) { return { x, y, radius, heat, vy, stretch, vx: 0, tilt: 0, warming: heat > .53, phase: nextBlob() * Math.PI * 2, contactAfter: 0, splitAfter: time + 2 + nextBlob() * 1.5 }; } const blobs = [ makeBlob(-7, 42, 17, .66, -15, 1.09), makeBlob(10, 81, 15, .30, 10, .9), makeBlob(-19, 143, 23, .81, -31, 1.11), makeBlob(24, 174, 12, .49, 4), makeBlob(26, 222, 20, .32, 18, 1.12), makeBlob(-26, 252, 24, .88, -32, 1.11), makeBlob(9, 302, 34, .91, -12, .71), makeBlob(-41, 308, 15, .84, -9, .77) ]; function keepInGlass(blob) { const height = blob.radius * blob.stretch; const floor = glassHeight - 9 - height * .69; const ceiling = 9 + height * .83; const wall = 36 + clamp(blob.y - height * .5, 0, 261) * .144; const limit = Math.max(0, wall - blob.radius / blob.stretch * .87); if (blob.x < -limit || blob.x > limit) { blob.x = clamp(blob.x, -limit, limit); if (blob.x * blob.vx > 0 || limit === 0) blob.vx *= -.25; } if (blob.y > floor) { blob.y = floor; blob.vy = Math.min(0, blob.vy); } else if (blob.y < ceiling) { blob.y = ceiling; blob.vy = Math.max(0, blob.vy); } } function mergeBlobs(a, b) { const area = a.radius ** 2 + b.radius ** 2; const share = b.radius ** 2 / area; const separation = Math.abs(a.y - b.y); a.x = lerp(a.x, b.x, share); a.y = lerp(a.y, b.y, share); a.vx = lerp(a.vx, b.vx, share); a.vy = lerp(a.vy, b.vy, share); a.heat = lerp(a.heat, b.heat, share); a.warming = a.heat > .53; a.stretch = clamp(lerp(a.stretch, b.stretch, share) + separation * .007, .56, 1.4); a.radius = Math.sqrt(area); a.contactAfter = time + .65; a.splitAfter = time + 1.55 + nextBlob() * 1.2; keepInGlass(a); } function splitBlob(parent) { const share = .25 + nextBlob() * .17; const radius = parent.radius; const direction = parent.x > 0 ? -1 : 1; const horizontal = direction * radius * .54; const vertical = radius * .71; const daughter = makeBlob( parent.x + horizontal * (1 - share), parent.y - vertical * (1 - share), radius * Math.sqrt(share), clamp(parent.heat + .27, 0, 1), parent.vy - 21, Math.max(.94, parent.stretch) ); daughter.vx = parent.vx + direction * 18; daughter.contactAfter = time + 3.1; daughter.splitAfter = time + 4; parent.x -= horizontal * share; parent.y += vertical * share; parent.vx -= direction * 12; parent.vy += 12; parent.heat = clamp(parent.heat - .15, 0, 1); parent.warming = parent.heat > .53; parent.radius = radius * Math.sqrt(1 - share); parent.contactAfter = time + 3.1; parent.splitAfter = time + 4 + nextBlob() * 2; keepInGlass(parent); keepInGlass(daughter); blobs.push(daughter); } function advanceWax(dt) { time += dt; brightness += ((powered ? 1 : 0) - brightness) * Math.min(1, dt * 5.5); for (const blob of blobs) { const warmZone = smoothstep(233, 306, blob.y); const coldZone = 1 - smoothstep(24, 101, blob.y); const waxHeight = blob.radius * blob.stretch; // Keep warming or cooling until the wax reaches the opposite end. if (blob.y + waxHeight * .56 > 285) blob.warming = true; if (blob.y - waxHeight * .42 < 36) blob.warming = false; const endZone = blob.warming ? warmZone : coldZone; const temperature = powered ? (blob.warming ? .93 : .13) : .08; const exchange = powered ? (.125 + .71 * endZone) * clamp(22 / blob.radius, .64, 1.45) : .69; blob.heat += (temperature - blob.heat) * exchange * dt; blob.vy += ((.53 - blob.heat) * 125 - blob.vy * 1.32) * dt; const sway = powered ? 20 * Math.sin(blob.phase + time * .67 + blob.y * .024) : 0; const centering = powered ? lerp(.79, .25, blob.y / glassHeight) : 2.2; blob.vx += (sway - blob.x * centering - blob.vx * 1.22) * dt; blob.x += blob.vx * dt; blob.y += blob.vy * dt; const resting = warmZone * smoothstep(-17, 7, blob.vy); const stretch = .94 + Math.min(Math.abs(blob.vy) * .0065, .37) - resting * .49 - coldZone * .1 + Math.sin(time * 1.7 + blob.phase) * .055 * brightness; blob.stretch += (stretch - blob.stretch) * Math.min(1, dt * 3.7); blob.tilt = clamp(blob.vx * .011, -.24, .24); keepInGlass(blob); } // The visible bridge forms before the centers are close enough to combine. for (let i = 0; i < blobs.length; i++) { const a = blobs[i]; for (let j = i + 1; j < blobs.length; j++) { const b = blobs[j]; if (powered && (Math.max(a.contactAfter, b.contactAfter) > time || a.radius ** 2 + b.radius ** 2 > maxMergedArea)) continue; const stretch = (a.stretch + b.stretch) * .5; const distance = Math.hypot((a.x - b.x) * stretch, (a.y - b.y) / stretch); const reach = (a.radius + b.radius) * (powered ? .68 : .82); if (distance >= reach) continue; mergeBlobs(a, b); blobs.splice(j, 1); break; } } if (powered && blobs.length < 9) { const minimumRadius = blobs.length < 5 ? 22 : 31; const ready = blobs.find(blob => blob.radius >= minimumRadius && time > blob.splitAfter); if (ready) splitBlob(ready); } } const framePixels = waxContext.createImageData(glassWidth, glassHeight); const field = new Float32Array(glassWidth * glassHeight); const heatField = new Float32Array(field.length); waxContext.fill(glassPath); const glassMask = waxContext.getImageData(0, 0, glassWidth, glassHeight).data; function renderWax() { field.fill(0); heatField.fill(0); const pixels = framePixels.data; // A bounded density field joins overlapping shapes into a single surface. for (const blob of blobs) { const x = blob.x + glassHalf; const y = blob.y; const radius2 = blob.radius * blob.radius; const reach = blob.radius * 2.38; const stretch2 = blob.stretch * blob.stretch; const limit2 = reach * reach; const softCore = radius2 * .08; const strength = radius2 + softCore; const falloff = (strength / (limit2 + softCore)) ** 2; const normalization = 1 / (1 - falloff); const firstRow = Math.max(1, Math.ceil(y - reach * blob.stretch)); const lastRow = Math.min(glassHeight - 2, Math.floor(y + reach * blob.stretch)); for (let row = firstRow; row <= lastRow; row++) { const dy = row - y; const dy2 = dy * dy / stretch2; const center = x + dy * blob.tilt; const extent = Math.sqrt(Math.max(0, (limit2 - dy2) / stretch2)); const first = Math.max(1, Math.ceil(center - extent)); const last = Math.min(glassWidth - 2, Math.floor(center + extent)); const offset = row * glassWidth; for (let column = first; column <= last; column++) { const dx = column - center; const density = strength / (dx * dx * stretch2 + dy2 + softCore); const contribution = (density * density - falloff) * normalization; field[offset + column] += contribution; heatField[offset + column] += contribution * blob.heat; } } } for (let y = 1; y < glassHeight - 1; y++) { const bulbLight = y / glassHeight; for (let x = 1; x < glassWidth - 1; x++) { const index = y * glassWidth + x; const pixel = index * 4; const density = field[index]; const glass = glassMask[pixel + 3]; if (density < .14 || glass === 0) { pixels[pixel + 3] = 0; continue; } const gx = field[index + 1] - field[index - 1]; const gy = field[index + glassWidth] - field[index - glassWidth]; const slope = Math.sqrt(gx * gx + gy * gy); const light = .5 + .5 * (gx * .8 + gy * .6) / (slope + .032); const depth = clamp((1 - 1 / Math.sqrt(density)) * 1.9, 0, 1); const edge = clamp(.53 + (density - 1) / Math.max(.065, slope * .5), 0, 1); const warmth = lerp(bulbLight, heatField[index] / density, .63); const highlight = light * light * (1 - depth); const halo = brightness * Math.min(.15, (density - .14) * .18); pixels[pixel] = lerp(59 + 32 * depth + 14 * light, 191 + 44 * depth + 19 * warmth + 45 * highlight + 13 * light, brightness); pixels[pixel + 1] = lerp(31 + 13 * depth + 9 * light, 41 + 47 * depth + 35 * warmth + 83 * highlight + 13 * light, brightness); pixels[pixel + 2] = lerp(26 + 10 * depth + 6 * light, 22 + 17 * depth + 12 * warmth + 49 * highlight, brightness); pixels[pixel + 3] = glass * (edge * .96 + (1 - edge) * halo); } } waxContext.putImageData(framePixels, 0, 0); } let frame = 0; let previous = 0; let restTime = 0; function animate(now) { const dt = previous ? Math.min((now - previous) / 1000, .04) : 0; previous = now; advanceWax(dt); renderWax(); const resting = !powered && brightness < .001 && blobs.every(blob => blob.heat < .092 && Math.abs(blob.vx) < .3 && Math.abs(blob.vy) < .3 && blob.y >= glassHeight - 9 - blob.radius * blob.stretch * .69 - .5 ); restTime = resting ? restTime + dt : 0; if (restTime >= .65) { frame = previous = 0; } else { frame = requestAnimationFrame(animate); } } power.addEventListener('click', () => { powered = !powered; restTime = 0; display.dataset.powered = String(powered); power.setAttribute('aria-checked', String(powered)); powerState.textContent = powered ? 'On' : 'Off'; if (!frame) frame = requestAnimationFrame(animate); }); document.addEventListener('visibilitychange', () => { previous = 0; }); renderWax(); frame = requestAnimationFrame(animate); </script></body></html>