SOURCE / PINNED RELEASE
Made of little things.
Aurora
- Release
- 5f32c94b13cc…
- Author-recorded commit
- Not provided
- License
- Check the original source
- Author’s source link
- Open external source ↗May change independently of this release
The hash-verified playable HTML, which may contain bundled or minified code. This view does not execute it.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>Aurora</title>
<style>
html,body{height:100%;margin:0;overflow:hidden}body{background:#101a32}
canvas{display:block;width:100%;height:100%}
</style>
</head>
<body>
<canvas role="img" aria-label="Aurora"></canvas>
<script>
const canvas=document.querySelector('canvas'),ctx=canvas.getContext('2d',{alpha:false});
const back=document.createElement('canvas'),bg=back.getContext('2d',{alpha:false});
const reduced=matchMedia('(prefers-reduced-motion: reduce)'),dark=matchMedia('(prefers-color-scheme: dark)');
const TAU=Math.PI*2,clamp=(x,a=0,b=1)=>Math.max(a,Math.min(b,x));
const rand=n=>{const x=Math.sin(n*127.1+32.4)*43758.545;return x-Math.floor(x)};
const rgba=(rgb,a)=>'rgba('+rgb+','+clamp(a)+')';
let night=dark.matches,themeBg='',w=1,h=1,unit=1,time=0,last=0,raf=0,inView=false,parked=false;
let flow=0,target=0,checked=0,retryAt=0,handle;
const recent=new Map(); // At most 100 public event IDs and timestamps, never note content.
function visible(){return !parked&&inView&&!document.hidden&&canvas.clientWidth>0&&canvas.clientHeight>0}
function updateTarget(){
const now=Date.now()/1000;
for(const [id,at] of recent)if(at<now-60)recent.delete(id);
target=1-Math.exp(-recent.size/18);
}
function watch(){
if(handle||!visible()||reduced.matches||performance.now()<retryAt||!window.napplet?.relay?.subscribe)return;
try{
const sub=window.napplet.relay.subscribe({kinds:[1],since:Math.floor(Date.now()/1000)-60,limit:100});
handle=sub;
sub.onEvent(({event}={})=>{
if(handle!==sub||!visible()||!event||event.kind!==1||typeof event.id!=='string'||!/^[a-f0-9]{64}$/.test(event.id))return;
const now=Date.now()/1000,at=event.created_at;
if(!Number.isInteger(at)||at<now-60||at>now+5||recent.has(event.id))return;
recent.set(event.id,at);
if(recent.size>100){let oldest;for(const [id,t] of recent)if(!oldest||t<oldest[1])oldest=[id,t];recent.delete(oldest[0])}
});
sub.onClosed(()=>{if(handle!==sub)return;handle=undefined;recent.clear();target=0;retryAt=performance.now()+30000});
}catch{stopWatch();retryAt=performance.now()+30000}
}
function stopWatch(){
const sub=handle;handle=undefined;sub?.close();recent.clear();target=0;checked=0;retryAt=0;
}
function theme(t){
const color=t?.colors?.background;
if(/^#[0-9a-f]{6}$/i.test(color||'')){themeBg=color;const v=[1,3,5].map(i=>parseInt(color.slice(i,i+2),16));night=v[0]*.2126+v[1]*.7152+v[2]*.0722<120}
else if(!themeBg)night=dark.matches;
const lang=t?.lang||navigator.language;canvas.setAttribute('aria-label',lang.startsWith('ja')?label[1]:label[0]);
prepare();invalidate();
}
function resize(){
const r=canvas.getBoundingClientRect();if(!r.width||!r.height)return;
const scale=Math.min(devicePixelRatio||1,1.5,Math.sqrt(450000/(r.width*r.height)));
w=Math.max(1,Math.floor(r.width*scale));h=Math.max(1,Math.floor(r.height*scale));unit=Math.min(w,h);
canvas.width=w;canvas.height=h;back.width=w;back.height=h;prepare();invalidate();
}
function stop(){cancelAnimationFrame(raf);raf=0;last=0;stopWatch()}
function frame(now){
raf=0;if(!visible())return;
if(reduced.matches){paint();return}
// Draw at most ~30 fps; keep time continuous and avoid a resume jump.
if(!last||now-last>=32){
const dt=last?Math.min(.15,(now-last)/1000):0;last=now;time+=dt;
if(now>=checked){checked=now+1000;watch();updateTarget()}
flow+=(target-flow)*(1-Math.exp(-dt/12));paint();
}
raf=requestAnimationFrame(frame);
}
function invalidate(){if(visible()&&!raf)raf=requestAnimationFrame(frame)}
function visibility(){stop();if(reduced.matches)flow=0;if(visible())invalidate()}
function start(){
new ResizeObserver(resize).observe(document.body);
new IntersectionObserver(([e])=>{const next=e.isIntersecting&&e.intersectionRatio>0;if(next!==inView){inView=next;visibility()}}).observe(canvas);
document.addEventListener('visibilitychange',visibility);
window.addEventListener('pagehide',()=>{parked=true;stop()});
window.addEventListener('pageshow',()=>{parked=false;visibility()});
reduced.addEventListener('change',visibility);
dark.addEventListener('change',()=>{if(!themeBg)theme({})});
window.napplet?.theme?.get().then(theme,()=>{});window.napplet?.theme?.onChanged(theme);
theme({});resize();
}
const label=['Slow curtains of northern light','ゆっくり揺れるオーロラ'];
function prepare(){
const stops=night?['#090f25','#111f3c','#183b4d']:['#23334f','#435d7b','#698c9a'];
let g=bg.createLinearGradient(w*.26,0,w*.65,h);g.addColorStop(0,stops[0]);g.addColorStop(.55,stops[1]);g.addColorStop(1,stops[2]);bg.fillStyle=g;bg.fillRect(0,0,w,h);
g=bg.createRadialGradient(w*.46,h*.68,0,w*.46,h*.68,Math.max(w,h)*.75);
g.addColorStop(0,night?'rgba(57,142,142,.19)':'rgba(172,216,204,.17)');g.addColorStop(1,'rgba(57,142,142,0)');bg.fillStyle=g;bg.fillRect(0,0,w,h);
}
function curve(x,k){
const phase=time*.048+k*1.7;
return [.65,.47,.36][k]+[.085,.070,.054][k]*Math.sin(x*5.9+phase)+.028*Math.sin(x*13.7-phase*.65+k)+.008*Math.sin(x*29+phase);
}
const veil=document.createElement('canvas'),light=veil.getContext('2d');
function curtain(k){
const ink=['112,250,174','83,218,223','178,154,248'][k];
const intensity=[.83,.59,.42][k]*(.76+.62*flow),height=[.49,.42,.37][k]*veil.height;
// A continuous low-resolution light field; neighboring columns interpolate
// into soft folds when scaled onto the scene, rather than drawing hard rays.
for(let i=0;i<veil.width;i++){
const x=(i+.5)/veil.width,y=curve(x,k)*veil.height;
const fold=.5+.5*Math.sin(x*24+time*.14+k*2),fine=.5+.5*Math.sin(x*67-time*.1+k);
const grain=.5+.5*Math.sin(x*149+1.6*Math.sin(x*13)+time*.08);
const length=height*(.70+.24*fold+.07*fine),power=intensity*(.15+.47*fold**1.7+.13*fine+.05*grain);
const top=y-length,bottom=y+length*.18;
const g=light.createLinearGradient(0,top,0,bottom);
g.addColorStop(0,rgba(ink,0));g.addColorStop(.30,rgba(ink,power*.11));g.addColorStop(.60,rgba(ink,power*.47));g.addColorStop(.81,rgba(ink,power*.95));g.addColorStop(.88,rgba(ink,power));g.addColorStop(1,rgba(ink,0));
light.fillStyle=g;light.fillRect(i,top,1,bottom-top);
}
}
function paint(){
ctx.drawImage(back,0,0);
const vw=Math.max(112,Math.min(224,Math.round(w/3))),vh=Math.max(80,Math.min(200,Math.round(vw*h/w)));
if(veil.width!==vw||veil.height!==vh){veil.width=vw;veil.height=vh}
light.clearRect(0,0,vw,vh);light.globalCompositeOperation='screen';
for(let k=2;k>=0;k--)curtain(k);
ctx.globalCompositeOperation='screen';ctx.drawImage(veil,0,0,w,h);ctx.globalCompositeOperation='source-over';
}
start();
</script>
</body>
</html>
