← Copper Cathedral v1

index.html

<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>Copper Cathedral</title>
<style>
html,body{margin:0;height:100%;background:#050302;overflow:hidden;font-family:monospace}
#c{position:fixed;inset:0;width:100%;height:100%;display:block}
#splash{position:fixed;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;
background:radial-gradient(ellipse at 50% 60%,#1a0d04 0%,#050302 70%);color:#ffb46b;text-align:center;z-index:2;cursor:pointer}
#splash h1{margin:0 0 6px;font-size:clamp(28px,6vw,64px);letter-spacing:.18em;color:#ffd9a0;text-shadow:0 0 18px #ff7a00,0 0 60px #ff3c00}
#splash p{margin:4px 0;color:#c98a4b;font-size:13px;letter-spacing:.12em}
#go{margin-top:18px;background:transparent;border:1px solid #ff9a3c;color:#ffd9a0;padding:12px 42px;
font:inherit;font-size:16px;letter-spacing:.3em;cursor:pointer}
#go:disabled{opacity:.35;cursor:wait}
#go:not(:disabled):hover{background:#ff7a00;color:#000}
#hint{position:fixed;left:8px;bottom:6px;color:#7a5230;font-size:11px;letter-spacing:.08em;z-index:2;pointer-events:none}
</style></head><body>
<canvas id="c"></canvas>
<div id="splash"><h1>COPPER CATHEDRAL</h1><p>A TINY HYMN FOR COMPO.TV &middot; 1 FILE &middot; NO ASSETS</p><p id="st">WARMING UP THE ORGAN…</p><button id="go" disabled>LOADING</button><p>CLICK / TAP / KEY = SOUND ON &middot; F OR DOUBLE-CLICK = FULLSCREEN</p></div>
<div id="hint">F fullscreen &middot; M mute</div>
<script>
(()=>{const q=new URLSearchParams(location.search);const MUTED=q.get("mute")==="1";
const cv=document.getElementById("c"),gl=cv.getContext("webgl",{antialias:false,alpha:false});
const splash=document.getElementById("splash"),go=document.getElementById("go"),st=document.getElementById("st");
if(!gl){st.textContent="WEBGL UNAVAILABLE";return;}
// --- fullscreen ---
function fs(){if(document.fullscreenEnabled&&!document.fullscreenElement){try{document.documentElement.requestFullscreen()}catch(e){}}}
addEventListener("keydown",e=>{if(e.key==="f"||e.key==="F")fs();if(e.key==="m"||e.key==="M")toggleMute();});
cv.addEventListener("dblclick",fs);
// --- shader: tunnel + copper bars + plasma, synced to audio clock ---
const VS="attribute vec2 p;void main(){gl_Position=vec4(p,0.,1.);}";
const FS=`precision mediump float;uniform vec2 r;uniform float t;uniform float b;
float h(vec2 p){return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453);}
void main(){vec2 uv=(gl_FragCoord.xy-.5*r)/r.y;float a=atan(uv.y,uv.x);float d=length(uv);
float tun=.35/abs(d+.12+.08*sin(a*3.-t*.7));float rings=fract(d*6.-t*.9-a*.5);
float glow=smoothstep(.0,.9,rings)*smoothstep(1.,.2,rings);
vec3 col=vec3(.02,.01,.005);
col+=vec3(1.,.42,.08)*tun*.35*(.6+.4*sin(b*3.14159));
col+=vec3(1.,.75,.35)*glow*.5;
float bars=0.;for(float i=0.;i<4.;i++){float y=sin(t*(.6+i*.23)+i*1.7+a*.3)*.6;float w=fwidth(uv.y)*2.+0.015;
bars+=smoothstep(w,0.,abs(uv.y-y*.5))*(.5+.5*sin(t*2.+i*2.));}
col+=vec3(.9,.5,.15)*bars*.12;
float pl=sin(uv.x*8.+t*1.3)*sin(uv.y*7.-t);col+=vec3(.2,.05,.0)*pl*.15;
float vg=smoothstep(1.4,.3,d);col*=mix(.45,1.15,vg);
col+= (h(gl_FragCoord.xy)-.5)*.05;
float g=dot(col,vec3(.299,.587,.114));col=mix(vec3(g)*vec3(1.,.85,.6),col,.85);
gl_FragColor=vec4(col,1.);}`;
function sh(t,s){const o=gl.createShader(t);gl.shaderSource(o,s);gl.compileShader(o);return o;}
const pr=gl.createProgram();gl.attachShader(pr,sh(gl.VERTEX_SHADER,VS));gl.attachShader(pr,sh(gl.FRAGMENT_SHADER,FS));
gl.linkProgram(pr);gl.useProgram(pr);
const buf=gl.createBuffer();gl.bindBuffer(gl.ARRAY_BUFFER,buf);
gl.bufferData(gl.ARRAY_BUFFER,new Float32Array([-1,-1,3,-1,-1,3]),gl.STATIC_DRAW);
const loc=gl.getAttribLocation(pr,"p");gl.enableVertexAttribArray(loc);gl.vertexAttribPointer(loc,2,gl.FLOAT,false,0,0);
const ur=gl.getUniformLocation(pr,"r"),ut=gl.getUniformLocation(pr,"t"),ub=gl.getUniformLocation(pr,"b");
// --- audio: tiny techno chapel, rendered ahead in blocks ---
let AC=null,master=null,musicGain=null,muted=MUTED,beat=0,nextT=0,step=0,started=false,t0=0;
function toggleMute(){muted=!muted;if(master)master.gain.value=muted?0:.9;}
function audio(){AC=new (window.AudioContext||window.webkitAudioContext)();
master=AC.createGain();master.gain.value=muted?0:.9;master.connect(AC.destination);
musicGain=AC.createGain();musicGain.gain.value=.8;musicGain.connect(master);
// simple feedback delay = cathedral
const dl=AC.createDelay(1);dl.delayTime.value=.375;const fb=AC.createGain();fb.gain.value=.35;
const f2=AC.createBiquadFilter();f2.type="lowpass";f2.frequency.value=2200;
musicGain.connect(dl);dl.connect(f2);f2.connect(fb);fb.connect(dl);dl.connect(master);
nextT=AC.currentTime+.1;t0=nextT;setInterval(sched,80);}
function note(f,t,d,type,g,slide){if(!AC)return;const o=AC.createOscillator(),e=AC.createGain();
o.type=type||"sawtooth";o.frequency.setValueAtTime(f,t);if(slide)o.frequency.exponentialRampToValueAtTime(slide,t+d);
e.gain.setValueAtTime(0,t);e.gain.linearRampToValueAtTime(g||.2,t+.01);e.gain.exponentialRampToValueAtTime(.0008,t+d);
o.connect(e);e.connect(musicGain);o.start(t);o.stop(t+d+.05);}
function kick(t){const o=AC.createOscillator(),e=AC.createGain();o.type="sine";
o.frequency.setValueAtTime(150,t);o.frequency.exponentialRampToValueAtTime(40,t+.12);
e.gain.setValueAtTime(.9,t);e.gain.exponentialRampToValueAtTime(.001,t+.24);
o.connect(e);e.connect(musicGain);o.start(t);o.stop(t+.3);}
function hat(t,open){const b=noiseBuf(),s=AC.createBufferSource();s.buffer=b;
const f=AC.createBiquadFilter();f.type="highpass";f.frequency.value=7000;
const e=AC.createGain();const d=open?.28:.05;e.gain.setValueAtTime(open?.18:.12,t);
e.gain.exponentialRampToValueAtTime(.001,t+d);s.connect(f);f.connect(e);e.connect(musicGain);s.start(t);s.stop(t+d+.02);}
let _nb=null;function noiseBuf(){if(_nb)return _nb;const b=AC.createBuffer(1,AC.sampleRate*.3,AC.sampleRate);
const d=b.getChannelData(0);for(let i=0;i<d.length;i++)d[i]=Math.random()*2-1;_nb=b;return b;}
const bass=[55,0,55,0,65.4,0,55,0,49,0,49,0,58.3,0,73.4,0];
const lead=[220,261.6,329.6,440,329.6,261.6,220,196,220,261.6,329.6,523.25,440,329.6,261.6,246.9];
function sched(){if(!AC||!started)return;while(nextT<AC.currentTime+.35){const s=step%16;
kick(nextT);if(s%2===0)note(110, nextT,.18,"square",.10);
if(bass[s])note(bass[s],nextT,.22,"sawtooth",.22);
if(s%4===2)hat(nextT,false);if(s%16===14)hat(nextT,true);
if(s%2===1)note(lead[(step>>1)%16]*2,nextT,.16,"triangle",.07);
if(s===0&&((step>>4)%4===3))note(440,nextT,.5,"sawtooth",.06,880);
beat=(step/4)%4;nextT+=.1875;step++;}}
// --- main loop: sync visuals to audio clock, report fps ---
let last=performance.now(),frames=0,fpsT=0,fps=60,firstFrameAt=0,firstSoundAt=0,w=0,h=0,dpr=1;
function resize(){dpr=Math.min(devicePixelRatio||1,2);
const slow=fps<40&&w>0;dpr=slow?1:dpr;
w=Math.floor(innerWidth*dpr);h=Math.floor(innerHeight*dpr);
if(cv.width!==w||cv.height!==h){cv.width=w;cv.height=h;gl.viewport(0,0,w,h);}}
addEventListener("resize",resize);resize();
function nowT(){return (AC&&started)?AC.currentTime-t0:performance.now()/1000;}
function frame(){requestAnimationFrame(frame);resize();
const t=nowT();gl.uniform2f(ur,w,h);gl.uniform1f(ut,t);gl.uniform1f(ub,beat+(AC?((AC.currentTime-nextT+.1875*4)/.75%1):0));
gl.drawArrays(gl.TRIANGLES,0,3);
const n=performance.now();frames++;if(!firstFrameAt&&started)firstFrameAt=n;
if(n-fpsT>500){fps=frames*1000/(n-fpsT);frames=0;fpsT=n;
try{parent.postMessage({compo:{fps:Math.round(fps*10)/10,ms:Math.round((performance.now()-last)*10)/10}},"*");}catch(e){}}
last=n;}
requestAnimationFrame(frame);
// --- blob worker: builds copper palette off-thread (keeps main thread drawing) ---
try{const wsrc="onmessage=e=>{let p=[];for(let i=0;i<256;i++){p.push([255,120+Math.floor(100*Math.sin(i*.1)),40]);}postMessage(p)}";
const wu=URL.createObjectURL(new Blob([wsrc],{type:"text/javascript"}));
const wk=new Worker(wu);wk.onmessage=()=>{st.textContent="READY — PRESS TO ENTER";go.disabled=false;go.textContent="▶ RUN";};
wk.postMessage(1);setTimeout(()=>{if(go.disabled){go.disabled=false;go.textContent="▶ RUN";st.textContent="READY — PRESS TO ENTER";}},1500);
}catch(e){go.disabled=false;go.textContent="▶ RUN";st.textContent="READY — PRESS TO ENTER";}
// --- start on first press (own start button => audio inside gesture) ---
function start(e){if(e)e.preventDefault();if(started){fs();return;}started=true;fs();
try{if(!AC)audio();if(AC.state==="suspended")AC.resume();}catch(err){}
if(AC)firstSoundAt=performance.now();
splash.style.display="none";}
go.addEventListener("click",start);splash.addEventListener("click",start);
addEventListener("keydown",function k(e){start();removeEventListener("keydown",k);});
})();
</script></body></html>