Lava lamp v1 · OpenCode21.11.2026 19:48

Source Qwen3.8 27B, Low effort

index.html · 16.0 KB · 428 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"><title>Lava Lamp</title><style>  html,body{height:100%;margin:0;overflow:hidden;background:#0a0816;    touch-action:manipulation;overscroll-behavior:none;    user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}  body{position:fixed;inset:0}  canvas{display:block;width:100%;height:100%}</style></head><body><canvas id="c"></canvas><script>"use strict";const cv=document.getElementById('c'),ctx=cv.getContext('2d');const TAU=Math.PI*2;const clamp=(v,a,b)=>v<a?a:v>b?b:v;const lerp=(a,b,t)=>a+(b-a)*t;const smooth=t=>t*t*(3-2*t);const col=(off,on,t,a)=>{  const r=Math.round(lerp(off[0],on[0],t)),g=Math.round(lerp(off[1],on[1],t)),b=Math.round(lerp(off[2],on[2],t));  return a===undefined?`rgb(${r},${g},${b})`:`rgba(${r},${g},${b},${a})`;};let dpr=1,W=0,H=0,L=null;let bg=null,shell=null,glowSpr=null,blobSpr=null;let field=null,fctx=null,fw=0,fh=0,hwTable=null;let lut=null;const blobs=[],bubbles=[];let on=true,power=1,knobT=1,tNow=0,lastT=0,hintA=1,toggled=false;let lastLutP=-1;const LE=(()=>{const a=new ArrayBuffer(4);new Uint32Array(a)[0]=0x11223344;return new Uint8Array(a)[0]===0x44;})();const pack=(r,g,b,a)=>LE?((a<<24)|(b<<16)|(g<<8)|r)>>>0:((r<<24)|(g<<16)|(b<<8)|a)>>>0;function buildLUT(p){  const T=64,R=26;  const er=lerp(104,244,p),eg=lerp(48,126,p),eb=lerp(12,34,p);  const cr=lerp(176,255,p),cg=lerp(96,212,p),cb=lerp(28,80,p);  lut=new Uint32Array(256);  for(let a=0;a<256;a++){    if(a<T-R){lut[a]=pack(0,0,0,0);continue;}    const e=a>=T+R?1:smooth((a-(T-R))/(2*R));    const s=clamp((a-T)/(235-T),0,1);    let r=lerp(er,cr,s),g=lerp(eg,cg,s),b=lerp(eb,cb,s);    if(a>240){const h=(a-240)/15*.35;r=lerp(r,255,h);g=lerp(g,250,h);b=lerp(b,205,h);}    lut[a]=pack(r|0,g|0,b|0,(255*e)|0);  }  lastLutP=p;}function makeGlowSprite(){  const S=256,c=S/2,cnv=document.createElement('canvas');  cnv.width=cnv.height=S;  const g=cnv.getContext('2d').createRadialGradient(c,c,0,c,c,c);  g.addColorStop(0,'rgba(255,216,150,1)');  g.addColorStop(.35,'rgba(255,160,80,.55)');  g.addColorStop(1,'rgba(255,120,50,0)');  const x=cnv.getContext('2d');x.fillStyle=g;x.fillRect(0,0,S,S);  return cnv;}function makeBlobSprite(){  const S=128,c=S/2,cnv=document.createElement('canvas');  cnv.width=cnv.height=S;  const x=cnv.getContext('2d'),img=x.createImageData(S,S),d=img.data;  for(let y=0;y<S;y++)for(let i=0;i<S;i++){    const dx=(i-c)/c,dy=(y-c)/c,u2=dx*dx+dy*dy;    let a=u2>=1?0:Math.pow(1-u2,2)*255;    const p=(y*S+i)*4;d[p]=d[p+1]=d[p+2]=255;d[p+3]=a|0;  }  x.putImageData(img,0,0);  return cnv;}function computeLayout(){  W=window.innerWidth;H=window.innerHeight;  dpr=Math.min(window.devicePixelRatio||1,2);  cv.width=Math.round(W*dpr);cv.height=Math.round(H*dpr);  const deskY=H*.86;  const lampH=Math.min(H*.60,560);  const Wd=Math.min(W*.62,300,lampH*.64);  const x0=W/2;  const baseH=lampH*.155,glassH=lampH*.655,capH=lampH*.15;  L={W,H,deskY,x0,     botY:deskY,baseH,glassH,capH,Wd,     neckHalf:Wd*.30,bulgeHalf:Wd*.50,baseHalf:Wd*.56,baseHalfIn:Wd*.44,     bodyBot:deskY,bodyTop:deskY-glassH,capTop:deskY-glassH-capH,     ix:0,iy:0,iw:0,ih:0,swBox:null};  L.ix=x0-L.bulgeHalf;L.iy=L.bodyTop;L.iw=2*L.bulgeHalf;L.ih=glassH;}function halfW(t){  t=clamp(t,0,1);  const n=L.neckHalf,b=L.bulgeHalf,bw=L.baseHalfIn;  if(t<.72){const u=t/.72;return n+(b-n)*smooth(u);}  const u=(t-.72)/.28;return b+(bw-b)*smooth(u);}function subPath(c,off){  const N=26;  for(let i=0;i<=N;i++){    const t=i/N,hw=halfW(t)+off,x=L.x0-hw,y=L.bodyTop+t*L.glassH;    i?c.lineTo(x,y):c.moveTo(x,y);  }  for(let i=N;i>=0;i--){    const t=i/N,hw=halfW(t)+off;    c.lineTo(L.x0+hw,L.bodyTop+t*L.glassH);  }}function rr(c,x,y,w,h,r){  c.beginPath();c.moveTo(x+r,y);  c.arcTo(x+w,y,x+w,y+h,r);c.arcTo(x+w,y+h,x,y+h,r);  c.arcTo(x,y+h,x,y,r);c.arcTo(x,y,x+w,y,r);c.closePath();}function buildBackground(){  bg=document.createElement('canvas');  bg.width=cv.width;bg.height=cv.height;  const c=bg.getContext('2d');c.setTransform(dpr,0,0,dpr,0,0);  const {W,H,deskY,x0,baseHalf,botY}=L;  let g=c.createLinearGradient(0,0,0,H);  g.addColorStop(0,'#181430');g.addColorStop(.55,'#100d20');g.addColorStop(1,'#0a0816');  c.fillStyle=g;c.fillRect(0,0,W,H);  g=c.createRadialGradient(x0,deskY*.72,10,x0,deskY*.72,Math.max(W,240));  g.addColorStop(0,'rgba(90,70,140,.16)');g.addColorStop(1,'rgba(0,0,0,0)');  c.fillStyle=g;c.fillRect(0,0,W,H);  g=c.createLinearGradient(0,deskY,0,H);  g.addColorStop(0,'#4a2b1a');g.addColorStop(.12,'#3a2013');g.addColorStop(1,'#1c0e07');  c.fillStyle=g;c.fillRect(0,deskY,W,H-deskY);  c.fillStyle='rgba(255,190,120,.20)';c.fillRect(0,deskY,W,2);  for(let i=0;i<7;i++){    const y=deskY+8+i*(H-deskY-14)/7+((i*37)%11);    c.fillStyle=i%2?'rgba(0,0,0,.18)':'rgba(255,200,150,.05)';    c.fillRect(0,y,W,1.5);  }  g=c.createRadialGradient(x0,botY+6,2,x0,botY+6,baseHalf*1.6);  g.addColorStop(0,'rgba(0,0,0,.5)');g.addColorStop(1,'rgba(0,0,0,0)');  c.save();c.translate(x0,botY+6);c.scale(1,.18);c.translate(-x0,-(botY+6));  c.fillStyle=g;c.beginPath();c.arc(x0,botY+6,baseHalf*1.6,0,TAU);c.fill();c.restore();}function buildShell(){  shell=document.createElement('canvas');  shell.width=cv.width;shell.height=cv.height;  const c=shell.getContext('2d');c.setTransform(dpr,0,0,dpr,0,0);  const {x0,bodyTop,bodyBot,capH,capTop,neckHalf,bulgeHalf,baseHalf,botY}=L;  const capBase=neckHalf*1.28;  let g=c.createLinearGradient(x0-capBase,0,x0+capBase,0);  g.addColorStop(0,'#3c3c46');g.addColorStop(.25,'#8d8da0');g.addColorStop(.5,'#c9c9da');  g.addColorStop(.75,'#77778a');g.addColorStop(1,'#33333d');  c.fillStyle=g;  c.beginPath();  c.moveTo(x0-capBase,bodyTop+2);  c.lineTo(x0-capBase,bodyTop-capH*.42);  c.quadraticCurveTo(x0-capBase,capTop,x0,capTop);  c.quadraticCurveTo(x0+capBase,capTop,x0+capBase,bodyTop-capH*.42);  c.lineTo(x0+capBase,bodyTop+2);  c.closePath();c.fill();  g=c.createRadialGradient(x0-neckHalf*.4,capTop+capH*.28,1,x0-neckHalf*.4,capTop+capH*.28,neckHalf*.7);  g.addColorStop(0,'rgba(255,255,255,.35)');g.addColorStop(1,'rgba(255,255,255,0)');  c.fillStyle=g;c.fillRect(x0-neckHalf*1.3,capTop-2,neckHalf*2.6,capH);  g=c.createLinearGradient(x0-capBase,0,x0+capBase,0);  g.addColorStop(0,'#26262e');g.addColorStop(.5,'#6a6a7c');g.addColorStop(1,'#1f1f26');  c.fillStyle=g;c.fillRect(x0-capBase-1,bodyTop-3,(capBase+1)*2,5);  g=c.createLinearGradient(x0-baseHalf,0,x0+baseHalf,0);  g.addColorStop(0,'#3a3a44');g.addColorStop(.22,'#84849a');g.addColorStop(.5,'#bcbcd2');  g.addColorStop(.78,'#6d6d82');g.addColorStop(1,'#2e2e38');  c.fillStyle=g;  c.beginPath();  c.moveTo(x0-bulgeHalf*1.04,bodyBot-1);  c.lineTo(x0-baseHalf,botY-4);  c.quadraticCurveTo(x0-baseHalf,botY,x0-baseHalf*.96,botY);  c.lineTo(x0+baseHalf*.96,botY);  c.quadraticCurveTo(x0+baseHalf,botY,x0+baseHalf,botY-4);  c.lineTo(x0+bulgeHalf*1.04,bodyBot-1);  c.closePath();c.fill();  c.fillStyle='rgba(255,255,255,.18)';  c.fillRect(x0-bulgeHalf*1.04,bodyBot-2,bulgeHalf*2.08,2);  c.beginPath();subPath(c,4.5);subPath(c,0);  c.fillStyle='rgba(200,220,255,.08)';c.fill('evenodd');  c.beginPath();subPath(c,4.5);c.strokeStyle='rgba(255,255,255,.40)';c.lineWidth=1.6;c.stroke();  c.beginPath();subPath(c,.5);c.strokeStyle='rgba(255,255,255,.16)';c.lineWidth=1;c.stroke();  const hl=(side,xoff,wdt,alpha)=>{    c.beginPath();    for(let i=0;i<=20;i++){      const t=lerp(.14,.86,i/20),hw=halfW(t);      const x=side>0?L.x0+hw-xoff:L.x0-hw+xoff;      i?c.lineTo(x,L.bodyTop+t*L.glassH):c.moveTo(x,L.bodyTop+t*L.glassH);    }    c.strokeStyle=`rgba(255,255,255,${alpha})`;c.lineWidth=wdt;c.lineCap='round';c.stroke();  };  hl(1,5,2.5,.30);hl(-1,4,1.2,.14);}function buildField(){  fw=clamp(Math.round(L.iw/2.6),48,120);  fh=Math.max(48,Math.round(fw*L.ih/L.iw));  field=document.createElement('canvas');field.width=fw;field.height=fh;  fctx=field.getContext('2d',{willReadFrequently:true});  hwTable=new Float32Array(128);  for(let i=0;i<128;i++)hwTable[i]=halfW(i/127);}function yRangeForR(r){  const need=r+2.5;  let lo=-1,hi=-1;  for(let i=0;i<128;i++)if(hwTable[i]>=need){if(lo<0)lo=i;hi=i;}  if(lo<0)return [L.bodyTop,L.bodyBot];  return [L.bodyTop+lo/127*L.glassH, L.bodyTop+hi/127*L.glassH];}function newBlob(x,y,r,heat){  return {x,y,r,heat,vx:0,vy:0,    rate:.8+Math.random()*.5,wf:.6+Math.random()*1.2,wp:Math.random()*TAU,    drift:(Math.random()-.5)*10,noSplit:0};}function initBlobs(){  blobs.length=0;  for(let i=0;i<7;i++){    const r=L.Wd*(.095+Math.random()*.035);    const x=L.x0+(Math.random()-.5)*L.Wd*.6;    const y=L.bodyTop+L.glassH*(.3+Math.random()*.55);    blobs.push(newBlob(x,y,r,.3+Math.random()*.45));  }}function initBubbles(){  bubbles.length=0;  for(let i=0;i<9;i++)bubbles.push({    x:L.x0+(Math.random()-.5)*L.Wd*.7,    y:L.bodyTop+Math.random()*L.glassH,    r:1.2+Math.random()*2.2,sp:7+Math.random()*14,    wf:.8+Math.random(),wp:Math.random()*TAU});}function step(dt){  tNow+=dt;  const pT=on?1:0;  power+=(pT-power)*(1-Math.exp(-dt/(on?.8:2.4)));  knobT+=(pT-knobT)*(1-Math.exp(-dt*9));  if(Math.abs(power-lastLutP)>.02)buildLUT(power);  if(!toggled&&tNow<7)hintA=Math.min(1,hintA+dt*3);  else hintA=Math.max(0,hintA-dt*1.5);  const {x0,bodyTop,glassH,bodyBot,bulgeHalf,Wd}=L;  const rMax=bulgeHalf*.40;  for(const b of bubbles){    b.y-=b.sp*dt*(.3+.7*power);    b.x+=Math.sin(tNow*b.wf+b.wp)*12*dt;    if(b.y<bodyTop+8){b.y=bodyBot-6-Math.random()*20;b.x=x0+(Math.random()-.5)*Wd*.7;}  }  for(const b of blobs){    const t=clamp((b.y-bodyTop)/glassH,0,1);    const target=clamp((t-.32)*1.7,0,1)*power;    b.heat+=(target-b.heat)*(.22+.5*power)*b.rate*dt;    b.vy+=(0.5-b.heat)*200*dt;    b.vx+=Math.sin(tNow*b.wf+b.wp)*9*dt+b.drift*dt;    b.vy*=Math.exp(-2.1*dt);b.vx*=Math.exp(-1.7*dt);    b.x+=b.vx*dt;b.y+=b.vy*dt;    const hw=halfW(clamp((b.y-bodyTop)/glassH,0,1))-b.r-2.5;    if(hw>0){      if(b.x<x0-hw){b.x=x0-hw;if(b.vx<0)b.vx*=-.25;}      else if(b.x>x0+hw){b.x=x0+hw;if(b.vx>0)b.vx*=-.25;}    }    const yr=yRangeForR(b.r);    let yMin=Math.max(bodyTop+b.r+5,yr[0]);    let yMax=Math.min(bodyBot-b.r-5,yr[1]);    if(yMin>yMax){yMin=yMax=bodyBot-b.r-5;}    if(b.y<yMin){b.y=yMin;if(b.vy<0)b.vy*=-.15;}    else if(b.y>yMax){b.y=yMax;if(b.vy>0)b.vy*=-.12;}  }  let merged=true;  while(merged){    merged=false;    outer:    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,rr2=(a.r+b.r)*.8;      if(dx*dx+dy*dy<rr2*rr2){        const am=a.r*a.r,bm=b.r*b.r,tm=am+bm;        const m=newBlob((a.x*am+b.x*bm)/tm,(a.y*am+b.y*bm)/tm,          Math.min(Math.sqrt(tm),bulgeHalf*.92),(a.heat*am+b.heat*bm)/tm);        m.vx=(a.vx*am+b.vx*bm)/tm;m.vy=(a.vy*am+b.vy*bm)/tm;        m.noSplit=tNow+.9;        blobs.splice(j,1);blobs.splice(i,1);blobs.push(m);        merged=true;break outer;      }    }  }  for(let i=blobs.length-1;i>=0;i--){    const b=blobs[i];    if(b.r>rMax&&tNow>b.noSplit&&blobs.length<14&&power>.12){      const s1=.55+(Math.random()*.14-.07);      const r1=Math.sqrt(s1)*b.r,r2=Math.sqrt(1-s1)*b.r;      const ang=Math.random()*.9-.45,off=(r1+r2)*.85;      const dx=Math.cos(ang)*off,dy=Math.sin(ang)*off*.6;      const a=newBlob(b.x-dx,b.y-dy,r1,b.heat);      a.vx=b.vx-Math.cos(ang)*22;a.vy=b.vy-Math.sin(ang)*12;a.noSplit=tNow+.6;      const c2=newBlob(b.x+dx,b.y+dy,r2,b.heat);      c2.vx=b.vx+Math.cos(ang)*22;c2.vy=b.vy+Math.sin(ang)*12;c2.noSplit=tNow+.6;      blobs[i]=a;blobs.push(c2);    }  }}function updateField(){  const {ix,iy,iw,ih}=L;  fctx.clearRect(0,0,fw,fh);  fctx.globalCompositeOperation='lighter';  for(const b of blobs){    const R=b.r*1.4*fw/iw;    fctx.drawImage(blobSpr,(b.x-ix)*fw/iw-R,(b.y-iy)*fh/ih-R,R*2,R*2);  }  fctx.globalCompositeOperation='source-over';  const img=fctx.getImageData(0,0,fw,fh);  const d=img.data,v=new Uint32Array(d.buffer);  for(let i=0;i<d.length;i+=4)v[i>>2]=lut[d[i+3]];  fctx.putImageData(img,0,0);}function drawSwitch(){  const {x0,bodyBot,baseH,Wd}=L;  const w=clamp(Wd*.17,30,46),h=w*.52;  const sx=x0-w/2,sy=bodyBot+baseH*.42;  ctx.fillStyle='#14141c';rr(ctx,sx,sy,w,h,h*.5);ctx.fill();  ctx.strokeStyle='rgba(255,255,255,.18)';ctx.lineWidth=1;rr(ctx,sx,sy,w,h,h*.5);ctx.stroke();  const kx=sx+h*.5+(w-h)*knobT,ky=sy+h*.5;  const g=ctx.createLinearGradient(0,ky-h*.32,0,ky+h*.32);  g.addColorStop(0,'#f2f2f8');g.addColorStop(1,'#9a9aa8');  ctx.beginPath();ctx.arc(kx,ky,h*.32,0,TAU);ctx.fillStyle=g;ctx.fill();  ctx.beginPath();ctx.arc(sx+w+7,ky,2.6,0,TAU);  ctx.fillStyle=on?`rgba(255,70,60,${.35+.65*power})`:'rgba(120,120,130,.8)';ctx.fill();  if(on&&power>.05){    ctx.globalCompositeOperation='lighter';ctx.globalAlpha=.5*power;    ctx.drawImage(glowSpr,sx+w, sy+h*.5-7,14,14);    ctx.globalAlpha=1;ctx.globalCompositeOperation='source-over';  }  L.swBox={x:sx-12,y:sy-12,w:w+30,h:h+26};}function render(){  const {W,H,x0,ix,iy,iw,ih,bodyTop,bodyBot,glassH,Wd,capTop,deskY}=L;  ctx.setTransform(dpr,0,0,dpr,0,0);  ctx.drawImage(bg,0,0,W,H);  const flick=.93+.07*Math.sin(tNow*7.3)*Math.sin(tNow*3.1+1.7);  const p=power*flick;  ctx.globalCompositeOperation='lighter';  let gR=Wd*1.15;  ctx.globalAlpha=.30*p;ctx.drawImage(glowSpr,x0-gR,bodyBot-gR,gR*2,gR*2);  gR=Wd*.55;  ctx.globalAlpha=.55*p;ctx.drawImage(glowSpr,x0-gR,bodyBot-gR,gR*2,gR*2);  ctx.globalAlpha=1;ctx.globalCompositeOperation='source-over';  ctx.save();  ctx.beginPath();subPath(ctx,.5);ctx.clip();  let g=ctx.createLinearGradient(0,bodyTop,0,bodyBot);  g.addColorStop(0,col([40,18,70],[86,28,140],power));  g.addColorStop(.65,col([58,16,88],[150,32,130],power));  g.addColorStop(1,col([80,20,90],[210,58,120],power));  ctx.fillStyle=g;ctx.fillRect(ix-2,bodyTop,iw+4,glassH+2);  ctx.globalCompositeOperation='lighter';  g=ctx.createRadialGradient(x0,bodyBot+glassH*.05,4,x0,bodyBot+glassH*.05,glassH*.55);  g.addColorStop(0,col([255,150,60],[255,195,115],.5,.5*p));  g.addColorStop(1,'rgba(255,120,50,0)');  ctx.fillStyle=g;ctx.fillRect(ix,bodyTop,iw,glassH);  ctx.globalCompositeOperation='source-over';  ctx.fillStyle=`rgba(255,240,220,${.10+.12*power})`;  for(const b of bubbles){ctx.beginPath();ctx.arc(b.x,b.y,b.r,0,TAU);ctx.fill();}  updateField();  ctx.drawImage(field,ix,iy,iw,ih);  ctx.restore();  ctx.drawImage(shell,0,0,W,H);  drawSwitch();  if(hintA>.01){    ctx.font='500 13px -apple-system,"Segoe UI",system-ui,sans-serif';    ctx.textAlign='center';    ctx.fillStyle=`rgba(235,235,255,${.6*hintA})`;    ctx.fillText('tap the switch',x0,Math.max(26,capTop-14));  }}function frame(ts){  const now=ts/1000;  let dt=now-lastT;lastT=now;  if(dt>.05)dt=.05;if(dt<0)dt=0;  step(dt);render();  requestAnimationFrame(frame);}function resize(){  const old=L;  computeLayout();  buildLUT(power);  buildBackground();buildShell();buildField();  if(old){    const sx=L.bulgeHalf/old.bulgeHalf,sy=L.glassH/old.glassH;    for(const b of blobs){b.x=L.x0+(b.x-old.x0)*sx;b.y=L.bodyTop+(b.y-old.bodyTop)*sy;b.r*=sx;}  }else initBlobs();  initBubbles();}function toggle(){on=!on;toggled=true;}function hitSwitch(x,y){  const b=L.swBox;  return b&&x>=b.x&&x<=b.x+b.w&&y>=b.y&&y<=b.y+b.h;}cv.addEventListener('pointerdown',e=>{  const r=cv.getBoundingClientRect();  if(hitSwitch(e.clientX-r.left,e.clientY-r.top))toggle();});cv.addEventListener('contextmenu',e=>e.preventDefault());window.addEventListener('keydown',e=>{  if(e.code==='Space'){e.preventDefault();toggle();}});window.addEventListener('resize',resize);glowSpr=makeGlowSprite();blobSpr=makeBlobSprite();resize();requestAnimationFrame(frame);</script></body></html>