<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>ECLIPSE</title>
<meta name=viewport content="width=device-width,initial-scale=1">
<style>html,body{margin:0;height:100%;background:#000;overflow:hidden}canvas{display:block;width:100vw;height:100vh;cursor:pointer}</style>
</head>
<body>
<canvas id=c></canvas>
<script>
/* ECLIPSE - two of them, as they happened in 2019.
It opens outside the galaxy, falls in to where the Sun is, and backs away from the Milky Way until the Earth comes into the frame.
21 January: the Moon crosses the Earth's shadow and turns red; round to its far side, where the Earth is a black disc ringed
with every sunset at once. Six months of orbits. 2 July: the Moon's shadow crosses the Pacific and comes ashore in Chile;
from the mountain of Cerro Tololo the Sun thins, breaks into beads and goes out, and for 124 seconds there is the corona -
seen as a camera sees it, one exposure after another, and then all of them together.
Sun, Moon and shadows are placed from the published elements of the two eclipses, so the clock on the screen is the real one.
The coastlines, the city lights, 225 stars and the seas of the Moon are tables typed in by hand. The soundtrack is
synthesised as it plays: ninety beats a minute, a drum machine and a bass. Every cut is on a beat; the big ones flicker in
like a shutter speeding up. No assets, no dependencies.
Keys: F fullscreen. S steady: no flicker. Drop an audio file to use your own music. */
(()=>{
'use strict';
/* ---------------- synth (runs inside an AudioWorklet) ---------------- */
function SYN(sr){
// The cuts, in bars: the picture reads them from here, because the synth has to click on every one. MAJ are the big cuts, which are
// run up to by blinks at the beats RMP of the bar before. BRK: the bar where nine exposures are taken, one a beat.
const CUT=[0,4,6,8,10,12,14,16,17,18,19,20,22,24,26,28,30,32,36,38,40,42,44,45,46,47,48,50,52,54,56,58.25,60,62,64,68],MAJ=[8,16,24,32,36,44,48,60,64],BRK=56,
RMP=[0,1,2,2.5,3,3.25,3.5,3.625,3.75,3.875,4];
if(!sr)return{CUT,MAJ,BRK,RMP};
const TAU=6.283185307179586,T=1/sr,S16=sr/6,NST=68*16,mf=n=>440*2**((n-69)/12),dc=s=>Math.exp(-1/(sr*s));
let rs=22222;const rnd=()=>{rs^=rs<<13;rs^=rs>>>17;rs^=rs<<5;return(rs>>>0)/2147483648-1};
// TPT state variable filter: returns low-pass, leaves band-pass in s[2]
const svf=(s,x,fc,k)=>{const g=Math.tan(Math.PI*Math.min(fc,sr*.45)*T),h=1/(1+g*(g+k)),v3=x-s[1],v1=h*s[0]+g*h*v3,v2=s[1]+g*h*s[0]+g*g*h*v3;s[0]=2*v1-s[0];s[1]=2*v2-s[1];s[2]=v1;return v2};
const saw=(p,d)=>{let v=2*p-1;if(p<d){const t=p/d;v-=t+t-t*t-1}else if(p>1-d){const t=(p-1)/d;v-=t*t+t+t+1}return v};
// Ninety beats a minute, F minor: a drum machine, a clap, a cowbell, and a bass that is meant to be felt - a sine at the note itself
// under a filtered saw, pushed into a soft clip, ducking under each kick. Over it a thin pulse-wave lead with an echo, stabs, and for
// the two totalities a choir that is really saws through two formants. The cuts of the picture click like a shutter.
// The bass, a step at a time: [note, how many steps, accent]. A: two bars with air in them. B: the same root, rolling.
const BA=[[29,2],0,0,[29,1],0,0,[41,1,1],0,0,[39,1],[41,1],[29,2],0,0,[32,1],[34,1],[36,2],0,0,[36,1],0,0,[39,1,1],0,0,[36,1],0,[34,1],[32,2],0,[31,1],[28,1]],
BB=[29,29,41,29,32,29,34,29,36,29,39,29,41,39,36,34,29,29,41,29,32,29,34,29,37,29,36,29,34,32,31,28],
BS=[[29,10],0,0,0,0,0,0,0,0,0,[32,6],0,0,0,0,0,[34,8],0,0,0,0,0,0,0,[36,4],0,0,0,[39,4],0,0,0], // the slow one, under the red Moon
BR=[29,32,34,36,39,41,44,46,48], // one for each exposure, climbing
KA=['x..x......x.....','x..x...x..x.....'],KB=['x.....x...x.....','x..x..x...x...x.'],
CB='...x..x....x..x.',
// the lead, a sixteenth at a time over four bars: a note, 0 to hold it, -1 to let go. H1 the tune, H2 slow under the red Moon, H3 for the corona
H1=[72,0,0,-1,75,0,-1,77,0,0,0,0,-1,0,0,0, 0,0,80,0,79,0,75,0,0,0,-1,0,72,0,0,-1, 72,0,0,-1,75,0,-1,77,0,0,80,0,0,0,0,0, 0,0,82,0,80,0,77,0,0,0,0,0,-1,0,0,0],
H2=[84,0,0,0,0,0,0,0,0,0,0,0,82,0,0,0, 80,0,0,0,0,0,0,0,79,0,0,0,0,0,0,0, 77,0,0,0,0,0,0,0,0,0,0,0,80,0,0,0, 79,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0],
H3=[77,0,0,0,80,0,0,0,84,0,0,0,0,0,82,0, 80,0,0,0,0,0,79,0,80,0,0,0,0,0,0,0, 77,0,0,0,80,0,0,0,84,0,0,0,0,0,87,0, 85,0,0,0,0,0,84,0,0,0,0,0,82,0,0,0],
// chords: Fm9, Cm7, D flat major 7, E flat
CH=[[53,56,60,63,67],[48,51,55,58,62],[49,53,56,60,65],[51,55,58,63,67]];
// when the shutter fires, in samples
const CK=[];for(const c of CUT)CK.push([c*16,1]);for(const m of MAJ)for(let k=1;k<10;k++)CK.push([m*16-16+RMP[k]*4,.45+.06*k]);for(let k=1;k<9;k++)CK.push([BRK*16+k*4,1]);
CK.sort((a,b)=>a[0]-b[0]);
let pos=0,nx=0,st=-1,mg=1,ck=0,off=0,
kt=-1,kp=0,kv=1,duck=0,
se=0,sne=0,sp1=0,sp2=0,ct=-1,cv=0,
he=0,hd=.99,hv=0,
ce=0,cp1=0,cp2=0,
tt=-1,tf=200,tp=0,
bf=43.65,bft=43.65,bp=0,bg=0,be=0,bfe=0,bac=0,bcut=1,bglide=1,
lf=523,lft=523,lp=0,lg=0,le=0,lv=0,lpw=0,
ste=0,
plv=0,plt=0,pcut=700,pct=700,choir=0,cht=0,
dlv=0,dlt=0,dp1=0,
ckd=0,cke=0,ckp=0,
st1=-1,stv=1,
sct=-1,scd=1,scp=0,
it=-1,ip=0,ilv=0,
ris=0,ri=0,rph=0,
di=0,dlp=0,drp=0;
const F=()=>new Float64Array(3),bf1=F(),bf2=F(),sn=F(),cl1=F(),hh=F(),cbf=F(),ldf=F(),stf=F(),pL=F(),pR=F(),f1=F(),f2=F(),rz=F(),im=F(),sc1=F(),sc2=F(),ckf=F(),
pf=new Float64Array(5),pt=new Float64Array(5),pp=new Float64Array(10),sf=new Float64Array(4),sph=new Float64Array(4),
bl=new Float64Array(24); // six bells: phase, frequency, level, pan
let bn=0;
const hdc=dc(.03),hdo=dc(.2),ckc=dc(.004);
// stereo delay (a dotted eighth) and a Freeverb-style reverb
const DN=Math.round(S16*3),dL=new Float32Array(DN),dR=new Float32Array(DN);
const mk=(a,o)=>a.map(n=>new Float32Array(Math.round((n+o)*sr/44100)));
const cl=[1116,1188,1277,1356,1422,1491,1557,1617],al=[556,441,341,225];
const cL=mk(cl,0),cR=mk(cl,23),aL=mk(al,0),aR=mk(al,23),ci=new Int32Array(16),ai=new Int32Array(8),cf=new Float64Array(16);
const verb=(x,C,A,o)=>{let y=0;
for(let j=0;j<8;j++){const b=C[j],q=o*8+j,i=ci[q],v=b[i];cf[q]=v*.75+cf[q]*.25;b[i]=x+cf[q]*.88;ci[q]=i+1==b.length?0:i+1;y+=v}
for(let j=0;j<4;j++){const b=A[j],q=o*4+j,i=ai[q],v=b[i];b[i]=y+v*.5;ai[q]=i+1==b.length?0:i+1;y=v-y}
return y};
const bass=(n,l,a,gl)=>{bft=mf(n);if(!gl||bg<=0){bf=bft*1.12;be=0}bg=l*S16*.92;bfe=1;bac=a?1:0};
const lead=n=>{if(n<0){lg=0;return}lft=mf(n);if(lg<=0){lf=lft;lv=0}lg=1};
const chord=k=>{const c=CH[k];for(let j=0;j<5;j++)pt[j]=mf(c[j])};
chord(0);pf.set(pt);
const trig=()=>{
const s=st&15,bar=st>>4,i32=(bar&1)*16+s,i64=(bar&3)*16+s,x=bar+s/16;
// which part of the tune. 0 the galaxy, 1 drums come in, 2 the groove, 3 half-time under the red Moon, 4 rolling, 5 six months, 6 the groove again,
// 7 the light going, 8 totality, 9 nine exposures, 10 all together, 11 the diamond ring, 12 light again, 13 out
const sec=bar<4?0:bar<8?1:bar<20?2:bar<24?3:bar<32?4:bar<36?5:bar<44?6:bar<48?7:bar<56?8:bar<58?9:bar<60?10:bar<62?11:bar<64?12:13;
const grv=sec==2||sec==6||sec==12||sec==13&&bar<66,roll=sec==4||sec==8||sec==10;
// drums
let kp_=null;
if(sec==1||grv)kp_=KA[bar&1];else if(roll)kp_=KB[bar&1];else if(sec==3)kp_='x.........x.....';else if(sec==5)kp_=bar&1?'..........x.....':'x...............';
else if(sec==7||sec==9)kp_='x...x...x...x...';
if(kp_&&kp_[s]=='x'){kt=0;kp=0;kv=sec==5?.7:1;duck=1}
if(sec==0&&s==0){kt=0;kp=0;kv=.5}
const bk=sec==1||grv||roll||sec==7||sec==9;
if(bk&&(s==4||s==12)){se=1;sne=1;ct=0;cv=sec==9?.6:1}
if(sec==3&&s==8){se=1;sne=1;ct=0;cv=1}
if(sec==5&&s==12){ct=0;cv=.7}
if(bar==46&&s>11){se=.35+.1*(s-12);sne=.5} // the snare runs up to totality
if(bar==47){se=.3+.045*s;sne=.4+.03*s}
if(sec!=0&&sec!=11&&!(sec==13&&bar>65)){const open=(s==2||s==10)&&(grv||roll)&&bar>=12,q=sec==3||sec==5;
if(!q||!(s&1)){he=1;hd=open?hdo:hdc;hv=(s&3)==0?.5:(s&1)?.2:.36;if(q)hv*=.6;if(sec==1&&bar<5)hv*=.5}}
if((grv&&bar>=12||roll)&&CB[s]=='x'){ce=1}
// a run down the toms before each new part
if((bar==7||bar==15||bar==23||bar==31||bar==35||bar==43||bar==55)&&s>=12){tt=0;tf=[330,262,196,147][s-12];tp=0}
// bass
if(sec==1){if(s==0)bass(29,6,0);if(bar==7&&s>=12&&s!=13)bass([28,0,29,31][s-12],1,1)}
else if(grv||sec==5){const e=BA[i32];if(e)bass(e[0],e[1],e[2])}
else if(roll){const n=BB[i32];bass(n,.8,n!=29||!(s&3))}
else if(sec==3){const e=BS[i32];if(e)bass(e[0],e[1],0,1)}
else if(sec==7){if(bar<46){if(!(s&1))bass(s==14?41:29,1.2,s==14)}else bass(s&1?41:29,.8,s&1)}
else if(sec==9){const b=st-BRK*16>>2;if(!(s&3)&&b<9)bass(BR[b],3,1)}
else if(sec==11){if(s==0&&bar==60)bass(29,30,0)}
else if(sec==13&&bar==66&&s==0)bass(29,20,0);
bcut=sec==5?.25+.2*(x-32):sec==1?.5:sec==7?.6+.3*(x-44)/4:1;
// lead
if(sec==2&&bar>=12||sec==6&&bar>=40||sec==12||sec==13&&bar<66||sec==4&&bar>=28){const n=H1[i64];if(n)lead(n)}
else if(sec==3){const n=H2[i64];if(n)lead(n)}
else if(sec==8&&bar>=50||sec==10){const n=H3[i64];if(n)lead(n)}
else if(s==0)lead(-1);
// stabs, on the off-beats
if((grv&&bar>=10||roll)&&(s==10||s==13)&&(bar&1||roll)){const c=CH[roll?[0,0,2,3][bar&3]:bar&1];for(let j=0;j<4;j++)sf[j]=mf(c[j+1]+(roll?0:0));ste=1}
// pad and choir
if(s==0){
plt=sec==0?.5:sec==3?.55:sec==5?.3:sec==8?.75:sec==10?.95:sec==11?.7:sec==13?.5:sec==4&&bar>=28?.5:0;
pct=sec==0?500+250*bar:sec==3?1200:sec==8||sec==10?2600:sec==11?3200:900;
cht=sec==8||sec==10||sec==11||sec==4&&bar>=28?1:0;
chord(sec==3?[0,2,0,3][bar&3]:sec==8||sec==4?[0,0,2,3][bar&3]:sec==10?[2,3][bar&1]:0);
dlt=sec==0?.6:sec==5?.35:sec==11?.4:0;
ckd=sec==0?1:sec==5?.5:sec==13&&bar>65?.6:0;
}
// the needle dragged back and forth, before the beat comes in and through the six months
if(x==3.5||x==7.5||x==33.75||x==35.5||x==67){sct=0;scd=x==7.5||x==35.5?S16*8*T:S16*4*T}
// risers and things that hit
ris=x>=6.5&&x<8||x>=34.5&&x<36||x>=46&&x<48?1:0;
if(s==0&&(bar==8||bar==24||bar==36)){it=0;ip=0;ilv=.6}
if(s==0&&bar==48){it=0;ip=0;ilv=1}
if(s==4&&bar==58||s==0&&bar==60){it=0;ip=0;ilv=.9}
// bells, when the diamond ring comes
if(sec==11&&!(s&1)||sec==10&&s==4&&bar==58){const k=bn%6*4;bn++;bl[k+1]=mf([84,87,89,92,96,91,99,94][(s>>1)+bar&7]);bl[k+2]=.5;bl[k+3]=rnd()*.7}
};
return(L,R)=>{
for(let i=0;i<L.length;i++,pos++){
if(pos>=nx){st++;nx+=S16;if(st==NST){st=0;ck=0;off=pos;mg=1}trig()} // at the end, round again
while(ck<CK.length&&pos-off>=CK[ck][0]*S16){st1=0;stv=CK[ck][1];ck++}
if(st>=NST-8)mg=Math.max(0,mg-T/2.4);
const n=rnd();let l=0,r=0,m=0,rv=0,dly=0;
// kick: a sine falling fast from a click to its note, and a duck for the bass to go under
if(kt>=0){kp+=(47+170*Math.exp(-kt*42))*T;const y=Math.sin(TAU*kp)*Math.exp(-kt*7)*kv+n*Math.exp(-kt*400)*.3*kv;m+=Math.tanh(y*2.2)*.62;kt+=T;if(kt>.6)kt=-1}
duck*=.9994;
// snare and clap
if(se>.001){sp1+=186*T;sp2+=331*T;const y=(Math.sin(TAU*sp1)+.6*Math.sin(TAU*sp2))*sne*.5+(n-svf(sn,n,1400,1.2))*se;sne*=.9982;se*=.99955;m+=y*.2;rv+=y*.13}
if(ct>=0){const e=(ct<.033?Math.exp(-(ct%.011)*260):Math.exp(-(ct-.033)*16))*cv;svf(cl1,n,1150,.7);const y=cl1[2]*e*.75;l+=y*.9;r+=y;rv+=y*.5;ct+=T;if(ct>.5)ct=-1}
// hats
if(he>.001){he*=hd;const y=(n-svf(hh,n,7500,.9))*he*hv*.4;l+=y*.8;r+=y}
// cowbell: two squares that do not agree
if(ce>.001){ce*=.9997;cp1+=540*T;cp2+=800*T;if(cp1>=1)cp1-=1;if(cp2>=1)cp2-=1;svf(cbf,(cp1<.5?1:-1)+(cp2<.5?1:-1),900,.6);const y=cbf[2]*ce*ce*.07;l+=y*.6;r+=y;rv+=y*.2}
// toms
if(tt>=0){tp+=tf*(1+.9*Math.exp(-tt*30))*T;const y=Math.sin(TAU*tp)*Math.exp(-tt*9)*.34;m+=y;rv+=y*.25;tt+=T;if(tt>.5)tt=-1}
// bass
if(bg>0||be>.0005){
bf+=(bft-bf)*.004;bp+=bf*T;if(bp>=1)bp-=1;
if(bg>0){bg--;be+=(1-be)*.01}else be*=.9988;
bfe*=.99975;
const o=saw(bp,bf*T)+(bp<.5?.5:-.5),fc=bf*2+(260+(bac?2300:1150)*bfe)*bcut,
y=svf(bf2,svf(bf1,o,fc,.75),fc,1.1)*.55+(Math.sin(TAU*bp)+.22*Math.sin(2*TAU*bp))*.95;
m+=Math.tanh(y*be*1.5)*.5*(1-.5*duck);
}
// lead: a pulse whose width wanders, sliding between notes
if(lg>0||le>.0005){
lf+=(lft-lf)*.0012;lv+=(1-lv)*.00006;le+=((lg>0?1:0)-le)*(lg>0?.004:.0004);
lp+=lf*(1+.007*lv*Math.sin(pos*T*34))*T;if(lp>=1)lp-=1;lpw=.5+.32*Math.sin(pos*T*1.7);
const y=svf(ldf,saw(lp,lf*T)-saw((lp+lpw)%1,lf*T),1800+2400*le,.8)*le*.085;l+=y;r+=y*.85;dly+=y*.75;rv+=y*.5}
// stabs
if(ste>.001){ste*=.99965;let o=0;for(let j=0;j<4;j++){sph[j]+=sf[j]*T;if(sph[j]>=1)sph[j]-=1;o+=saw(sph[j],sf[j]*T)}
const y=svf(stf,o,500+3800*ste*ste,.7)*ste*.06;l+=y;r+=y*.8;rv+=y*.6;dly+=y*.3}
// pad, and the choir: the same saws through two formants
plv+=(plt-plv)*.00002;pcut+=(pct-pcut)*.00005;choir+=(cht-choir)*.00003;
if(plv>.002){let a=0,b=0;
for(let j=0;j<5;j++){pf[j]+=(pt[j]-pf[j])*.0005;const f=(pf[j]||pt[j])*T;pp[j*2]+=f*.997;pp[j*2+1]+=f*1.004;if(pp[j*2]>=1)pp[j*2]-=1;if(pp[j*2+1]>=1)pp[j*2+1]-=1;
const u=saw(pp[j*2],f),v=saw(pp[j*2+1],f);if(j&1){a+=u;b+=v}else{a+=v;b+=u}}
const x=(a+b)*.5;svf(f1,x,650+60*Math.sin(pos*T*.7),.25);svf(f2,x,1080+90*Math.sin(pos*T*.5),.3);
const c=(f1[2]+f2[2]*.7)*choir*.5,ya=(svf(pL,a,pcut,1.1)*(1-.5*choir)+c)*plv*.085,yb=(svf(pR,b,pcut,1.1)*(1-.5*choir)+c)*plv*.085;
l+=ya;r+=yb;rv+=(ya+yb)*.6}
// a low hum under the quiet parts, and the crackle of a record
dlv+=(dlt-dlv)*.00003;if(dlv>.002){dp1+=43.65*T;if(dp1>=1)dp1-=1;m+=Math.sin(TAU*dp1)*dlv*.3*(1+.3*Math.sin(pos*T*.6))}
if(ckd>0&&Math.abs(rnd())<ckd*.00025){cke=1;ckp=rnd()}
if(cke>.001){cke*=ckc;const y=n*cke*.16;l+=y*(1-ckp);r+=y*(1+ckp);rv+=y*.3}
// the shutter: mirror up, first curtain, second curtain
if(st1>=0){const a=Math.exp(-st1*900),b=st1>.032?Math.exp(-(st1-.032)*700):0;svf(ckf,n*(a+b*.8),2600,.5);
const y=(ckf[2]*1.5+Math.sin(TAU*150*st1)*Math.exp(-st1*90)*.5)*stv*.5;l+=y;r+=y*.9;rv+=y*.35;st1+=T;if(st1>.12)st1=-1}
// a record pulled back and forth under the needle
if(sct>=0){const u=sct/scd,v=Math.sin(TAU*sct*6),a=Math.abs(v);scp+=(150+420*a)*T;if(scp>=1)scp-=1;const x=saw(scp,.01)*.6+n*.5;
svf(sc1,x,500+1300*a,.3);svf(sc2,x,900+2300*a,.35);const y=(sc1[2]+sc2[2])*Math.sqrt(a)*Math.sin(Math.PI*Math.min(1,u*8))*.22;l+=y;r+=y*.7;rv+=y*.3;sct+=T;if(sct>=scd)sct=-1}
// something hits: a falling sub and a burst
if(it>=0){ip+=(38+80*Math.exp(-it*8))*T;
const y=(Math.sin(TAU*ip)*Math.exp(-it*1.8)+svf(im,n,500+4000*Math.exp(-it*6),.8)*Math.exp(-it*3.5)*.8)*ilv;m+=Math.tanh(y*1.4)*.45;rv+=y*.45;it+=T;if(it>3)it=-1}
// riser
ri+=(ris-ri)*(ris?.00012:.004);if(ri>.002){svf(rz,n,300*2**(ri*5),.35);rph+=130*2**(ri*2.4)*T;if(rph>=1)rph-=1;const y=(rz[2]*.28+saw(rph,.01)*.035)*ri*ri;l+=y;r+=y;rv+=y*.4}
// bells
for(let k=0;k<24;k+=4)if(bl[k+2]>.001){bl[k]+=bl[k+1]*T;const y=Math.sin(TAU*bl[k]+1.6*bl[k+2]*Math.sin(TAU*bl[k]*3.01))*bl[k+2]*.07;bl[k+2]*=.99987;l+=y*(1-bl[k+3]);r+=y*(1+bl[k+3]);dly+=y*.6;rv+=y*.7}
// echo
{const a=dL[di],b=dR[di];dlp+=(b-dlp)*.4;drp+=(a-drp)*.4;dL[di]=dly+dlp*.42;dR[di]=drp*.42;if(++di==DN)di=0;l+=a*.55;r+=b*.55;rv+=(a+b)*.12}
// reverb + soft clip
l+=verb(rv*.03+1e-18,cL,aL,0)*1.3;r+=verb(rv*.03+1e-18,cR,aR,1)*1.3;
L[i]=Math.tanh((m+l)*.95)*mg;R[i]=Math.tanh((m+r)*.95)*mg;
}
return pos};
}
/* ---------------- the Earth, the Moon and the stars, drawn by hand ---------------- */
// Coastlines: closed rings of "longitude,latitude", east and north positive. Rough - a degree or so - and smoothed when drawn.
const ring=s=>s.trim().split(/\s+/).map(p=>p.split(',').map(Number));
const LAND=[
// the Americas, from the Darien round South America, up the Pacific coast to Alaska, along the Arctic, Hudson Bay, and down the Atlantic
`-77.4,8.7 -76.8,8 -75.6,9.4 -75.5,10.5 -74.8,11.1 -73.3,11.3 -71.7,12.4 -71.3,11.7 -71.9,11 -71.3,10.9 -70.3,11.5 -70,12.2 -69.6,11.5 -68.4,11.2 -68,10.5
-66.2,10.6 -64.7,10.1 -63,10.7 -61.9,10.7 -62.6,10.2 -61,9.5 -60,8.5 -58.2,6.8 -57,5.9 -55.2,5.9 -52.3,4.9 -51.6,4.3 -50,1.8 -50,.3 -48.4,-.2 -48,-.7 -44.3,-2.5 -41.8,-2.9
-40,-2.8 -38.5,-3.7 -37.2,-4.8 -35.2,-5.3 -34.8,-7.1 -34.9,-8.2 -35.7,-9.7 -37,-10.9 -38.5,-13 -39,-14.8 -39.1,-16.4 -39.2,-17.7 -39.7,-18.5 -40.3,-20.3 -41,-22 -42,-23
-43.2,-23 -44.6,-23.2 -46.3,-24 -48.5,-25.5 -48.5,-27.6 -48.8,-28.5 -50.1,-30 -51.2,-31.2 -52.1,-32.1 -53.4,-33.7 -54.9,-35 -56.2,-34.9 -57.8,-34.5 -58.4,-34 -58.4,-34.6
-57.3,-35.2 -57.4,-36 -56.7,-36.4 -57.5,-38 -58.7,-38.6 -61,-39 -62.2,-38.9 -62.1,-39.9 -62.3,-40.6 -62.8,-41.1 -65,-40.8 -65.1,-41.6 -63.8,-42.1 -63.6,-42.8 -64.3,-42.9
-65,-42.8 -65.1,-43.3 -65.5,-44.9 -67.5,-45.9 -67.6,-46.5 -66.5,-47 -65.8,-47.2 -65.9,-47.8 -67.7,-49.3 -68.5,-50.1 -69.2,-51.6 -68.4,-52.3 -68.6,-52.7 -67.7,-53.8
-66.6,-54.3 -65.2,-54.65 -67.3,-55.9 -69,-55.5 -71,-54.9 -72.5,-54.1 -74.7,-52.7 -75.2,-51.3 -75.5,-50 -75.5,-48 -75.6,-46.7 -74.7,-45.9 -74.4,-45 -74.3,-43.4 -74.2,-42
-73.8,-41.7 -73.8,-40.9 -73.4,-39.8 -73.5,-38.5 -73.7,-37.6 -73.2,-36.8 -72.4,-35.3 -71.7,-33.6 -71.6,-33 -71.5,-31.9 -71.6,-30.3 -71.4,-29.95 -71.4,-29.2 -71.2,-28.5
-70.9,-27.1 -70.6,-26.3 -70.5,-25.4 -70.4,-23.6 -70.6,-23.2 -70.2,-22.1 -70.15,-20.2 -70.3,-18.5 -71.3,-17.6 -72,-17 -72.7,-16.6 -74.3,-15.9 -75.2,-15.4 -76.3,-13.9
-77.1,-12 -77.6,-11.1 -78.6,-9.1 -79,-8.1 -79.9,-6.8 -81.1,-5.8 -81.3,-4.7 -80.5,-3.5 -79.9,-2.6 -81,-2.2 -80.7,-.95 -80.5,-.4 -80,.8 -78.8,1.8 -77.1,3.9 -77.5,5.5
-77.4,6.6 -77.9,7.2 -78.4,8 -78.3,8.5 -79.5,8.95 -80,8.3 -80.4,7.4 -81.1,7.2 -81.7,7.7 -82.9,8.05 -83.3,8.4 -83.7,8.45 -84.3,9.5 -85.1,9.6 -85.8,10.2 -85.7,11.1 -86.6,12.1
-87.5,12.95 -87.7,13.3 -88.8,13.2 -89.8,13.5 -91.5,14 -92.2,14.5 -93.9,16 -95.2,16.2 -96.5,15.65 -98.5,16.3 -99.9,16.85 -101.6,17.6 -102.2,17.95 -104.3,19.05 -105.7,20.4
-105.3,20.7 -105.4,21.6 -106.4,23.2 -107.8,24.4 -109.4,25.6 -109.9,27 -110.9,27.9 -112.2,29 -113.2,30.8 -113.5,31.3 -114.7,31.8 -114.8,31 -114.1,29.6 -113.5,28.9
-112.7,27.9 -112.3,27.2 -111.3,26 -110.6,24.7 -110.3,24.2 -109.5,23.2 -109.9,22.9 -110.3,23.5 -112.1,24.6 -112.3,26 -113.6,26.7 -115.1,27.85 -114.1,28 -114.4,28.8
-115.7,29.9 -116.6,31.85 -117.1,32.6 -118.4,33.9 -120.5,34.45 -121.9,36.6 -122.5,37.8 -123.7,38.95 -124.4,40.4 -124.2,41.8 -124.55,42.8 -124,46.2 -124.7,48.4
-125.6,48.9 -126.5,49.5 -127.9,50.1 -128.4,50.8 -127.5,51.2 -128.2,52.2 -129.5,53.5 -130.4,54.3 -131,55.2 -133.5,55.3 -135.6,57 -136.6,58.2 -139.8,59.5 -144.6,60
-145.8,60.5 -148,60 -149.5,59.7 -151.9,59.2 -151.2,60.5 -150,61.2 -152,60.6 -153.5,59.3 -154.2,58.3 -156.5,57 -158.4,56 -160.5,55.4 -163.4,54.8 -162,55.8 -160.5,56
-158.7,56.8 -157.7,57.6 -157,58.7 -158.5,58.9 -162.1,58.65 -162,59.9 -164.5,60.3 -165.3,61.6 -164.8,62.6 -163,63.1 -161,63.6 -161,64.4 -165.4,64.5 -168.1,65.6
-164,66.5 -162,66.1 -162.6,66.9 -164.5,67.7 -166.8,68.35 -166.2,68.9 -163,69.7 -160,70.6 -156.5,71.4 -152,70.8 -148.5,70.4 -141,69.65 -137,69 -135,69.4 -133,69.4
-129.5,70.1 -128,70.6 -125,69.4 -121,69.8 -115.1,67.8 -110,67.8 -108,66.8 -107.5,68 -104,68 -100,67.8 -96,67.3 -95.5,68.8 -94.5,71.9 -92.5,70.5 -92,69.5 -89.5,69
-88,67.5 -85.5,69.7 -82.5,69.7 -81.3,68.5 -81.5,66.9 -84,66.3 -86.2,66.5 -86,65.5 -87.5,64.5 -88.5,64 -90.7,63.3 -92.1,62.8 -94.1,61.1 -94.6,60 -94.2,58.8 -92.6,57
-87.6,56 -85,55.3 -82.3,55.2 -82.3,53 -80.6,51.3 -79.5,51.5 -78.9,53 -79.8,54.6 -76.5,56.5 -77.6,58 -78.5,59.8 -77.5,61 -77.9,62.6 -75.7,62.3 -73.7,62.4 -72,61.6
-70,61.1 -69.6,60 -69.4,58.9 -68.4,58.2 -66,58.9 -65,59.5 -64.4,60.4 -63.5,59 -62.5,58 -61.7,56.5 -60.3,55.3 -58.5,54.8 -57.3,54 -56,53 -55.7,52 -57.1,51.4 -58.7,51.1
-60,50.2 -63,50.3 -66.4,50.2 -67.5,49.3 -68.5,48.9 -69.5,48 -71.2,46.8 -70,47.5 -68.5,48.5 -67,49 -64.2,48.8 -66.3,48 -65,47.5 -64.9,47 -64.5,46.2 -63.5,45.9 -61.5,45.7
-60.5,47 -59.8,46 -61,45.3 -63.6,44.6 -65.6,43.4 -66.1,43.8 -65.8,44.6 -64.4,45.3 -66.1,45.2 -67,44.8 -68.2,44.3 -69,44 -70.2,43.6 -70.6,42.65 -71,42.3 -70.7,41.95
-70.1,42.05 -69.95,41.65 -70.6,41.55 -71.5,41.4 -71.9,41 -73.5,40.6 -74,40.4 -74.4,39.4 -74.9,38.95 -75.5,39.4 -75.1,38.8 -75.1,38 -75.9,37.1 -76,36.9 -75.5,35.25
-76.5,34.6 -78,33.85 -79.9,32.75 -81.1,32 -81.4,30.3 -80.55,28.45 -80,26.7 -80.15,25.75 -80.4,25.2 -81.1,25.1 -81.8,26.1 -82.7,27.7 -82.7,28.5 -83,29.1 -84,30.1
-85.4,29.7 -86.5,30.4 -87.2,30.35 -88,30.3 -89.4,30.2 -89.2,29 -90.2,29.1 -91.3,29.3 -92.3,29.6 -93.8,29.7 -94.8,29.3 -96,28.6 -97.3,27.7 -97.15,25.95 -97.7,24
-97.8,22.2 -97.3,21 -96.1,19.2 -95.7,18.7 -94.4,18.15 -92.6,18.6 -91.8,18.65 -90.5,19.85 -90.4,21 -89.7,21.3 -88,21.6 -87.1,21.6 -86.8,21.2 -87.4,20.2 -87.7,18.5
-88.2,17.5 -88.6,16.3 -88.9,15.9 -87.9,15.85 -86.8,15.8 -86,16 -85,16 -83.2,15 -83.4,14 -83.8,12 -83.7,10.9 -83,10 -82.2,9.4 -81.2,8.8 -79.9,9.4 -78.9,9.55`,
// Europe, Asia and Africa in one: Gibraltar north to the Arctic, round Asia, Arabia, Africa, and back through the Mediterranean and the Black Sea
`-5.6,36 -6.3,36.5 -7,37.2 -9,37 -8.9,38 -9.5,38.8 -9.4,39.4 -8.7,41.1 -8.9,42.2 -9.3,42.9 -8.4,43.4 -7.7,43.8 -5.7,43.6 -3.8,43.5 -2,43.3 -1.5,43.5 -1.2,44.7 -1.1,45.6
-1.2,46.2 -2.2,47.3 -3.4,47.7 -4.7,48 -4.8,48.4 -4,48.7 -2,48.65 -1.5,48.65 -1.9,49.7 -1.3,49.7 -1.1,49.35 .1,49.5 1.1,49.9 1.6,50.7 1.85,50.95 2.9,51.25 3.6,51.5 4.1,52
4.7,52.95 5.5,53.3 6.9,53.4 8.1,53.7 8.7,53.9 8.8,54.3 8.4,55.5 8.2,56.7 8.6,57.1 10.6,57.75 10.5,57.4 10.9,56.5 10.3,56.2 9.7,55.5 9.8,54.8 10.2,54.4 11.1,54.4 10.9,54
12.1,54.2 13.6,54.6 14.3,53.9 15.6,54.2 17.5,54.8 18.7,54.4 19.9,54.9 21.1,55.7 21,56.5 21.5,57.4 22.6,57.75 23.2,57 24.1,57 24.5,58.4 23.5,58.6 23.5,59 24.8,59.45
28,59.5 30.2,59.9 28.7,60.7 26.9,60.5 25,60.15 23,59.8 22,60.4 21.6,61.5 21.5,63.1 23.1,63.85 25.4,65 24.3,65.8 22.2,65.6 21.2,64.7 20.4,63.7 18.8,63.2 17.4,62.4
17.2,60.7 18.9,59.8 18.5,59.2 17.1,58.7 16.7,57.75 16.4,56.7 15.6,56.1 14.35,55.55 13.2,55.35 12.95,55.6 12.7,56.05 12.8,56.65 11.9,57.7 11.1,58.9 10.6,59.2 10.7,59.9
10.4,59.3 10,59 8,58.1 7,58 5.6,58.9 5.2,60.4 4.9,61.1 5.1,62.2 6.1,62.5 7.7,63.1 9.5,63.7 10,64.2 11.2,64.9 12.2,65.5 14.4,67.3 14,68.2 16.1,69.3 18.9,69.7 20.5,70.2
23.7,70.7 25.8,71.2 27.7,71.1 31.1,70.4 29,70 30,69.7 32.5,69.9 35,69.2 38,68.3 40.5,67.7 41.4,67.2 40.6,66.5 38.5,66.05 36,66.3 34.3,66.7 32.4,67.1 34.8,65 34.8,64.5
36.5,63.9 38.1,63.9 37.3,64.4 36.8,65.15 38.5,64.9 39.8,64.6 40.5,64.5 40.1,65.3 41.5,66.1 42.5,66.5 44,66.2 44.3,66.9 43.3,68.6 46,68.3 46.5,67.7 47.5,67 48.5,67.7
52,68.5 54,68.2 57,68.6 60,68.4 60.5,69.8 64.5,69.3 66,68.5 68,68.3 67.5,69.5 66.8,71 68.5,72.5 70,73 72.5,72.6 73,71 73.7,68.8 74.5,67.5 75,68.5 74.5,70 74.3,72
77.5,72.6 79.5,72 80.5,71 82.5,70.5 80.5,73.5 86,74 87,75.1 93,75.9 98,76.3 104.3,77.7 107,77 112,76.5 113.5,75.5 111,73.9 113.5,73.6 119,73.2 123.5,73.5 127,73.5
129.5,72.2 129,71.6 130,71 132.5,71.6 135.5,71.5 137,71.4 139.5,72.2 140.7,72.8 143,72.5 146,72.2 150,71.5 152.5,70.9 157,71 161,69.5 163,69.7 168,70 170,69 170.3,69.7
170.5,70.1 176,69.8 180,69 184,68 188,66.9 190.3,66.1 189,65.5 186.7,64.4 182.5,65.4 180.5,65 177.5,64.7 179.5,62.5 175,61.8 172,60.9 170.4,59.9 166,60.3 163.5,59
162.5,57.8 162.8,56.2 162,54.8 160,53.1 158.8,52.9 156.7,50.9 156,52.5 155.5,55 155.6,57 157,58 159,59 161.5,60.3 163.5,61.7 164.5,62.4 162.5,61.5 160.6,60.7
160.4,61.9 157,61.6 155,59.4 153,59.1 150.8,59.5 148.5,59.3 143,59.3 140.5,58 138.2,56.4 137,54.3 139.5,54 141,53.2 141.3,52.2 140.8,51.5 140.3,49 138.5,46.5 136,44.3
133,42.8 131.9,43.1 130.7,42.6 129.8,41.8 129.7,40.8 127.6,39.8 127.4,39.2 128.4,38.6 129,37.8 129.5,36 129.1,35.1 127.7,34.7 126.3,34.6 126.5,35.6 126.6,37 126,37.7
125,37.9 125.3,38.7 124.4,39.8 121.6,38.9 122.2,40.7 121,40.9 119.6,39.9 117.8,39 118.5,38.2 119,37.8 119.5,37.1 120.7,37.8 121.4,37.6 122.6,37.4 121.5,36.7 120.4,36.1
119.4,34.7 120.9,33 121.9,31.6 121.9,30.9 120.9,30.3 121.9,29.9 121,28 119.6,26 118.1,24.5 116.7,23.3 114.2,22.3 113.5,22.2 111.8,21.6 110.5,21.2 110.3,20.3 109.7,21.5
109.1,21.5 108,21.5 106.8,20.7 105.9,19.5 105.8,18.6 106.6,17.5 108.2,16.1 109.3,13.8 109.2,11.9 108.1,10.9 107.1,10.3 106.7,9.5 104.8,8.6 105.1,10 104,10.5 103.5,10.6
103,11.5 102.5,12.2 101.3,12.7 100.6,13.5 99.95,12.5 99.2,10.5 99.3,9.2 100,8.4 100.6,7.2 101.8,6.4 102.2,6.2 103.1,5.3 103.4,3.8 103.8,2.4 104.2,1.35 103.5,1.3
102.2,2.2 101.3,3 100.3,5.4 100,6.5 98.3,7.9 98.6,10 98.5,12.4 98.1,14.1 97.8,15.3 97.6,16.5 96.9,17.3 96.2,16.6 95.3,15.8 94.3,16 94.3,18.5 92.9,20.1 92,21.4 91.8,22.3
91,22.5 90,21.9 89,21.7 88.2,21.6 87,21.3 86.7,20.3 85.8,19.8 83.3,17.7 82.3,16.9 81.2,16 80.1,15.3 80.3,13.1 79.85,11.9 79.9,10.3 79.3,10.3 79.3,9.3 78.2,8.8 77.55,8.1
76.9,8.5 76.2,9.95 75.8,11.25 74.8,12.9 73.8,15.4 73.3,17 72.8,19 72.8,20.4 72.7,21.6 72.5,22.2 72.2,21.8 71,20.7 69.6,21.6 69,22.3 70.3,22.9 69.3,22.8 68.5,23.6
67.5,23.9 66.9,24.8 66.5,25.4 64.6,25.2 62.3,25.1 60.6,25.3 57.8,25.65 56.9,27 56.3,27.2 54.9,26.55 53,27 50.8,28.9 50.2,30 48.9,30 48,29.4 48.4,28.5 50.2,26.7
50.1,25.7 50.8,24.8 50.75,25.6 51.3,26.15 51.6,25.3 51.3,24.6 52.6,24.2 54.4,24.5 55.3,25.3 56,25.9 56.4,26.35 56.4,25.1 56.75,24.4 58.6,23.6 59.8,22.5 58.8,20.5
57.7,19.6 57.8,18.9 56.5,18 54.1,17 52.2,16 49.1,14.5 45,12.8 43.4,12.7 43.25,13.3 42.9,14.8 42.5,16.9 41.1,19.1 39.15,21.5 38,24.1 36.4,26.2 35.7,27.35 34.6,28
35,29.5 34.25,27.7 33.6,28.2 32.55,29.95 32.35,29.6 33.1,28.35 33.85,27.2 34.3,26.1 34.9,25.1 35.8,23.9 36.6,22.2 37.2,19.6 37.7,18.4 39.5,15.6 40.9,14.7 42.7,13
43.15,11.6 45,10.45 47,11.1 49.2,11.3 51.3,11.85 51.4,10.4 50.8,9.3 49.85,8 48.5,5.35 47,3.8 45.35,2.05 42.55,-.35 40.9,-2.3 39.7,-4.05 39.1,-5.1 39.3,-6.8 39.5,-8.9
40.2,-10.3 40.5,-13 40.7,-14.5 39.9,-16.2 37,-17.9 36.3,-18.8 34.9,-19.85 35.3,-21 35.3,-22 35.5,-23.9 33.7,-25.1 32.6,-25.95 32.9,-27 32.1,-28.8 31.05,-29.85
29.5,-31.65 27.9,-33 25.7,-34 24.8,-34.2 22.1,-34.2 20,-34.8 18.5,-34.35 18.4,-33.9 17.9,-33 18.3,-32 16.85,-29.25 16.5,-28.6 15.15,-26.65 14.5,-22.95 13.4,-20.5
12,-18.4 11.75,-17.25 12.15,-15.2 13.4,-12.6 13.2,-8.8 12.9,-7 12.3,-6 11.85,-4.8 10.65,-3.4 8.7,-.7 9.4,.4 9.75,1.85 9.9,2.9 9.5,4 8.5,4.6 7,4.4 6.1,4.3 5.4,5.3
3.4,6.4 2.4,6.35 1.2,6.1 -.2,5.55 -2.1,4.75 -4,5.25 -6.1,4.95 -7.7,4.35 -9.2,5.3 -10.8,6.3 -12.5,7.4 -13.3,8.5 -13.7,9.5 -15.5,11.2 -16.5,12.4 -16.7,13.45 -17.5,14.7
-16.5,16 -16,18.1 -16.3,19.4 -17.05,20.8 -15.95,23.7 -14.5,26.1 -13.4,27.15 -12.9,27.95 -10.2,29.4 -9.65,30.4 -9.9,30.65 -9.8,31.5 -9.25,32.3 -8.5,33.25 -7.6,33.6
-6.85,34.05 -6.15,35.2 -5.95,35.8 -5.3,35.9 -5.25,35.6 -3.9,35.25 -2.95,35.3 -2,35.1 -.65,35.7 .1,35.95 1.3,36.5 3.05,36.8 3.9,36.9 5.1,36.75 5.8,36.8 6.9,36.9
7.75,36.9 9.85,37.3 11.05,37.05 10.6,36.4 10.65,35.8 10.75,34.75 10.1,33.9 11.1,33.5 13.2,32.9 15.1,32.4 16.6,31.2 18.5,30.5 19.2,30.25 20,30.8 20.05,32.1 21.7,32.9
22.65,32.75 23.95,32.1 25.15,31.55 27.25,31.35 28.95,30.85 29.9,31.2 30.4,31.45 31.1,31.6 31.8,31.5 32.3,31.25 33.8,31.15 34.3,31.4 34.75,32.05 35,32.8 35.5,33.9
35.8,34.45 35.75,35.5 35.9,36.2 36.2,36.6 35.4,36.6 34.6,36.8 33.9,36.3 32.8,36.05 32,36.55 30.7,36.85 30.5,36.3 29.6,36.2 29.1,36.6 28.3,36.8 27.4,37 27.25,37.85
26.3,38.3 26.9,38.45 26.8,39 26.7,39.3 26.9,39.55 26.05,39.5 26.2,40 26.4,40.15 27.3,40.4 27.95,40.35 28.9,40.4 29.3,40.65 29.95,40.75 29.05,41 29.15,41.2 29.6,41.2
30.7,41.1 31.8,41.45 32.4,41.75 33.75,42 35.15,42.05 36,41.7 36.35,41.3 37.3,41.1 38.4,40.9 39.7,41 40.5,41.05 41.6,41.65 41.65,42.15 41,43 39.7,43.6 39.1,44.1
37.8,44.7 37.3,44.9 36.7,45.15 37.4,45.3 38.15,46.05 38.3,46.7 39.3,47.2 37.55,47.1 36.8,46.75 34.8,46.2 35.3,45.3 36.5,45.35 35.4,45 34.15,44.5 33.4,44.6 33.35,45.2
32.5,45.35 33.6,46.1 32.9,46.1 31.5,46.5 30.75,46.5 29.7,45.2 28.65,44.2 27.95,43.2 27.5,42.5 28,41.9 29.1,41.25 28.95,41 28.25,41.07 27.5,40.97 27.1,40.6 26.65,40.4
26.2,40.05 26.2,40.3 26.8,40.6 26.05,40.7 25.9,40.85 24.4,40.9 24,40.7 24.4,40.15 23.9,40.35 24,39.95 23.7,40.2 23.35,39.95 22.95,40.6 22.6,40 23.1,39.3 22.8,38.9
23.4,39 24.2,38.6 24.6,38 24.05,38.1 24.05,37.7 23.6,37.95 23,37.95 23.4,37.4 23.2,36.45 22.6,36.75 22.5,36.4 22.1,37 21.7,36.8 21.65,37.25 21.3,37.8 21.7,38.25
21.4,38.35 21.1,38.5 20.75,38.95 20.25,39.5 20,39.9 19.45,40.45 19.45,41.3 19.35,41.9 18.75,42.4 18.1,42.65 16.45,43.5 15.2,44.1 14.9,45 14.45,45.3 13.85,44.8
13.6,45.25 13.75,45.65 12.4,45.4 12.5,44.95 12.3,44.45 12.6,44.05 13.5,43.6 14.2,42.45 15.2,41.9 16.2,41.9 15.9,41.6 16.85,41.1 18,40.65 18.5,40.15 18.35,39.8
18,40.05 17.2,40.45 16.5,39.7 17.15,39.1 16.6,38.8 16.05,37.95 15.65,38.1 15.9,38.7 16,39.35 15.6,40.05 14.75,40.65 14.25,40.85 13.55,41.2 12.6,41.45 11.8,42.1
11.1,42.4 10.5,42.95 10.3,43.55 9.8,44.1 8.95,44.4 7.8,43.8 7.25,43.7 6.65,43.25 5.9,43.1 5.35,43.3 4.6,43.35 3.7,43.4 3.1,43.1 3.05,42.7 3.3,42.3 2.2,41.4 1.25,41.1
.85,40.7 0,40 -.3,39.45 .2,38.75 -.5,38.35 -.7,37.6 -2.2,36.75 -3.5,36.75 -4.4,36.7 -4.9,36.5 -5.35,36.15`,
// Australia
`142.5,-10.7 143.5,-12.5 144,-14.3 145.3,-15.5 145.8,-16.9 146.8,-19.25 148.3,-20 149.2,-21.15 150.8,-22.5 150.9,-23.5 152.9,-25 153.4,-27.5 153.6,-28.65 153.15,-30.3
152.9,-31.45 151.8,-32.9 151.3,-33.85 150.8,-35.1 150,-36.9 149.95,-37.5 148,-37.9 146.4,-39.1 144.9,-38.3 143.5,-38.85 141.6,-38.4 140.4,-38 139.7,-37 139.5,-36
138.5,-35.6 138.5,-34.9 138,-34.2 137,-35.2 137.6,-34 137.8,-32.5 137.6,-33 135.9,-34.9 135,-33.7 134.2,-32.8 133.7,-32.1 131.2,-31.5 128.9,-31.7 126,-32.3 123.9,-33.6
121.9,-33.9 117.9,-35.05 115.1,-34.4 115.6,-33.3 115.75,-31.95 114.6,-28.8 113.15,-26.15 113.65,-24.9 114.15,-21.8 114.3,-22.5 115.1,-21.65 116.7,-20.65 118.6,-20.3
121,-19.4 122.2,-18 122.9,-16.4 123.6,-17.3 124.5,-16.3 125,-15 126.9,-13.75 128.2,-15 129.5,-14.9 129.7,-13.8 130.85,-12.45 132,-12.2 132.6,-11.1 135,-12.1
136.9,-12.2 136,-13.7 135.4,-14.8 137,-15.9 139.6,-17.6 140.8,-17.5 141.4,-16 141.6,-14.5 141.9,-12.6`,
// Antarctica, closed along the bottom edge of the map
`-200,-78 -165,-78.3 -158,-77.5 -150,-77 -140,-75.5 -135,-74.5 -125,-73.8 -115,-74 -105,-74.5 -100,-72.5 -90,-72.8 -80,-73 -75,-71 -68,-67.5 -66,-65.5 -57.5,-63.3
-60,-64.5 -62,-66.5 -61,-69 -61,-72 -62,-75 -60,-76 -50,-77.8 -42,-78 -36,-78 -30,-76.5 -27,-75.5 -20,-73.5 -12,-71.5 -5,-70.8 0,-69.5 10,-70 20,-70 30,-69 35,-69
40,-68.5 45,-67.7 53,-65.9 57,-66.7 63,-67.5 70,-68.5 72,-69.5 75,-69.5 78,-68 82,-66.5 90,-66.5 95,-66 100,-65.7 105,-66.3 110,-66 115,-66.5 120,-66.8 125,-66.3
130,-66 135,-66 140,-66.7 145,-67 150,-68.4 155,-69 160,-70 166,-70.8 170.3,-71.3 170,-72.5 166,-74.5 164,-76 166.7,-77.8 170,-77.5 200,-78 200,-95 -200,-95`,
// Greenland
`-43.9,59.8 -46,60.7 -49.7,62 -51.7,64.2 -53.7,66.9 -51,69 -54,69.5 -54.5,70.5 -56.2,72.8 -58,75 -62,76 -66.5,76 -69,76.5 -71.5,77.5 -73,78.3 -68,79.5 -65,80.5 -62,81.5
-55,82.3 -45,82.8 -33.4,83.6 -25,83 -20,82 -11.5,81.4 -17,80 -18.5,78.5 -18,76.5 -20,75 -19.5,73.5 -22,72.5 -22,70.5 -24,69.5 -26.5,68.6 -30,68.1 -33,67 -37.5,65.6
-40,65 -41,63.5 -42.5,61.5`,
// the Canadian Arctic
'-61.5,66.6 -63.5,65 -67.5,66.2 -65,64 -64.6,62.9 -68.4,63.7 -65.3,61.9 -69.5,62.6 -73,64.2 -77.8,64.4 -74.2,65.6 -73.2,68 -77.5,69.6 -81.5,69.8 -85,70.2 -89,71 -89.6,72.6 -88,73.7 -81.5,73.7 -78,72.8 -74,71.5 -68.5,70.4 -66.5,68.8 -63,67.4',
'-105,68.9 -101.5,69.5 -102,71 -105,72.7 -108.5,73 -112,72.8 -118,72.6 -117.5,71.3 -115,70.5 -117.3,69.6 -116.5,68.9 -113.5,68.5 -109,68.6',
'-123.5,71.1 -125.6,72.2 -124,74.3 -119,74.3 -115.8,73.2 -119.5,71.6','-78.5,76.4 -89,76.4 -85.5,78.2 -87.5,80 -92,81.3 -82,82.8 -70,83.1 -62,82.5 -66,80.8 -71.5,79.6 -75.5,78',
'-79.5,74.7 -91.5,74.7 -92.5,76.2 -88,76.7 -80.5,75.7','-96,79.5 -91,78.3 -87.8,79.3 -90.5,80.8 -95.5,81','-80.3,63.7 -87,63.5 -85.5,65.5 -83,66.2 -80.5,64.9',
'-106,75 -110,74.6 -117,75.6 -113,76.5 -107,76','-97,73 -99.5,71.4 -102.5,72.6 -100,73.9','-93,73.9 -90.5,72 -95.5,72.6 -95.5,73.9','-97,75.2 -101,75 -100,76.5 -97.5,76.2','-95.5,69 -99.5,69.1 -97.5,70',
// islands of the Americas
'-59.3,47.6 -57.5,47.6 -55.9,46.9 -53.1,46.65 -52.7,47.6 -53,48.7 -54.5,49.5 -55.5,50 -55.5,51.6 -56.9,51 -57.4,50.3 -58,49.2 -59.2,48.5',
'-84.95,21.85 -84,22.7 -82.4,23.15 -81.2,23.2 -80,22.95 -78.3,22.4 -77,21.7 -76.1,21.15 -74.15,20.25 -75.2,19.9 -75.85,19.95 -77.75,19.85 -77.1,20.35 -78,20.7 -78.9,21.5 -80,21.75 -80.45,22.05 -81.2,22.2 -82,22.35 -82.3,22.7 -83.5,22.2 -84.3,21.8',
'-73.4,19.8 -72.2,19.75 -71.65,19.85 -70.7,19.8 -69.2,19.3 -68.35,18.6 -68.6,18.2 -69.9,18.45 -71.1,18.2 -71.4,17.6 -72.5,18.2 -74.45,18.35 -74.1,18.65 -72.8,18.45 -72.35,18.55 -72.7,19.1 -72.7,19.45',
'-78.35,18.3 -77.9,18.5 -76.9,18.4 -76.2,18.15 -76.3,17.87 -77.2,17.7 -78.2,18.05','-67.2,18.5 -65.6,18.4 -65.7,18 -67.2,17.95','-61.9,10.7 -60.9,10.8 -61,10.1 -61.9,10.05','-78.2,25.1 -77.7,25 -77.6,24.2 -78.1,24.3',
'-61.2,-51.9 -59.7,-51.25 -57.8,-51.5 -58.6,-52.3 -60.7,-52.2','-155.9,20.25 -155.05,19.75 -155.65,18.95 -156.05,19.7','-156.7,20.9 -156,20.9 -156.1,20.6 -156.6,20.6','-158.25,21.55 -157.7,21.6 -157.7,21.25 -158.1,21.3',
'-159.75,22.2 -159.3,22.2 -159.35,21.9 -159.75,21.95','-91.5,.1 -91.1,-.1 -90.9,-.9 -91.4,-1','-133,54.1 -131.7,54 -131.1,52.2 -132.3,52.9','-154.5,57.6 -152.3,57.9 -152.6,57.2 -154.3,56.8',
// islands of Europe
'-5.7,50.05 -5.2,49.95 -3.6,50.2 -2.45,50.5 -1.1,50.7 .25,50.75 1.35,51.1 1.45,51.35 .6,51.5 1.6,52.1 1.75,52.6 1.3,52.95 .3,52.9 .35,53.2 .1,53.6 -.1,54.1 -1.2,54.6 -1.4,55 -2,55.8 -3.2,56 -2.6,56.3 -2.05,57.15 -1.8,57.6 -4,57.6 -3.05,58.6 -5,58.6 -5.3,57.9 -5.8,57.4 -6.2,56.7 -5.5,56.4 -5.8,55.3 -4.9,55.9 -4.7,55.4 -5,54.65 -3.5,54.9 -3.6,54.5 -2.9,54.1 -3.1,53.4 -4.6,53.3 -4.7,52.8 -4.1,52.4 -5.3,51.9 -5.1,51.65 -4.2,51.55 -2.9,51.5 -3.5,51.2 -4.5,51',
'-7.4,55.4 -6.1,55.2 -5.6,54.6 -6.2,54 -6.1,53.3 -6.35,52.2 -8.3,51.8 -9.8,51.45 -10.4,52.1 -9.9,52.6 -9,53.2 -10.2,53.4 -10.1,54 -8.5,54.3 -8.3,55.15',
'-24.5,65.5 -22.5,66.45 -21.5,65.5 -20.3,66.1 -18.2,66.15 -16.2,66.5 -14.6,66 -13.6,65.1 -14.9,64.3 -18.5,63.4 -20.3,63.5 -22.6,63.85 -22,64.3 -24,64.9 -22.2,65.3',
'11.1,55.2 11,55.7 11.7,56 12.6,56.05 12.6,55.4 12.1,54.95','9.8,55.4 10.7,55.6 10.8,55.1 10.2,55.05','12.4,38 13.4,38.2 15.6,38.25 15.1,36.7 14.3,37 12.5,37.6','8.2,40.9 9.2,41.25 9.8,40.5 9.6,39.2 9,39 8.4,39.2 8.4,40.3',
'9.4,43 9.5,42 9.2,41.4 8.6,42 8.7,42.6','23.5,35.6 24.5,35.4 26.3,35.3 26.1,35 24,35 23.5,35.25','32.3,35.1 33,35.35 34.6,35.7 34,35 33,34.6 32.4,34.75','2.4,39.6 3.2,39.95 3.4,39.5 2.9,39.3',
'11,79.7 16,80 21.5,80.4 27,80.1 24,79.3 21.5,78.6 18.5,77.5 16.5,76.6 14,77.5 11.5,78.6','51.5,70.7 57.5,70.6 57.6,71.6 56.3,73.2 58.8,74.3 62,75.2 66,76.2 69,76.9 66,77 61.5,76.3 57,75.5 55,74.4 53.3,72.8 52,71.6',
'95.5,79.3 100,80.2 104.5,79.3 102,78.2 98,78','137.5,75.4 141,76.1 144,75.3 142,74.8 138.5,74.8','178.7,71.1 181,71.5 182.5,71.2 180.5,70.8',
// islands of Asia and the Pacific
'142,54.3 143,53 143.3,51 143.7,49.3 144.7,48.9 142.8,47.3 143.5,46.3 142,45.9 142,47.5 142.2,49.5 141.8,51.5 141.7,53.3',
'141.9,45.5 144.3,44 145.3,44.3 145.8,43.3 144.4,42.95 143.25,41.9 141.6,42.6 141,42.3 140.7,41.75 140.1,41.45 139.8,42.2 140.35,43.3 141.6,43.95 141.6,45.4',
'140.9,41.5 141.45,41.4 141.5,40.5 142,39.6 141.55,38.3 141,38.2 140.95,37 140.85,35.7 139.9,34.9 139.8,35.5 139.65,35.15 138.85,34.6 138.5,35 138.2,34.6 137,34.6 136.8,35 136.9,34.3 135.75,33.45 135.1,34.2 135.4,34.65 133.9,34.5 132.4,34.3 130.9,33.95 131.4,34.4 132.7,35.4 133.3,35.55 134.2,35.55 135.7,35.6 136,35.7 136,36.2 136.7,36.7 137.35,37.5 137,37.1 137.2,36.75 139,37.9 139.8,38.9 139.75,39.9 140,40.6 140.4,41.25 140.8,40.9',
'132.5,33.2 133,34.1 134.05,34.35 134.65,34.2 134.2,33.25 133.5,33.5 133,32.75','130.9,33.9 131.7,33.6 131.9,33.25 131.45,31.9 131.3,31.4 130.65,31 130.2,31.4 130.2,32.2 129.75,32.6 129.5,33.35 130.4,33.6',
'121.5,25.3 122,25 121.6,24 120.85,21.9 120.1,23 120.5,24.3 121,25.05','108.7,19.2 109.5,20 110.6,20.1 111,19.6 110.3,18.6 109.5,18.2 108.7,18.6','79.9,9.8 80.8,9.2 81.8,7.5 81.2,6.3 80.2,6 79.8,7.2 79.8,8.6',
'120.6,18.55 122.2,18.5 122.4,17 121.6,15.8 121.6,14.6 123,14 124.1,13 124.1,12.55 123.3,13 122.6,13.6 121.7,13.9 121,13.75 120.6,14.2 120.9,14.6 120.5,14.45 120,15.3 119.8,16.3 120.3,16.05 120.3,17 120.4,18.1',
'122.05,6.9 122.2,8 123.4,8.6 124.3,8.2 124.65,8.5 125.4,9 125.5,9.8 126.3,8.5 126.2,6.3 125.6,7.1 125.4,6 125.3,5.6 124.1,6.1 124.2,7.2 123.4,7.6 122.9,7.3',
'124.3,12.5 125.3,12.5 125.75,11 125.25,10.1 124.75,10.1 124.4,11.4','122,11.9 123.1,11.5 122.6,10.5 121.9,10.45','123.2,10.95 124,11.2 123.6,9.6 123.3,9.1 122.6,9.4 122.5,10.6','120.4,13.4 121.2,13.4 121.5,12.4 120.9,12.3','117.2,8.35 118.6,9.8 119.6,11.35 119.7,10.55 118.3,8.9',
'109.65,2.05 110.4,1.6 111.4,2.3 113,3.2 114.5,4.8 116,6 116.8,6.95 118.1,5.85 119.2,5.2 118.3,4.3 117.6,3.5 118,2.2 119,1 117.8,.8 117.5,-.6 116.8,-1.3 116.5,-2.3 116,-3.6 114.6,-4.1 114.6,-3.4 113,-3.2 111.7,-3 110.2,-3 110,-1.8 109.2,-.1 108.95,.9',
'95.3,5.6 97.1,5.2 98.3,4.1 98.7,3.75 99.9,2.9 100.9,2.1 101.4,1.7 103,.6 103.8,-.5 104.4,-1.1 104.9,-2.3 106,-3 105.8,-4.3 105.9,-5.8 105.3,-5.5 104.5,-5.9 102.25,-3.8 100.35,-.95 98.8,1.75 97.75,2.3 96.1,4.15',
'105.2,-6.8 106,-5.9 106.8,-6.1 108.3,-6.3 108.6,-6.7 110.4,-6.95 111,-6.4 112.75,-7.2 114.4,-7.7 114.6,-8.75 112.7,-8.4 110,-7.9 108.5,-7.7 106.5,-7.4 105.4,-6.85',
'125.2,1.6 124,1 122,1 120.9,1.3 119.9,.7 119.8,0 119.7,-.8 119.3,-2 118.9,-2.7 119.4,-3.5 119.4,-5.15 120.3,-5.6 120.4,-4.5 120.3,-3 121,-2.7 121.6,-4 121.9,-4.9 122.6,-5.4 122.9,-4.4 122.3,-3.2 121.6,-2 122.5,-1.6 123.5,-.9 122,-.9 120.8,-1.4 120.1,-.9 120.1,0 120.3,.4 121.5,.5 123,.5 124.5,.4',
'131.2,-.8 132.5,-.4 134.1,-.85 134.3,-2.5 135,-3.4 135.5,-3.3 136.5,-2.3 137.9,-1.6 140.7,-2.5 143.6,-3.55 145.8,-5.2 147,-5.9 147.85,-6.6 147,-6.75 148,-8 149,-9.1 150.9,-10.25 149.5,-10.4 147.15,-9.5 146,-8.1 145.3,-7.9 144.5,-7.6 143.5,-8.3 143.2,-9.1 141,-9.1 140.4,-8.5 138.8,-8.3 137.7,-8.4 138.4,-7.2 138.9,-6.3 138.1,-5.5 137,-4.9 136,-4.5 134.7,-3.9 133.7,-3.7 132.7,-4 132.3,-2.9 133.5,-2.5 132,-2.2 131,-1.5',
'123.6,-10.3 125,-9 127.2,-8.4 126.6,-9.1 124.5,-10.1','115,-8.2 117,-8.2 119,-8.3 121,-8.3 122.9,-8.2 122.8,-8.7 120,-8.8 117.5,-8.9 115.2,-8.75','119,-9.4 120.8,-9.9 120.2,-10.2 119.2,-9.8','127.6,1.9 128.8,1.4 128.3,-.8 127.6,.3','127.9,-3 130.8,-3 130.6,-3.6 128.2,-3.5','126.1,-3.2 127.2,-3.3 126.7,-3.8',
'148.3,-5.6 150,-5 152.2,-4.2 152,-5.5 150,-6.3','150.8,-2.6 152.9,-4.4 152.6,-4.7 150.5,-2.9','154.7,-5.5 155.9,-6.5 155.4,-6.8','164,-20.1 167,-22.2 166.5,-22.4 163.9,-20.5','177.3,-17.6 178.6,-17.6 178.4,-18.2 177.3,-18.1',
'49.3,-12 50.5,-15.3 49.8,-17 49.4,-18.2 48.3,-21.5 47.1,-24.9 45.1,-25.6 43.7,-23.4 44.3,-20.3 44.4,-16.2 46.3,-15.7 48.3,-13.4','53.3,12.6 54.5,12.6 53.8,12.3','68.8,-49.1 70.5,-49.2 69.8,-49.7',
'144.7,-40.7 148.3,-40.9 148.3,-42.2 147.9,-43.2 146.8,-43.6 145.5,-42.9 145.2,-41.8',
'172.7,-34.45 173,-34.4 174.3,-35.3 175,-36.9 175.6,-36.5 176.2,-37.6 178.55,-37.7 178,-38.7 176.9,-39.5 177.1,-39.65 175.3,-41.6 174.8,-41.3 175,-40 173.75,-39.3 174.1,-39.05 174.8,-38.1 174.5,-37 174.2,-36.4 173.1,-35.2',
'172.7,-40.5 173.3,-41.25 174.3,-41 174.3,-41.7 173.7,-42.4 173.1,-43.75 171.3,-44.4 170.75,-45.8 168.4,-46.6 166.6,-46.15 167,-45 168.6,-44 170.95,-42.7 171.5,-41.75 172.1,-40.8'
].map(ring),
// lakes and inland seas, cut back out of the land
WATER=[
'49,46.6 51.5,46.9 53,46.5 53,45.2 50.3,44.6 51.2,43.65 52.8,41.8 53,40 53.9,38.9 54,37 52.6,36.7 49.5,37.5 48.9,38.4 49.4,39.3 50.4,40.4 49.6,40.6 48.3,42.05 47.5,43 47.5,44.6 46.7,45.2 47.9,45.9',
'-92.1,46.75 -89.5,48 -88.3,48.9 -86.4,48.75 -84.9,47.9 -84.6,46.5 -86.6,46.45 -87.4,46.55 -87.8,47.45 -88.9,46.9 -90.9,46.65','-87.6,41.7 -86.9,41.75 -86.3,43 -86.5,44.1 -85.6,45 -85,45.8 -86.5,45.85 -87,45.7 -88,44.55 -87.65,44.1 -87.9,43',
'-84.7,45.9 -83.4,46 -81.5,46 -80.5,45.9 -80,44.8 -81,44.6 -81.6,45.25 -81.4,44.6 -81.7,43.8 -82.4,43 -82.6,43.7 -82.8,44.05 -83.9,43.65 -83.3,44.3 -83.4,45.1 -84.2,45.65',
'-83.4,41.7 -82.7,41.5 -81.7,41.5 -80.1,42.15 -78.9,42.85 -79.5,42.85 -81.2,42.65 -82.5,42 -83.1,42.1','-79.8,43.3 -79.4,43.65 -77.5,44 -76.4,44.2 -76.5,43.45 -77.6,43.25 -79,43.25',
'-96.8,50.4 -96.3,51.5 -97.8,53.8 -99,53.2 -97.6,51.6','-117,61 -114,62.5 -110,62.8 -109.5,62.5 -113,61.3','-124,65.2 -122,66.9 -118.5,66.6 -119.5,65 -122,64.8','-85.9,11.9 -84.8,11.3 -85.2,11 -85.9,11.5',
'-70,-15.5 -69.2,-15.6 -68.7,-16.5 -69.3,-16.4','-71.9,10.6 -71.4,10.6 -71.1,9.6 -71.6,9.1 -72,9.9','31.7,-.3 32.3,.3 34,.3 34.3,-1 33.5,-2.4 32.2,-2.5 31.8,-1.2','29.1,-3.4 29.7,-3.5 29.9,-5 30.6,-6.6 31.2,-8.6 30.6,-8.7 29.5,-6 29.2,-4.6',
'33.9,-9.6 34.5,-9.7 34.9,-11.5 35.2,-13.5 34.9,-14.4 34.4,-13.8 34.2,-11.5','103.8,51.6 105.5,51.8 108.5,53.3 110,55.5 109.2,55.8 107,53.4 104.5,52.2','73.5,45.5 74.5,46.6 78.5,46.8 79.2,46.3 76,46 74.5,45',
'30,60 31,61.6 32.9,61 32.5,60.2 31.2,59.95','34.3,61 35.2,62.5 36.3,62 35.7,61','12.4,58.7 13.3,59.3 14,58.7 13,58.4','58.2,44.6 59.6,46 60.2,45 59,44.2'
].map(ring),
// mountain ranges: a width in degrees, then the line of the range
MTN=[[3,-73,10,-75.5,5,-78,0,-78.7,-4,-77,-9,-74.5,-13,-71,-15.5,-68.5,-18,-67.8,-22,-68.5,-26,-69.8,-30,-70.1,-34,-71,-38,-72,-42,-73,-47,-72.5,-51],
[3,-150,62.5,-140,61,-130,57,-124,53,-117,50,-113.5,46,-109.5,43,-106.5,39.5,-105.5,35.5],[2,-122,48,-121.7,44,-119.5,38,-118.3,36],[2,-108.5,29,-105.5,24,-103,20.5],
[2,-100.5,25,-98.5,20,-96.5,17,-92,15.5,-88,14,-84.5,10.5],[1.4,-84,35,-80,38,-76,41.5,-71.5,44.5],[2,-153,63,-148,63.5],[1.5,-160,68,-146,68.5],[1,-44,-18,-46,-22.5,-50,-26.5],[1.2,-66,5,-61.5,5],
[2,6.5,45,9.5,46.5,13.5,47.2],[1.5,-1.5,43,2,42.5],[1.5,19,49.3,24,48.3,26,46,23,45.4],[2,6.5,60,9,62,14,66,18.5,68.5,21,69.5],[1.2,9.5,44.3,12.5,43,14,41.8,16,40],[1.5,14.5,45.5,18,43.6,20.2,41.5,21.5,39.3],
[2.5,38,44,43,43,48,41],[1.5,30,37,36,37.5,42,38.5],[2.5,44.5,37.5,48,34,52,30.5,56,28],[1.5,49,37,54,36.3],[4,67,35,72,36.2,76,35.2,79.5,31.5,84,28.7,88,27.8,92,27.8,96,28.8],
[2.5,76,36.8,84,36,92,36,100,35],[2.5,70,41,76,42,82,43,88,43.5,94,43],[2,84,50.5,90,48,96,46],[1.5,96,52,104,51.5,112,55],[1.3,59.5,67,59,61,58.5,54,58,51.5],[1.5,128,65,133,67,142,65.5,150,62],
[2,158,53,160.5,56.5,162.5,59],[1.5,130.8,32.5,133.5,34,137.8,36,140,39,142.5,43.5],[1.5,96,5,99,2,101,-1.5,104,-4.8],[1,106.5,-7,110.5,-7.4,113.5,-8],[2.5,134.5,-3.3,138,-4,142,-5,146,-6.3,148,-9],
[1,113,1.5,116.5,5.8],[1.5,98,25,100,21,104,19.5,107.5,15.5],[1.5,73.8,19.5,75.3,14,77,9.5],[3,36.5,13.5,38.5,10,39.5,7.5],[2,30,.3,35,-.5,37,-3.2,35,-8,34,-10.5],[2,27.5,-32,29.3,-29.5,30.5,-25],
[2,-8.5,31,-4.5,33.2,1,34.8,7,35.6],[1.5,17.5,21,18.5,20.5],[1.5,5.5,23.5,6.5,23],[1.5,38,26,41,20.5,43.8,15.3],[1.5,146.5,-37.5,149,-35,151.5,-30,148.5,-24,145.5,-18],[2,167.8,-45.2,170,-43.7,172.3,-42.2],[1.5,-58,-63.5,-64,-67,-65,-72]],
// deserts: longitude, latitude, half-widths east-west and north-south, how dry
DRY=[8,23,30,9,1, 46,23,12,9,1, 60,30,9,6,.8, 71,27,3,3,.7, 62,42,10,5,.8, 93,41,17,5,.9, 88,33,10,4,.6, 19,-24,7,7,.8, 46,7,5,5,.7, 132,-25,15,8,.9,
-70,-24,2.5,8,1, -76.5,-11,2.5,6,.8, -68,-44,4,8,.6, -110,31,8,7,.8, -116,40,4,4,.5],
// city lights: longitude, latitude, how bright
CITY=[-74,40.7,3,-71.1,42.4,2,-75.2,40,2,-77,38.9,2,-84.4,33.7,2,-80.2,25.8,2,-81.4,28.5,1,-82.5,28,1,-80.8,35.2,1,-87.6,41.9,3,-83,42.3,2,-79.4,43.7,2,-73.6,45.5,2,-81.7,41.5,1,-80,40.4,1,-84.5,39.1,1,
-86.2,39.8,1,-90.2,38.6,1,-93.3,45,1.5,-94.6,39.1,1,-96.8,32.8,2.5,-95.4,29.8,2.5,-98.5,29.4,1,-97.7,30.3,1,-90.1,30,1,-86.8,36.2,1,-90,35.1,1,-105,39.7,1.5,-111.9,40.8,1,-112.1,33.4,2,-115.1,36.2,1.5,
-118.2,34.1,3,-117.2,32.7,1.5,-122.3,37.7,2.5,-122.3,47.6,2,-122.7,45.5,1,-123.1,49.3,1.5,-114.1,51,1,-113.5,53.5,1,-97.1,49.9,.7,-99.1,19.4,3,-103.3,20.7,2,-100.3,25.7,2,-98.2,19,1,-117,32.5,1,
-82.4,23.1,1.5,-69.9,18.5,1.5,-66.1,18.4,1.5,-76.8,18,1,-75.8,20,.7,-90.5,14.6,1.5,-89.2,13.7,1,-84.1,9.9,1,-79.5,9,1,-74.1,4.7,2.5,-75.6,6.2,1.5,-76.5,3.4,1.5,-74.8,11,1,-66.9,10.5,2,-71.6,10.6,1.5,
-78.5,-.2,1.5,-79.9,-2.2,1.5,-77,-12,2.5,-68.1,-16.5,1,-70.7,-33.4,2.5,-71.6,-33,1,-73,-36.8,1,-71.25,-29.9,.7,-70.4,-23.6,.6,-58.4,-34.6,3,-64.2,-31.4,1.5,-60.7,-32.9,1.5,-68.8,-32.9,1,-65.2,-26.8,1,
-56.2,-34.9,1.5,-57.6,-25.3,1.5,-46.6,-23.5,3,-43.2,-22.9,3,-43.9,-19.9,2,-47.9,-15.8,1.5,-38.5,-13,1.5,-34.9,-8.1,1.5,-38.5,-3.7,1.5,-48.5,-1.4,1,-60,-3.1,1,-49.3,-25.4,1.5,-51.2,-30,1.5,-49.3,-16.7,1,
-.1,51.5,3,-1.9,52.5,1.5,-2.2,53.5,1.5,-4.3,55.9,1,-6.3,53.3,1,2.35,48.85,3,4.35,50.85,2,4.6,52.2,2.5,7,51.4,2.5,8.7,50.1,1.5,10,53.5,1.5,13.4,52.5,2,11.6,48.1,1.5,9.2,48.8,1,12.6,55.7,1.5,18.1,59.3,1.5,
10.75,59.9,1,24.9,60.2,1,30.3,59.9,2,37.6,55.75,3,21,52.2,1.5,14.4,50.1,1,16.4,48.2,1.5,19.05,47.5,1.5,26.1,44.4,1.5,30.5,50.45,1.5,27.6,53.9,1,-3.7,40.4,2.5,2.2,41.4,2,-9.15,38.7,1.5,-8.6,41.15,1,
-.4,39.5,1,-6,37.4,1,9.2,45.5,2.5,7.7,45.1,1,12.5,41.9,2,14.3,40.85,2,23.7,38,2,29,41,3,32.85,39.9,1.5,27.1,38.4,1,4.85,45.75,1,5.4,43.3,1,8.5,47.4,1,20.5,44.8,1,23.3,42.7,1,39.7,47.2,1,44,56.3,1,
49.1,55.8,1,50.2,53.2,1,60.6,56.8,1,82.9,55,1,73.4,55,.7,31.2,30.05,3,29.9,31.2,1.5,31.5,28,1,32,26,1,32.8,24.3,.8,31,31,1.5,34.8,32.1,1.5,35.5,33.9,1,36.3,33.5,1,44.4,33.3,2,51.4,35.7,2.5,46.7,24.7,2,
39.2,21.5,1.5,48,29.4,1.5,55.3,25.2,2,51.5,25.3,1,-7.6,33.6,1.5,3.05,36.75,1.5,10.2,36.8,1,13.2,32.9,1,3.4,6.5,2.5,7.5,9.1,1,8.5,12,1,-.2,5.6,1.5,-4,5.3,1.5,-17.4,14.7,1,15.3,-4.3,1.5,13.2,-8.8,1.5,
36.8,-1.3,1.5,38.75,9,1.5,39.3,-6.8,1,32.5,15.6,1.5,28,-26.2,2.5,18.4,-33.9,1.5,31,-29.9,1,67,24.9,2.5,74.3,31.5,2.5,77.2,28.6,3,72.9,19.1,3,88.4,22.6,2.5,90.4,23.8,2.5,80.3,13.1,2,77.6,13,2,
78.5,17.4,2,72.6,23,1.5,80.9,26.8,1.5,85.1,25.6,1.5,79.9,6.9,1,69.3,41.3,1,76.9,43.25,.8,100.5,13.75,2.5,106.7,10.8,2,105.85,21,2,101.7,3.1,2,103.8,1.35,2,106.8,-6.2,3,112.75,-7.25,1.5,110.4,-7,1,
121,14.6,2.5,113.7,22.8,3,121.5,31.2,3,118.8,32,1.5,120.2,30.3,1.5,116.4,39.9,3,117.2,39.1,2,114.3,30.6,2,106.5,29.6,2,104.1,30.7,2,108.9,34.3,1.5,123.4,41.8,1.5,126.6,45.75,1,113.6,34.75,1.5,
117,36.7,1.5,121.5,25.05,2,127,37.55,3,129.05,35.15,1.5,139.7,35.7,3,135.5,34.7,2.5,136.9,35.2,2,130.4,33.6,1.5,141.35,43.05,1,151.2,-33.9,2,145,-37.8,2,153,-27.5,1.5,115.9,-31.95,1.5,138.6,-34.9,1,
174.8,-36.85,1,-157.85,21.3,.8],
// the brightest stars: right ascension in hours, declination in degrees, magnitude, colour from 0 (blue) to 4 (red)
STAR=[5.919,7.41,.45,4, 5.242,-8.2,.15,0, 5.419,6.35,1.64,0, 5.796,-9.67,2.07,0, 5.679,-1.94,1.74,0, 5.604,-1.2,1.69,0, 5.533,-.3,2.25,0, 5.585,9.93,3.4,0, 5.59,-5.91,2.75,0, 4.831,6.96,3.2,2,
6.752,-16.72,-1.46,1, 6.378,-17.96,1.98,0, 6.977,-28.97,1.5,0, 7.14,-26.39,1.83,2, 7.402,-29.3,2.45,0, 6.338,-30.06,3,0, 7.655,5.22,.4,2, 7.453,8.29,2.89,0,
7.755,28.03,1.16,3, 7.577,31.89,1.58,1, 6.629,16.4,1.93,1, 6.383,22.51,2.87,4, 6.248,22.51,3.3,4, 6.732,25.13,3,2, 7.335,21.98,3.5,2, 7.068,20.57,3.8,2, 6.755,12.9,3.35,2, 7.741,24.4,3.57,3,
4.599,16.51,.87,3, 5.438,28.61,1.65,0, 3.791,24.11,2.85,0, 3.819,24.05,3.6,0, 3.748,24.11,3.7,0, 3.763,24.37,3.9,0, 3.772,23.95,4.1,0, 5.627,21.14,3,0, 4.33,15.63,3.65,3, 4.38,17.54,3.77,3, 4.477,19.18,3.53,3, 4.478,15.87,3.4,1, 4.01,12.49,3.4,0,
5.278,46,.08,2, 5.992,44.95,1.9,1, 5.995,37.21,2.65,1, 4.95,33.17,2.69,3, 5.033,43.82,3,2, 5.108,41.23,3.2,0, 3.405,49.86,1.79,2, 3.136,40.96,2.1,0, 3.902,31.88,2.85,0, 3.964,40.01,2.9,0, 3.08,53.5,2.9,2, 3.715,47.79,3,0,
.675,56.54,2.24,3, .153,59.15,2.28,2, .945,60.72,2.15,0, 1.43,60.24,2.68,1, 1.907,63.67,3.35,0, 11.062,61.75,1.81,3, 11.031,56.38,2.34,1, 11.897,53.69,2.41,1, 12.257,57.03,3.32,1, 12.9,55.96,1.76,1, 13.399,54.93,2.23,1, 13.792,49.31,1.85,0,
2.53,89.26,1.97,2, 14.845,74.16,2.07,3, 15.345,71.83,3,1, 10.14,11.97,1.36,0, 11.818,14.57,2.14,1, 10.333,19.84,2.01,3, 11.235,20.52,2.56,1, 11.237,15.43,3.33,1, 10.122,16.76,3.5,1, 10.278,23.42,3.43,2, 9.879,26.01,3.88,3, 9.764,23.77,2.97,3,
8.275,9.19,3.53,3, 8.745,18.15,3.94,3, 8.721,21.47,4.66,1, 8.778,28.76,4,2, 8.975,11.86,4.25,1, 8.67,19.9,5.6,1, 8.66,19.55,5.7,1, 8.685,19.7,5.9,1, 8.655,19.75,6,1, 8.675,19.45,6,1, 8.64,20,6.1,1,
9.46,-8.66,1.98,3, 13.42,-11.16,.97,0, 12.694,-1.45,2.74,2, 13.036,10.96,2.83,3, 14.261,19.18,-.05,3, 14.75,27.07,2.37,3, 13.911,18.4,2.68,2, 14.535,38.31,3.03,1, 15.032,40.39,3.5,3, 15.578,26.71,2.23,1,
16.49,-26.43,.96,4, 17.56,-37.1,1.63,0, 17.622,-43,1.87,2, 16.006,-22.62,2.32,0, 16.091,-19.81,2.62,0, 16.836,-34.29,2.29,3, 17.708,-39.03,2.41,0, 17.513,-37.3,2.69,0, 15.981,-26.11,2.89,0, 16.598,-28.22,2.82,0, 16.353,-25.59,2.89,0,
17.793,-40.13,3.03,2, 16.864,-38.05,3,0, 16.91,-42.36,3.6,3, 17.203,-43.24,3.33,2, 17.83,-37.04,3.2,3, 18.403,-34.38,1.85,0, 18.921,-26.3,2.02,0, 19.044,-29.88,2.59,1, 18.35,-29.83,2.7,3, 18.466,-25.42,2.81,3, 18.097,-30.42,2.99,3,
18.761,-26.99,3.17,0, 19.116,-27.67,3.32,3, 19.163,-21.02,2.89,2, 18.616,38.78,.03,1, 18.982,32.69,3.24,0, 18.835,33.36,3.5,0, 20.69,45.28,1.25,1, 20.37,40.26,2.2,2, 20.77,33.97,2.46,3, 19.75,45.13,2.87,0, 19.512,27.96,3.08,3,
19.846,8.87,.77,1, 19.771,10.61,2.72,3, 19.922,6.41,3.7,2, .14,29.09,2.06,0, 1.162,35.62,2.05,4, 2.065,42.33,2.26,3, 23.079,15.21,2.49,0, 23.063,28.08,2.42,4, .221,15.18,2.83,0, 21.736,9.88,2.39,3, 2.12,23.46,2,3, 1.911,20.81,2.64,1,
.726,-17.99,2.02,3, 3.038,4.09,2.53,4, 22.961,-29.62,1.16,1, 22.137,-46.96,1.74,0, 22.711,-46.88,2.1,4, 20.427,-56.74,1.94,0, 1.629,-57.24,.46,0, 5.131,-5.09,2.79,1, 2.971,-40.3,2.9,1, 3.967,-13.51,2.95,4,
6.399,-52.7,-.74,2, 9.22,-69.72,1.68,1, 8.375,-59.51,1.86,3, 9.285,-59.28,2.25,2, 10.716,-64.39,2.76,0, 9.785,-65.07,2.97,1, 8.158,-47.34,1.78,0, 8.745,-54.71,1.96,1, 9.369,-55.01,2.5,0, 9.133,-43.43,2.21,3, 10.779,-49.42,2.7,2,
8.06,-40,2.25,0, 7.286,-37.1,2.7,3, 8.126,-24.3,2.81,2, 6.833,-50.61,2.93,3, 6.629,-43.2,3.17,0, 7.487,-43.3,3.25,3, 7.821,-24.86,3.34,2, 12.443,-63.1,.76,0, 12.795,-59.69,1.25,0, 12.519,-57.11,1.63,4, 12.252,-58.75,2.8,0, 12.356,-60.4,3.59,3,
14.66,-60.83,-.27,2, 14.064,-60.37,.61,0, 14.111,-36.37,2.06,3, 12.692,-48.96,2.17,1, 13.665,-53.47,2.3,0, 14.592,-42.16,2.31,0, 13.926,-47.29,2.55,0, 12.139,-50.72,2.6,0, 13.343,-36.71,2.75,1, 14.699,-47.39,2.3,0, 14.976,-43.13,2.68,0, 15.586,-41.17,2.78,0,
16.811,-69.03,1.92,3, 15.919,-63.43,2.85,2, 15.315,-68.68,2.89,1, 17.422,-55.53,2.85,3, 17.531,-49.88,2.95,0, 12.62,-69.14,2.69,0, .429,-77.25,2.8,2, 1.98,-61.57,2.86,2, 22.308,-60.26,2.86,3, .438,-42.31,2.39,3, 5.661,-34.07,2.64,0, 5.849,-35.77,3.1,3,
5.545,-17.82,2.58,2, 5.471,-20.76,2.84,2, 12.263,-17.54,2.59,0, 12.573,-23.4,2.65,2, 12.498,-16.52,2.95,1, 12.169,-22.62,3,3, 15.283,-9.38,2.61,0, 14.848,-16.04,2.75,1, 17.582,12.56,2.08,1, 17.173,-15.72,2.43,1, 16.619,-10.57,2.56,0,
16.239,-3.69,2.74,4, 17.725,4.57,2.77,3, 16.504,21.49,2.77,2, 16.688,31.6,2.81,2, 17.943,51.49,2.23,3, 17.507,52.3,2.79,2, 21.31,62.59,2.44,1, 21.784,-16.13,2.87,1, 21.526,-5.57,2.91,2, 22.096,-.32,2.96,2, 12.934,38.32,2.9,1, 15.738,6.43,2.65,3,
9.351,34.39,3.13,3, 2.159,34.99,3,1],
// the Moon's dark plains (and the darker floors of a few craters): latitude, longitude east, radius in degrees, how dark
MARE=[32.8,-15.6,18,1, 44,-31,5,.8, 28,17.5,11.5,1, 8.5,31.4,13,1, 14,24,6,.8, 17,59.1,8,1.1, -7.8,51.3,9,.9, -3,53,6,.7, -15.2,35.5,5.5,.9, -21.3,-16.6,11,.9, -24.4,-38.6,6.2,1,
22,-58,17,.9, 42,-54,11,.8, 2,-46,13,.85, -8,-30,8,.8, -10,-23,6,.8, 7.5,-31,8,.75, 56,-35,5.5,.7, 57,-12,5.5,.7, 56,10,5.5,.7, 54,30,5,.65, 13.3,3.6,4.2,.8, 2.4,1.7,4.5,.6, 10.9,-8.8,4.4,.6,
38,29,5,.5, 56.8,81.5,4.5,.9, 13.3,86.1,5,.8, 1.3,87.5,5.5,.8, -38.9,93,9,.5, -19.4,-92.8,5,1, 27.3,147.9,4.5,1, -33.7,163.5,4.5,.8, -20.4,129.1,2.8,1, -53,-169,33,.22, 51.6,-9.4,1.8,1, -5.2,-68.6,3,1],
// bright young craters with rays: latitude, longitude, how far the rays reach in degrees
RAYS=[-43.3,-11.4,38, 9.6,-20.1,14, 8.1,-38,10, 23.7,-47.4,8, 16.1,46.8,7, -8.9,61.1,7, -32,54,8, 73.4,-10.1,10, -24.5,-63.7,8, 35.9,102.8,14, 22.4,-163.1,22, 18.4,-113.5,14, -5,123.1,10, 5,120.5,9];
// The Earth drawn flat, longitude across and latitude down, into two canvases that become textures:
// red is land, green how dry it is, blue how high; and a second one for the lights of the cities.
const mapc=(w,h)=>{const c=document.createElement('canvas');c.width=w;c.height=h;return c};
const EW=2048,EH=1024,EC=mapc(EW,EH),LC=mapc(EW,EH);
{const X=EC.getContext('2d'),px=lo=>(lo+180)/360*EW,py=la=>(90-la)/180*EH;
// a ring as a closed curve through the middles of its sides, which rounds the corners off
const path=(r,o)=>{const n=r.length,m=i=>{const a=r[i%n],b=r[(i+1)%n];return[px((a[0]+b[0])/2+o),py((a[1]+b[1])/2)]};X.beginPath();
if(n<7){for(const a of r)X.lineTo(px(a[0]+o),py(a[1]))}else{X.moveTo(...m(0));for(let i=1;i<=n;i++){const a=r[i%n];X.quadraticCurveTo(px(a[0]+o),py(a[1]),...m(i))}}
X.closePath();X.fill()};
X.fillStyle='#000';X.fillRect(0,0,EW,EH);
X.fillStyle='#f00';for(const o of[-360,0,360])for(const r of LAND)path(r,o);
X.fillStyle='#000';for(const r of WATER)path(r,0);
X.globalCompositeOperation='lighter';
for(let i=0;i<DRY.length;i+=5){const g=X.createRadialGradient(0,0,0,0,0,1),c=`rgb(0,${255*DRY[i+4]|0},0)`;g.addColorStop(0,c);g.addColorStop(.5,c);g.addColorStop(1,'#000');
X.save();X.translate(px(DRY[i]),py(DRY[i+1]));X.scale(DRY[i+2]*EW/360,DRY[i+3]*EH/180);X.fillStyle=g;X.beginPath();X.arc(0,0,1,0,7);X.fill();X.restore()}
X.lineCap=X.lineJoin='round';X.strokeStyle='rgb(0,0,62)';
for(const m of MTN)for(const k of[1,.7,.45,.22]){X.lineWidth=m[0]*k*EW/360;X.beginPath();for(let i=1;i<m.length;i+=2)X.lineTo(px(m[i]),py(m[i+1]));X.stroke()}
const Y=LC.getContext('2d');Y.fillStyle='#000';Y.fillRect(0,0,EW,EH);Y.globalCompositeOperation='lighter';
for(let i=0;i<CITY.length;i+=3){const x=px(CITY[i]),y=py(CITY[i+1]),w=CITY[i+2];
for(const[r,a]of[[1.1+.55*w,.5+.17*w],[3+2.2*w,.05*w]]){const g=Y.createRadialGradient(x,y,0,x,y,r),v=Math.min(255,255*a)|0;g.addColorStop(0,`rgb(${v},${v},${v})`);g.addColorStop(1,'#000');
Y.fillStyle=g;Y.beginPath();Y.arc(x,y,r,0,7);Y.fill()}}}
/* ---------------- the sky as it was ---------------- */
// Lengths in Earth radii, angles in degrees unless said. Astronomy is done in equatorial axes (x to the equinox, z north); the
// pictures use (x, north, y), so w3 swaps the last two. Times are hours of UT on the day of each eclipse.
const D2R=Math.PI/180,TAU=2*Math.PI,BEAT=2/3,BAR=8/3,NBAR=68,LEN=NBAR*BAR;
const add=(a,b)=>[a[0]+b[0],a[1]+b[1],a[2]+b[2]],sub=(a,b)=>[a[0]-b[0],a[1]-b[1],a[2]-b[2]],mul=(a,s)=>[a[0]*s,a[1]*s,a[2]*s],
dot=(a,b)=>a[0]*b[0]+a[1]*b[1]+a[2]*b[2],cross=(a,b)=>[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]],
len=a=>Math.hypot(a[0],a[1],a[2]),nrm=a=>mul(a,1/(len(a)||1)),lerp=(a,b,t)=>[a[0]+(b[0]-a[0])*t,a[1]+(b[1]-a[1])*t,a[2]+(b[2]-a[2])*t],
mix=(a,b,t)=>a+(b-a)*t,cl=(x,a=0,b=1)=>Math.min(b,Math.max(a,x)),ss=(a,b,x)=>{x=cl((x-a)/(b-a));return x*x*(3-2*x)},
w3=v=>[v[0],v[2],v[1]],poly=(c,t)=>c.reduceRight((s,v)=>s*t+v,0),
rad=(a,d)=>[Math.cos(d*D2R)*Math.cos(a*D2R),Math.cos(d*D2R)*Math.sin(a*D2R),Math.sin(d*D2R)];
// a camera looking from co at ta: rows right, up, forward
const look=(co,ta,up,roll)=>{const f=nrm(sub(ta,co));let r=nrm(cross(up,f)),u=cross(f,r);
if(roll){const c=Math.cos(roll),s=Math.sin(roll),q=add(mul(r,c),mul(u,s));u=add(mul(u,c),mul(r,-s));r=q}
return[...r,...u,...f]};
// Greenwich mean sidereal time, degrees, for a Julian date
const gmst=jd=>280.46061837+360.98564736629*(jd-2451545);
// The two eclipses, as published (F. Espenak, EclipseWise): Besselian elements, polynomials in hours of dynamical time from t0.
// Total lunar eclipse of 21 January 2019: x, y are the Moon's place east and north of the middle of the Earth's shadow in degrees,
// f1 f2 f3 the radii of the penumbra, the umbra and the Moon; ra, dec the Sun at greatest eclipse and how fast it moves.
const LE={jd:2458504.5,dT:69.1,t0:5,x:[-.08686,.58826,.00008,-.00001],y:[.38952,-.0708,-.00019],f1:1.30893,f2:.76713,f3:.27836,
ra:303.07167,dec:-19.96336,dra:.0443,dde:.0115,tg:.22419,dm:56.0847,ds:23081};
// Total solar eclipse of 2 July 2019: x, y where the axis of the Moon's shadow crosses the plane through the Earth's centre,
// d and mu the direction of that axis, l1 l2 the radii of penumbra and umbra on that plane, tf1 tf2 the slopes of the two cones.
const SE={jd:2458666.5,dT:69.6,t0:19,x:[-.21563,.56621,.00003,-.00001],y:[-.65071,.01064,-.00013],d:[23.0129,-.0032],
l1:[.53765,-.00009,-.00001],l2:[-.00847,-.00009,-.00001],mu:[103.9797,14.9995],tf1:.0045984,tf2:.0045755};
// where things are during the lunar eclipse, h hours UT: shadow axis a, Moon M, Sun S, sidereal angle th
const lun=h=>{const t=h+LE.dT/3600-LE.t0,x=poly(LE.x,t),y=poly(LE.y,t),ra=LE.ra+LE.dra*(t-LE.tg)+180,de=-(LE.dec+LE.dde*(t-LE.tg)),
a=rad(ra,de),e=[-Math.sin(ra*D2R),Math.cos(ra*D2R),0],n=cross(a,e),
md=nrm(add(a,add(mul(e,Math.tan(x*D2R)),mul(n,Math.tan(y*D2R)))));
return{h,t,x,y,rho:Math.hypot(x,y),a,e,n,md,M:mul(md,LE.dm),S:mul(a,-LE.ds),sd:mul(a,-1),th:gmst(LE.jd+h/24),jd:LE.jd+h/24}};
// and during the solar eclipse: i, j, k are the axes of the fundamental plane (east, north, towards the Sun)
const sol=h=>{const t=h+SE.dT/3600-SE.t0,x=poly(SE.x,t),y=poly(SE.y,t),d=poly(SE.d,t),l1=poly(SE.l1,t),l2=poly(SE.l2,t),
th=gmst(SE.jd+h/24),al=th-poly(SE.mu,t)+.00417807*SE.dT,k=rad(al,d),i=[-Math.sin(al*D2R),Math.cos(al*D2R),0],j=cross(k,i),
zm=(l2+.272281*Math.hypot(1,SE.tf2))/SE.tf2,ax=add(mul(i,x),mul(j,y)),M=add(ax,mul(k,zm)),S=add(ax,mul(k,zm+108.851/Math.sin(Math.atan(SE.tf2))));
return{h,t,x,y,d,l1,l2,th,i,j,k,M,S,md:nrm(M),sd:k,jd:SE.jd+h/24}};
// a place: geodetic latitude, east longitude, metres above the sea; at sidereal angle th. Its position, and its east, north and up
const site=(la,lo,hm,th)=>{const f=la*D2R,u=Math.atan(.99664719*Math.tan(f)),A=(th+lo)*D2R,rs=.99664719*Math.sin(u)+hm/6378137*Math.sin(f),rc=Math.cos(u)+hm/6378137*Math.cos(f),
Z=[Math.cos(f)*Math.cos(A),Math.cos(f)*Math.sin(A),Math.sin(f)],E=[-Math.sin(A),Math.cos(A),0];
return{p:[rc*Math.cos(A),rc*Math.sin(A),rs],E,Z,N:cross(Z,E)}};
// the solar eclipse as seen from there: distance from the shadow's axis and the radii of the two shadows at that height
const circ=(st,la,lo,hm)=>{const o=site(la,lo,hm,st.th),ze=dot(o.p,st.k),m=Math.hypot(st.x-dot(o.p,st.i),st.y-dot(o.p,st.j)),L1=st.l1-ze*SE.tf1,L2=st.l2-ze*SE.tf2;
return{o,m,L1,L2,mag:(L1-m)/(L1+L2)}};
// where on the ground the axis of the Moon's shadow lands: [latitude, longitude], or null when it misses the Earth
const axis=st=>{const r2=st.x*st.x+st.y*st.y;if(r2>=1)return null;const p=add(add(mul(st.i,st.x),mul(st.j,st.y)),mul(st.k,Math.sqrt(1-r2)));
return[Math.atan(Math.tan(Math.asin(p[2]))/.99330562)/D2R,((Math.atan2(p[1],p[0])/D2R-st.th)%360+540)%360-180]};
// the Moon's own axes (towards the middle of the near side, east, north pole) from Cassini's laws, for a direction md to the Moon
const EPS=23.4393*D2R,CE=Math.cos(EPS),SI=Math.sin(EPS),ecl=v=>[v[0],v[1]*CE+v[2]*SI,v[2]*CE-v[1]*SI],equ=v=>[v[0],v[1]*CE-v[2]*SI,v[2]*CE+v[1]*SI];
const mframe=(md,jd)=>{const T=(jd-2451545)/36525,Om=(125.0445-1934.1363*T)*D2R,F=(93.2721+483202.0175*T)*D2R,I=1.54242*D2R,
Z=equ([-Math.sin(I)*Math.sin(Om),Math.sin(I)*Math.cos(Om),Math.cos(I)]),m=ecl(md),W=Math.atan2(m[1],m[0])-Om,be=Math.asin(m[2]),
l=Math.atan2(Math.sin(W)*Math.cos(be)*Math.cos(I)-Math.sin(be)*Math.sin(I),Math.cos(W)*Math.cos(be))-F,
e=mul(md,-1),a=nrm(sub(e,mul(Z,dot(e,Z)))),b=cross(Z,a);
return[add(mul(a,Math.cos(l)),mul(b,-Math.sin(l))),add(mul(a,Math.sin(l)),mul(b,Math.cos(l))),Z]};
const SPOLE=rad(286.13,63.87); // the Sun's north pole
const hms=h=>{h=((h%24)+24)%24;const s=Math.floor(h*3600+.5),p=v=>String(v).padStart(2,'0');return p(s/3600|0)+':'+p((s/60|0)%60)+':'+p(s%60)};
/* ---------------- shaders ---------------- */
const VS=`#version 300 es
void main(){gl_Position=vec4(vec2(gl_VertexID&1,gl_VertexID>>1)*4.-1.,0,1);}`;
const HEAD=`#version 300 es
precision highp float;precision highp int;precision highp sampler2D;
`;
// shared by the three pictures: camera, noise, and the sky as it is seen from inside the galaxy
const CMN=`
uniform vec2 uR;uniform float uT,uRow,uFv,uEx,uMw;uniform vec4 uA,uK;uniform sampler2D uS;uniform vec3 uCo;uniform mat3 uCm;out vec4 O;
// uA: bass, low-mid, mid, high (FFT bands) uK: kick env, hat env, integral of bass, integral of energy
// uCo, uCm, uFv: the camera - where, which way (columns right, up, forward), focal length. uEx: exposure
#define PI 3.14159265
#define TAU 6.2831853
#define sat(x) clamp(x,0.,1.)
mat2 rot(float a){float c=cos(a),s=sin(a);return mat2(c,-s,s,c);}
float h21(vec2 p){return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453);}
float h31(vec3 p){return fract(sin(dot(p,vec3(127.1,311.7,74.7)))*43758.5453);}
vec3 h33(vec3 p){p=vec3(dot(p,vec3(127.1,311.7,74.7)),dot(p,vec3(269.5,183.3,246.1)),dot(p,vec3(113.5,271.9,124.6)));return fract(sin(p)*43758.5453);}
float ns(vec3 x){vec3 i=floor(x),f=fract(x);f=f*f*(3.-2.*f);
return mix(mix(mix(h31(i),h31(i+vec3(1,0,0)),f.x),mix(h31(i+vec3(0,1,0)),h31(i+vec3(1,1,0)),f.x),f.y),
mix(mix(h31(i+vec3(0,0,1)),h31(i+vec3(1,0,1)),f.x),mix(h31(i+vec3(0,1,1)),h31(i+vec3(1,1,1)),f.x),f.y),f.z);}
float n2(vec2 x){vec2 i=floor(x),f=fract(x);f=f*f*(3.-2.*f);return mix(mix(h21(i),h21(i+vec2(1,0)),f.x),mix(h21(i+vec2(0,1)),h21(i+vec2(1,1)),f.x),f.y);}
float fbm(vec3 p){float a=.5,s=0.;for(int i=0;i<5;i++){s+=a*ns(p);p=p*2.03+7.1;a*=.5;}return s;}
float fb3(vec3 p){return .5*ns(p)+.25*ns(p*2.03+7.1)+.125*ns(p*4.1+3.3);}
float lum(vec3 c){return dot(c,vec3(.3,.55,.15));}
float sq(float x){return x*x;}
// how much of a disc of radius r still shows when a disc of radius R has its centre d away from it
float show(float d,float r,float R){
if(d>=R+r)return 1.;if(d<=R-r)return 0.;
float A=r*r*acos(clamp((d*d+r*r-R*R)/(2.*d*r),-1.,1.))+R*R*acos(clamp((d*d+R*R-r*r)/(2.*d*R),-1.,1.))-.5*sqrt(max((r+R-d)*(d+r-R)*(d-r+R)*(d+r+R),0.));
return sat(1.-A/(PI*r*r));}
// The sky, in the world's axes (x to the equinox, y north). GC is the direction of the galaxy's centre, GP its pole.
// Faint stars in three layers, thicker towards the plane of the galaxy; the Milky Way with its dust lanes and its bulge;
// the two Magellanic Clouds; three red nebulae where they really are (Carina, the Lagoon, Orion). The bright stars are drawn as points.
const vec3 GC=vec3(-.05488,-.48384,-.87344),GY=vec3(.49411,.74698,-.44483),GP=vec3(-.86767,.45598,-.19808);
vec3 sky(vec3 d,float mw){
vec3 g=vec3(dot(d,GC),dot(d,GY),dot(d,GP)),c=vec3(0);
float b=g.z,ab=abs(b),px=uFv*uR.y*.5,S=30.; // px: pixels to a radian. A star stays a point however far the lens is zoomed,
for(int i=0;i<5;i++){ // and the finer layers only appear once there is room for them
vec3 q=d*S,id=floor(q),h=h33(id+float(i)*17.);
float e=length(q-id-.5-(h.yzx-.5)*.7)*px/S;
c+=step(.86+.1*smoothstep(0.,.45,ab),h.x)*(.07+.93*h.z*h.z*h.z*h.z)*mix(vec3(1.,.72,.5),vec3(.6,.8,1.),h.y)*exp(-e*e*.5)*3.*smoothstep(4.,10.,px/S)/(1.+.5*float(i));
S*=1.95;
}
float l=atan(g.y,g.x),ce=exp(-l*l*1.3),w=mix(.075,.15,ce),n=fbm(g*3.5+2.),f=fbm(g*14.+7.),k=fb3(g*vec3(6.,6.,14.)+5.)*.62+fb3(g*vec3(21.,21.,44.)+1.)*.38;
float du=smoothstep(.37,.56,k)*exp(-(b+.012)*(b+.012)/.006)*(.65+.35*ce);
float m=exp(-b*b/(w*w))*(.25+.75*n)*(.3+2.1*f*f)*(.5+1.3*ce+.2*cos(l+1.3))*(1.-.93*du);
vec3 mc=mix(vec3(.4,.58,1.),vec3(1.,.78,.5),sat(ce*1.3))*m;
mc+=vec3(1.,.72,.45)*exp(-(l*l*7.+b*b*45.))*(1.-.85*du)*(.5+1.6*f)*1.2;
mc+=vec3(.6,.75,1.)*(exp(-(1.-dot(g,vec3(.1527,-.8257,-.543)))*520.)*.8+exp(-(1.-dot(g,vec3(.3876,-.6012,-.6988)))*1700.)*.5)*(.6+.8*n);
mc+=vec3(1.,.25,.4)*.45*(exp(-(1.-dot(g,vec3(.3023,-.9531,-.0105)))*9000.)*2.+exp(-(1.-dot(g,vec3(.9943,.1045,-.0209)))*30000.)*1.5+exp(-(1.-dot(g,vec3(-.825,-.4573,-.3322)))*40000.));
return c+mc*mw*.045;
}
`;
// The face of the Moon, built from the table of its dark plains: shared by the view from space and the view from the ground.
// n is a point on it in the Moon's own axes (x towards the Earth, y east, z north). Returns how bright the ground is, and how much it is mare.
const sph=(la,lo)=>[Math.cos(la*Math.PI/180)*Math.cos(lo*Math.PI/180),Math.cos(la*Math.PI/180)*Math.sin(lo*Math.PI/180),Math.sin(la*Math.PI/180)],
f4=v=>v.map(x=>(+x.toFixed(4)).toString().replace(/^(-?)0\./,'$1.').replace(/^(-?\d+)$/,'$1.')).join(','),
NM=MARE.length/4,NR=RAYS.length/3;
let mr=[],md=[],ry=[];
for(let i=0;i<NM;i++){mr.push('vec4('+f4([...sph(MARE[i*4],MARE[i*4+1]),MARE[i*4+2]*Math.PI/180])+')');md.push(f4([MARE[i*4+3]]))}
for(let i=0;i<NR;i++)ry.push('vec4('+f4([...sph(RAYS[i*3],RAYS[i*3+1]),RAYS[i*3+2]*Math.PI/180])+')');
const MOONF=`
const vec4 MR[${NM}]=vec4[${NM}](${mr});const float MD[${NM}]=float[${NM}](${md});const vec4 RY[${NR}]=vec4[${NR}](${ry});
vec2 malb(vec3 n,float foot){
vec3 w=normalize(n+(vec3(fb3(n*4.+1.),fb3(n*4.+4.),fb3(n*4.+8.))-.44)*.15+(vec3(ns(n*17.),ns(n*17.+4.),ns(n*17.+8.))-.5)*.03);
float m=0.;
for(int i=0;i<${NM};i++){float d=length(w-MR[i].xyz);m=max(m,MD[i]*smoothstep(MR[i].w*1.32,MR[i].w*.88,d));}
float tx=fbm(n*24.),a=mix(.2+.07*(tx-.5),.07+.03*tx,sat(m));
for(int i=0;i<${NR};i++){vec3 c=RY[i].xyz;float d=length(n-c),R=RY[i].w; // rays thrown out by the young craters
if(d<R){vec3 u=normalize(cross(c,vec3(.2,.3,.9))),v=cross(c,u);float an=atan(dot(n,v),dot(n,u));
a+=.11*exp(-d/R*3.5)*pow(n2(vec2(cos(an),sin(an))*5.+float(i)*9.),3.)*4.*smoothstep(0.,R*.05,d)+.1*smoothstep(R*.06,R*.02,d);}}
return vec2(a,sat(m));}
// relief: craters are cells of space; where the surface cuts a cell's sphere there is a bowl with a raised rim. Seven sizes, as many as can be resolved.
float crat(vec3 p){vec3 i=floor(p),h=h33(i);float r=.2+.25*h.x*h.x,d=length(p-i-.5-(h.yzx-.5)*(1.-2.*r)*.95)/r;
return h.z<.72?(min(d*d,1.)-1.)*.7+.35*smoothstep(.55,1.,d)*smoothstep(1.35,1.,d):0.;}
float mrel(vec3 n,float foot,float mare){
float h=0.,s=5.;
for(int k=0;k<8;k++){if(s*foot>.6)break;h+=crat(n*s+float(k)*13.7)*(k<2?.045:.105)/s*(1.-(k<3?.8:.45)*mare);s*=2.17;}
return h+fbm(n*12.)*.003*(1.-mare);}
`;
// The Earth and the Moon from space. The world is centred on the Earth, whose radius is 1; the Moon is where it was (about 57 away).
// The Earth's surface comes from the hand-drawn map; its shadow on the Moon, and the Moon's on it, from the published elements of the two eclipses.
const SPC=CMN+MOONF+`
uniform sampler2D uE,uL;uniform vec3 uSd,uSp,uMp,uCr,uAx;uniform mat3 uSb,uMb;uniform vec4 uBe;uniform vec2 uF;
uniform float uGs,uCn,uSe,uNi,uRf,uSc,uUb,uSk;uniform int uEc;
// uSd towards the Sun, uSp where it is. uMp the Moon; uCr the camera as seen from the Moon's centre (kept apart, for precision close to it).
// uMb turns the world into the Moon's own axes. uGs how far the Earth has turned. uEc 1: lunar eclipse, 2: solar eclipse.
// lunar: uAx the axis of the Earth's shadow, uF the radii of umbra and penumbra as seen from the Earth (tangents).
// solar: uSb turns the world into the axes of the fundamental plane, uBe = x, y, l1, l2; uAx the axis of the Moon's shadow.
const float RM=.2725,TF1=.0045984,TF2=.0045755;
float isph(vec3 o,vec3 d,float r){float b=dot(o,d),h=b*b-dot(o,o)+r*r;return h<0.?-1.:-b-sqrt(h);}
// weather: wet along the equator and in the westerlies, dry in the horse latitudes, and a deck of low cloud off Peru and Chile
float cloud(vec3 p,float lo){
float la=abs(p.y);
vec3 q=p*3.+vec3(0.,uT*.003,0.);
q+=.55*vec3(fb3(q*1.3+11.),fb3(q*1.3+3.),fb3(q*1.3+7.))-.24;
float th=.57-.09*exp(-la*la*90.)-.1*exp(-(la-.78)*(la-.78)*16.)+.07*exp(-(la-.4)*(la-.4)*40.);
th-=.1*exp(-(pow((lo+1.45)/.2,2.)+pow((p.y+.3)/.16,2.)));
return smoothstep(th-.02,th+.16,fbm(q*2.2+1.7));}
// the air seen edge-on: a ray that passes h above the ground, nearest the Earth's centre at q
vec3 limb(vec3 q,float h,vec3 rd,float ft){
// (the air is thinner than a pixel from far off: there it is drawn a pixel or two thick, and fainter)
float s=dot(q,uSd),day=smoothstep(-.14,.18,s),H1=max(.0022,ft*1.3),H2=max(.008,ft*3.),d1=exp(-h/H1)*sqrt(.0022/H1),d2=exp(-h/H2)*sqrt(.008/H2);
vec3 c=(vec3(.28,.55,1.)*d1*1.3+vec3(.1,.25,.9)*d2*.3)*day;
// along the terminator the light has come the long way through the air: red low down, gold above, blue on top
float tw=exp(-s*s*50.),bk=pow(sat(dot(rd,uSd)),6.);
vec3 sd=normalize(uSp-uCo);float as=109.1/length(uSp-uCo),de=length(cross(rd,sd))/as;
float bead=dot(rd,sd)>0.?exp(-max(de-1.,0.)/1.6):0.; // and brightest where the hidden Sun is nearest the edge
vec3 warm=mix(vec3(1.,.2,.03),vec3(1.,.8,.45),sat(h/(H1*2.5)));
c+=(warm*d1*(.5+7.*bk+60.*bead*bk)+vec3(.2,.5,1.)*d2*bk*(1.2+6.*bead))*tw;
return c;}
vec3 earth(vec3 p,vec3 rd,float t){
float la=asin(clamp(p.y,-1.,1.)),lo=mod(atan(p.z,p.x)-uGs+PI,TAU)-PI,mu=max(dot(p,-rd),0.),ala=abs(la);
vec2 uv=vec2(lo/TAU+.5,.5-la/PI);
float lod=max(log2(t*650./(uFv*uR.y*max(mu,.2))),0.);
vec3 m=textureLod(uE,uv,lod+.5).rgb;
float sf=textureLod(uE,uv,lod+2.5).r,dn=fbm(p*70.),land=smoothstep(.47,.53,m.r*.45+sf*.55+(dn-.48)*.3*(1.-smoothstep(1.5,4.,lod)));
float nl=dot(p,uSd),day=smoothstep(-.08,.22,nl);
// the Moon's shadow: how much of the Sun still shows from here
float ec=1.;
if(uEc==2){vec3 f=uSb*p;float L1=uBe.z-f.z*TF1,L2=uBe.w-f.z*TF2,mm=length(f.xy-uBe.xy);if(mm<L1)ec=show(2.*mm/(L1+L2),1.,(L1-L2)/(L1+L2));}
// the ground: jungle, grass, desert, rock, taiga; snow by latitude and height, further down in whichever hemisphere has winter
float hi=m.b*land*(.45+1.1*abs(2.*ns(p*230.)-1.)),win=sat((1.-2.*uSe)*sign(la)); // ranges broken into ridges
vec3 veg=mix(vec3(.022,.085,.02),vec3(.1,.125,.045),smoothstep(.12,.45,ala+dn*.2-.1));
veg=mix(veg,vec3(.075,.085,.05),smoothstep(.8,1.1,ala+dn*.15));
vec3 gr=mix(veg,vec3(.46,.33,.18)*(.75+.5*dn),sat(m.g*1.25));
gr=mix(gr,vec3(.21,.18,.15)*(.7+.6*dn),sat(hi*1.6-.25));
float sn=smoothstep(0.,.12,ala+hi*.5+dn*.12-(1.1-.24*win));
sn=max(sn,smoothstep(.5,.8,hi)*smoothstep(.2,.5,ala+.25*win));
sn=max(sn,smoothstep(1.02,1.08,la)*smoothstep(-1.36,-1.26,lo)*smoothstep(-.14,-.26,lo)); // Greenland
sn=max(sn,smoothstep(-1.04,-1.1,la)); // Antarctica
float ice=max(smoothstep(0.,.05,la+dn*.1-(1.3-.2*win)),smoothstep(0.,.05,-la+dn*.1-(1.24-.14*win))); // sea ice
vec3 oc=mix(vec3(.007,.028,.095),vec3(.02,.17,.22),smoothstep(.08,.5,sf)*.9);
vec3 srf=mix(mix(oc,vec3(.75,.84,.9),ice),mix(gr,vec3(.85,.88,.92),sn),land);
vec3 sc=mix(vec3(1.,.4,.14),vec3(1.,.97,.92),smoothstep(-.03,.32,nl));
sc=sc*ec+vec3(1.,.55,.3)*.012*(1.-ec); // inside the shadow only the glow of its far edge
float cl=cloud(p,lo),cs=cloud(normalize(p+uSd*.012),lo);
vec3 hv=normalize(uSd-rd);float sp=(pow(max(dot(p,hv),0.),160.)*5.+pow(max(dot(p,hv),0.),18.)*.3)*(1.-land)*(1.-ice);
vec3 col=(srf*(1.-.5*cs*(1.-cl))+vec3(1.,.9,.75)*sp*(1.-cs))*sc*day;
col=mix(col,vec3(.95)*sc*day,cl);
// the night side: cities
float li=textureLod(uL,uv,max(lod-1.,0.)).r;li*=li*(.4+1.6*ns(p*700.));
col+=vec3(1.,.7,.33)*li*land*(1.-day)*(1.-.85*cl)*uNi*4.+mix(srf,vec3(.8),cl)*vec3(.5,.62,1.)*(1.-day)*.006; // and a little moonlight
// the air in the way: thin overhead, thick towards the edge; gold along the terminator
float fr=pow(1.-mu,3.);
col=mix(col,vec3(.26,.5,1.)*sc*day*1.15,sat(fr*.9+.07));
col+=vec3(1.,.35,.1)*fr*exp(-nl*nl*45.)*.35*smoothstep(-.2,.0,nl);
return col+limb(p,0.,rd,t*2./(uFv*uR.y))*pow(1.-mu,5.)*.6;}
vec3 moon(vec3 pm,vec3 rd,float t){
vec3 n=pm/RM,nb=uMb*n;
float foot=t*2./(uFv*uR.y)/RM/max(dot(n,-rd),.15);
vec2 ma=malb(nb,foot);
vec3 t1=normalize(cross(nb,vec3(.3,.9,.2))),t2=cross(nb,t1);float e=max(foot*1.5,.0012);
float h0=mrel(nb,foot,ma.y),h1=mrel(normalize(nb+t1*e),foot,ma.y),h2=mrel(normalize(nb+t2*e),foot,ma.y);
vec2 gr=vec2(h1-h0,h2-h0)/e;
vec3 nn=normalize(nb-(t1*gr.x+t2*gr.y)*uRf)*uMb;
ma.x*=1.+.9*min(length(gr),1.2)*(1.-.5*ma.y); // steep ground is fresher, and brighter
float mu0=dot(nn,uSd),mu=max(dot(nn,-rd),.02),ls=(mu0>0.?2.*mu0/(mu0+mu):0.)*smoothstep(-.02,.07,dot(n,uSd)); // airless ground: no darkening towards the limb
ls*=1.+.35*pow(max(dot(-rd,uSd),0.),30.);
vec3 lt=vec3(1.,.98,.94)*ls;
if(uEc==1){
// the Earth's shadow. In the penumbra part of the Sun shows; in the umbra there is only sunlight bent through the Earth's air:
// red in the middle, paler towards the edge, and a turquoise fringe from the light that came through the ozone layer, which takes out the red
vec3 q=uMp+pm;float ca=dot(q,uAx),rho=length(q-uAx*ca)/ca,u=rho/uF.x;
vec3 um=mix(vec3(.9,.09,.015),vec3(1.,.42,.12),smoothstep(.2,.95,u))*exp(3.*(u-1.))*2.4e-4+vec3(.12,.7,.8)*smoothstep(.78,1.,u)*4e-4;
lt=lt*show(rho,.5*(uF.y-uF.x),.5*(uF.y+uF.x))+um*uUb*ls*smoothstep(1.4,1.,u);
}
vec3 ed=-normalize(uMp); // earthshine on its night side
lt+=vec3(.55,.7,1.)*max(dot(nn,ed),0.)*(.5+.5*dot(-ed,uSd))*1.3e-4;
return ma.x*lt;}
// the Sun, where nothing is in front of it: the disc, and a little of the corona round it
vec3 sun(vec3 rd){
vec3 sd=normalize(uSp-uCo);if(dot(rd,sd)<.7)return vec3(0);
float de=length(cross(rd,sd))*length(uSp-uCo)/109.1;
return vec3(1.,.95,.85)*smoothstep(1.03,.97,de)*400.*(.4+.6*sqrt(max(1.-de*de,0.)))+vec3(1.,.92,.85)*uSc/(1.+pow(de,2.6)*2.5)*smoothstep(40.,4.,de);}
// A shadow as something you can see: how far the ray runs inside a cone round the axis a from o, of radius r0+k*z, for z from 0 to zm
float cone(vec3 o,vec3 d,vec3 a,float r0,float k,float zm,float tm){
float zo=dot(o,a),zd=dot(d,a);vec3 po=o-a*zo,pd=d-a*zd;
float R=r0+k*zo,A=max(dot(pd,pd)-k*k*zd*zd,1e-9),B=dot(po,pd)-k*R*zd,h=B*B-A*(dot(po,po)-R*R);
if(h<0.)return 0.;h=sqrt(h);
float t0=max((-B-h)/A,0.),t1=min((-B+h)/A,tm),ta=-zo/zd,tb=(zm-zo)/zd;
if(abs(zd)>1e-6){t0=max(t0,min(ta,tb));t1=min(t1,max(ta,tb));}else if(zo<0.||zo>zm)return 0.;
return max(t1-t0,0.);}
void main(){
vec2 uv=(gl_FragCoord.xy*2.-uR)/uR.y;
vec3 rd=normalize(uCm*vec3(uv,uFv)),col;
float tE=isph(uCo,rd,1.),tM=isph(uCr,rd,RM),tm=1e5;
if(tM>0.&&(tE<0.||tM<tE)){tm=tM;col=moon(uCr+rd*tM,rd,tM);}
else if(tE>0.){tm=tE;col=earth(uCo+rd*tE,rd,tE);}
else col=sky(rd,uMw)*uSk/uEx+sun(rd); // the stars are not dimmed or burnt out by the exposure: they are there to be seen
if(tE<0.){float tc=-dot(uCo,rd);vec3 q=uCo+rd*tc;float h=length(q)-1.;if(tc>0.&&tc<tm&&h<.12)col+=limb(q/(1.+h),h,rd,tc*2./(uFv*uR.y));}
if(uCn>0.){
if(uEc!=2){ // the Earth's shadow, lit from inside by every sunrise and sunset at once
float L=cone(uCo,rd,-uSd,1.,-.004684,88.,tm),Lp=cone(uCo,rd,-uSd,1.,.00477,88.,tm);
col+=uCn/uEx*(vec3(1.,.1,.03)*(1.-exp(-L*.6))*.26+vec3(.25,.35,.75)*(1.-exp(-Lp*.3))*.05);
}
if(uEc>1){ // the Moon's: a needle that only just reaches the ground
float L=cone(uCr,rd,-uSd,RM,-TF2,59.,tm),Lp=cone(uCr,rd,-uSd,RM,TF1,61.,tm);
col+=uCn/uEx*(vec3(.55,.35,1.)*(1.-exp(-L*7.))*.8+vec3(.2,.4,.8)*(1.-exp(-Lp*.5))*.07);
}
}
O=vec4(min(max(col*uEx,0.),vec3(6e4)),1);
}`;
// The sky from the ground at Cerro Tololo, 2 July 2019. Axes: east, up, north. Brightness is in units where the daylight sky is about 1:
// the face of the Sun is then a million, the inner corona about 2, the corona four radii out a thousandth, the dark of the Moon less still.
// What a camera makes of that depends on the exposure - which is the point of the last part of the demo.
const GND=CMN+MOONF+`
uniform vec3 uSd,uTx,uTy,uMo,uAp,uAm;uniform mat3 uMb,uHq;uniform float uSr,uPa,uHd,uFl,uGd,uUm,uPx,uSz;
// uSd towards the Sun; uTx, uTy the directions across and up on the sky there. uSr the Sun's radius (tangent).
// uMo: the Moon's centre measured from the Sun's in solar radii, and its radius in solar radii. uPa: which way the Sun's north pole points.
// uAp: a point on the axis of the Moon's shadow as seen from here, in km; uUm: how many km from that axis make one solar radius between the two discs.
// uMb turns the sky's axes (across, up, towards us) into the Moon's own. uHq turns the ground's axes into the world's, for the stars. uAm: light scattered twice.
// uHd: 0 a plain photograph, 1 the range compressed as in a composite of many exposures. uFl: a solar filter. uGd: the landscape. uSz: the Sun's azimuth.
// how much of the Sun shows from a point x near here: it depends only on how far that point is from the shadow's axis
float lit(vec3 x){vec3 v=x-uAp;return show(length(v-uSd*dot(v,uSd))/uUm,1.,uMo.z);}
// The colour of the sky: sunlight scattered once by the air along the line of sight, ten steps out to 700 km. Blue is scattered most
// and so also lost most on the way: light from far-off air arrives red. In totality the air nearby is in shadow and the only light
// comes from beyond its edge, all round the horizon - a sunset in every direction.
vec3 air(vec3 rd){
const vec3 BR=vec3(.0058,.0135,.0331);
float el=max(rd.y,-.03),cs=dot(rd,uSd),ph=.75*(1.+cs*cs),pm=.07/pow(1.64-1.6*cs,1.5),s=0.,ds=3.;
vec3 L=vec3(0),tau=vec3(0);
for(int i=0;i<10;i++){
float sm=s+ds*.5,h=2.2+sm*el+sm*sm/12756.;if(h<0.)break;
float rho=exp(-h/8.);vec3 dt=BR*rho*ds;
L+=exp(-tau-dt*.5-BR*rho*8./max(uSd.y+.06,.06))*(dt*ph+vec3(.004)*exp(-h/1.5)*ds*pm)*lit(rd*sm+vec3(0,h-2.2-sm*el,0));
tau+=dt;s+=ds;ds*=1.55;
}
return L*5.;}
// The corona. Its light is sunlight scattered by electrons strung along the Sun's magnetic field, so it shows the field's shape:
// here a dipole whose outer lines the solar wind has dragged open, as it was at the minimum of the cycle in 2019. psi is constant along a line of force.
// Open lines fan out from the poles as plumes; closed ones arch over the equator as helmets, and beyond their tips a streamer runs out.
float psi(vec2 p,float a,float K){float ay=abs(p.y)+a,r=length(p);return p.x*p.x/(r*r*r)+K*(1.-ay/sqrt(ay*ay+p.x*p.x));}
float corona(vec2 q,float r){
float tot=0.;
for(int i=0;i<3;i++){
float fi=float(i);
vec2 p=rot((fi-1.)*.17+.08*sin(fi*2.))*q; // three sheets, each tilted a little: one sees right through the corona
p+=(vec2(n2(p*.7+fi*5.),n2(p*.7+fi*5.+9.))-.5)*.4*smoothstep(1.,3.,r);
float a=1.5+.25*fi,K=.82+.06*fi+.05*sign(p.x)*(1.-fi),ps=max(psi(p,a,K),0.),u=sign(p.x)*sqrt(ps),op=smoothstep(K*1.02,K*.9,ps);
float sd=fi*7.3+(p.y>0.?0.:3.7)*op,al=length(p)-uT*.04,fw=fwidth(u),th=0.,f=13.,am=.55; // hairs: fine across the lines of force, long along them, drifting slowly outward
for(int k=0;k<5;k++){th+=am*pow(n2(vec2(u*f+sd*(1.+float(k)),al*.11+float(k)*3.)),2.4)*smoothstep(.6,.15,f*fw);f*=2.45;am*=.86;}
float w=mix(.5,1.,smoothstep(.25,.85,ps/K))*(.6+.8*n2(vec2(u*3.5+sd,al*.1))); // the poles a little fainter; and broad differences from place to place
float hel=(1.-op)*(1.+.9*exp(-sq((ps-K)/(.07*K)))); // closed loops, brightest along their outer edge
float stalk=op*exp(-sq(p.y/(.04+.03*abs(p.x))))*smoothstep(1.2,2.2,abs(p.x));
tot+=w*(.22+th)*(op+hel*1.15)+stalk*(.5+th);
}
return tot/3.;}
// prominences: hydrogen held above the edge of the Sun. Where round the limb (from north through east), how high, how wide
const vec3 PRM[5]=vec3[5](vec3(.96,.09,.06),vec3(1.14,.05,.04),vec3(2.02,.11,.07),vec3(4.4,.06,.045),vec3(5.25,.08,.055));
float prom(vec2 p,float r){
float a=atan(-p.x,p.y),s=0.;
for(int i=0;i<5;i++){vec3 P=PRM[i];float da=a-P.x;da=atan(sin(da),cos(da));
vec2 lc=vec2(da/P.z,(r-1.)/P.y); // across and up, in units of its own size
if(abs(lc.x)<1.6&&lc.y<1.6){
float f=fbm(vec3(lc*vec2(5.,3.)+float(i)*4.,uT*.05)),g=ns(vec3(lc.x*14.+f*3.,lc.y*2.5,float(i)));
float arch=exp(-sq((length(lc*vec2(1.,.9))-.75)/.15)); // a loop standing on the limb
float body=smoothstep(1.,.2,length(lc-vec2(.2,.3))*1.25+(f-.5)*1.3); // and a ragged cloud hanging inside it
s+=(arch*(.4+g)+body*(.25+1.3*g*f))*smoothstep(1.35,.9,length(lc));}}
return s*step(1.,r);}
void main(){
vec2 uv=(gl_FragCoord.xy*2.-uR)/uR.y;
vec3 rd=normalize(uCm*vec3(uv,uFv));
float cz=dot(rd,uSd),px=2./(uFv*uR.y),pxs=px/uSr;
vec2 q=vec2(dot(rd,uTx),dot(rd,uTy))/max(cz,.05)/uSr;
float r=cz>0.?length(q):1e3;
vec3 skc=air(rd)+uAm,col=skc;
col+=(sky(uHq*rd,uMw)*exp(-lum(skc)*uEx*4.)*.3+vec3(.022,.04,.075)*uHd)/uEx*step(0.,rd.y); // stars, where the sky as exposed is dark enough
if(r<70.){
vec2 dm=q-uMo.xy,ps=rot(-uPa)*q;float rm=length(dm),am=atan(dm.y,dm.x),rr=max(r,1.);
// the Moon's edge is not smooth: mountains and valleys, a few seconds of arc high - enough to break the last sunlight into beads
float lim=uMo.z*(1.+(n2(vec2(cos(am),sin(am))*40.+3.)-.5)*.0045+(n2(vec2(cos(am),sin(am))*150.)-.5)*.0018),mc=sat((lim-rm)/pxs+.5);
float kc=.053*pow(rr,-2.5)+1.4*pow(rr,-7.)+2.6*pow(rr,-17.),st=corona(ps,rr);
vec3 cor=mix(vec3(1.,.98,.96)*kc*st,vec3(.92,.96,1.)*pow(min(kc,1.3),.25)*(.12+st*.88)*.42,uHd);
cor+=vec3(1.,.2,.4)*(exp(-(rr-1.)/.0035)*14.+prom(ps,r)*2.6)*mix(1.,.35,uHd); // the chromosphere, and prominences standing on it
float ph=sat((1.-r)/pxs+.5);
vec3 fr=mix(cor,vec3(1.,.94,.86)*1e6*(.42+.58*sqrt(max(1.-r*r,0.))),ph); // the Sun's own face, darker towards its edge
vec2 dd=dm/uMo.z;float dz=sqrt(max(1.-dot(dd,dd),0.)); // the Moon: its night side, lit by the Earth
vec3 mn=vec3(.75,.85,1.)*malb(uMb*vec3(dd,dz),pxs/uMo.z).x*(.5+.5*dz)*mix(.03,.55,uHd);
col+=mix(fr,mn,mc);
if(uFl>0.)col=mix(col,vec3(1.,.5,.12)*ph*(1.-mc)*(.42+.58*sqrt(max(1.-r*r,0.)))*1.5/uEx,uFl);
}
if(uGd>0.&&rd.y<.25){
// the ground: four ranges of hills one behind another, each paler with distance, and on the nearest the domes of the observatory
float az=atan(rd.x,rd.z),sunl=lit(vec3(0));
vec3 hz=air(normalize(vec3(rd.x,.012,rd.z)))+uAm,gl=vec3(.3,.21,.13)*(vec3(1.,.8,.55)*sunl*.5*sat(uSd.y*4.)+lum(hz)*.05+uAm*9.);
for(int i=0;i<4;i++){
float fi=float(i),z=az*(3.+fi*2.5)+fi*13.+uPx*(.01+.03*fi*fi);
float hh=mix(.03,-.035,fi/3.)+(.02+.014*fi)*(n2(vec2(z,fi))+.5*n2(vec2(z*2.3,fi+5.))+.25*n2(vec2(z*5.1,fi+9.))-.7);
if(i==3){float da=az-uSz+uPx*.28;da=atan(sin(da),cos(da));
for(int k=0;k<5;k++){vec3 D=vec3(-.24,.022,.034);if(k==1)D=vec3(-.14,.009,.014);if(k==2)D=vec3(-.09,.011,.017);if(k==3)D=vec3(.19,.014,.021);if(k==4)D=vec3(.3,.008,.013);
float x=abs(da-D.x);if(x<D.z)hh=max(hh,D.y-.02+sqrt(D.z*D.z-x*x));}}
col=mix(col,mix(gl*(.55+.45*n2(vec2(z*30.,rd.y*260.)))*(.55+.45*sat(1.-(hh-rd.y)*14.)),hz*.8,mix(.8,.06,fi/3.))*(1.-.5*fi/3.),sat((hh-rd.y)/px+.5));
}
}
O=vec4(min(max(col*uEx,0.),vec3(6e4)),1);
}`;
// The galaxy from outside: a thin disc, marched through. Two long arms and two lesser ones wound round a bar; young blue stars and red
// clouds of hydrogen along them, dust on their inner edges, the old yellow stars of the bulge. Radius 1 is about fifty thousand light-years.
const GAL=CMN+`
void main(){
vec2 uv=(gl_FragCoord.xy*2.-uR)/uR.y;
vec3 rd=normalize(uCm*vec3(uv,uFv)),col=vec3(0);
const float H=.08;
float sg=rd.y<0.?-1.:1.,t0=max((-H*sg-uCo.y)/rd.y,0.),t1=min((H*sg-uCo.y)/rd.y,t0+3.5),tr=1.;
if(t1>t0){
float dt=(t1-t0)/34.,t=t0+dt*h21(gl_FragCoord.xy+fract(uT)*7.);
for(int i=0;i<34;i++){
vec3 p=uCo+rd*t;float r=length(p.xz);
if(r<1.4){
float ph=atan(p.z,p.x)*2.-log(r+.02)*7.+.6,n=fb3(p*vec3(9.,30.,9.)+3.)*1.14;
float a=pow(.5+.5*cos(ph),2.5)+.45*pow(.5+.5*cos(ph*2.+2.1),4.),du=pow(.5+.5*cos(ph+.75),5.)+.4*pow(.5+.5*cos(ph*2.+3.2),6.);
float hz=.012+.02*r,disc=exp(-r/.27)*exp(-abs(p.y)/hz),tp=smoothstep(1.15,.6,r)*smoothstep(.06,.2,r);
float bar=exp(-(sq(dot(p.xz,vec2(.9,.44))/.17)+sq(dot(p.xz,vec2(-.44,.9))/.06)+sq(p.y/.045))),bul=exp(-length(p*vec3(1.,1.7,1.))/.05);
vec3 e=vec3(1.,.8,.52)*(bul*8.+bar*4.+disc*1.)+vec3(.5,.68,1.)*disc*a*tp*(1.+5.*n*n)*5.
+vec3(1.,.18,.35)*disc*a*tp*smoothstep(.7,.85,ns(p*vec3(34.,60.,34.)))*36.;
col+=tr*e*dt*6.;tr*=exp(-disc*du*tp*smoothstep(1.,.45,r)*(.3+1.4*n)*exp(-abs(p.y)/(hz*.5))*540.*dt);
}
t+=dt;if(tr<.02)break;
}
}
col+=sky(rd,0.)*.3*tr;
O=vec4(min(max(col*uEx,0.),vec3(6e4)),1);
}`;
// Points and lines. The bright stars, each where it really is, as points; markers and tracks placed by the script; and, for the
// fall into the galaxy, a box of stars round the camera drawn as streaks (two ends of a line each, from the vertex number alone).
const PV=`#version 300 es
precision highp float;
layout(location=0)in vec4 aP;layout(location=1)in vec4 aC;
uniform mat3 uCm,uSf;uniform vec3 uCo,uBx,uVl;uniform vec4 uO0,uO1;uniform float uFv,uAsp,uPx,uT,uDk,uHo,uMd,uTk;
out vec4 vC;
// aP: a direction and a magnitude (a star, aC.a = 0) or a place and a size. aC: colour. uSf turns the sky's axes into the picture's.
// uO0, uO1: two balls that hide what is behind them. uHo: the horizon. uDk: how dark the sky is. uTk: twinkling.
float hit(vec3 d,vec4 s,float tm){vec3 oc=uCo-s.xyz;float b=dot(oc,d),h=b*b-dot(oc,oc)+s.w*s.w;if(h<0.)return 0.;float t=-b-sqrt(h);return t>0.&&t<tm?1.:0.;}
vec3 hh(int n){uvec3 v=uvec3(n)*uvec3(1597334673u,3812015801u,2798796415u)+uvec3(12345u,67891u,424243u);v^=v>>15;v*=2246822519u;v^=v>>13;v*=3266489917u;v^=v>>16;return vec3(v)/4294967295.;}
void main(){
vec3 d,c=aC.rgb;float tm=1e9,br=1.,sz=aP.w;
if(uMd>.5){ // a streak
vec3 h=hh(gl_VertexID>>1),p=mod(h*uBx-uCo,uBx)-.5*uBx-uVl*float(gl_VertexID&1);
tm=length(p);d=p/tm;c=mix(vec3(1.,.75,.5),vec3(.6,.8,1.),h.x)*(.3+h.y*h.y*3.)*uDk/(1.+tm*tm*uMd);sz=1.;
vec3 v=d*uCm;gl_Position=v.z>.01?vec4(v.x*uFv/uAsp,v.y*uFv,0.,v.z):vec4(2.,2.,2.,1.);gl_PointSize=1.;vC=vec4(c,.7);return;
}
if(aC.a<.5){d=uSf*aP.xyz;float b=min(8.*pow(2.512,-aP.w),45.);sz=1.5+1.7*pow(b,.27);
br=b*uDk*(1.+uTk*sin(uT*(7.+mod(float(gl_VertexID),5.))+float(gl_VertexID)));if(d.y<uHo)br=0.;}
else{d=aP.xyz-uCo;tm=length(d);d/=tm;tm*=.9995;if(aC.a>1.5)tm=0.;}
if(hit(d,uO0,tm)+hit(d,uO1,tm)>0.)br=0.;
vec3 v=d*uCm;if(v.z<.01)br=0.;
gl_Position=br>0.?vec4(v.x*uFv/uAsp,v.y*uFv,0.,v.z):vec4(2.,2.,2.,1.);
gl_PointSize=max(sz*uPx,1.);vC=vec4(c*br,.7);
}`;
const PF=`#version 300 es
precision highp float;in vec4 vC;out vec4 O;
void main(){O=vec4(vC.rgb*smoothstep(.5,.5-.5*vC.a,length(gl_PointCoord-.5)),1);}`;
const LF=`#version 300 es
precision highp float;in vec4 vC;out vec4 O;
void main(){O=vec4(vC.rgb,1);}`;
const PRE=`#version 300 es
precision highp float;uniform sampler2D uC;uniform vec2 uR,uI;uniform float uTh;out vec4 O;
`;
// dual-filter bloom: 5-tap downsample (soft threshold on the first pass), 8-tap tent upsample
const DOWN=PRE+`void main(){vec2 v=gl_FragCoord.xy/uR;
vec3 s=texture(uC,v).rgb*4.+texture(uC,v+uI).rgb+texture(uC,v-uI).rgb+texture(uC,v+uI*vec2(1,-1)).rgb+texture(uC,v+uI*vec2(-1,1)).rgb;s*=.125;
if(uTh>0.){s=min(s,vec3(40.));s*=smoothstep(.5,1.8,max(s.r,max(s.g,s.b)));}
O=vec4(s,1);}`;
const UP=PRE+`void main(){vec2 v=gl_FragCoord.xy/uR;vec3 e=vec3(uI,0.);
vec3 s=texture(uC,v+e.xz).rgb+texture(uC,v-e.xz).rgb+texture(uC,v+e.zy).rgb+texture(uC,v-e.zy).rgb
+2.*(texture(uC,v+uI*.5).rgb+texture(uC,v-uI*.5).rgb+texture(uC,v+uI*vec2(.5,-.5)).rgb+texture(uC,v+uI*vec2(-.5,.5)).rgb);
O=vec4(s/12.,1);}`;
const COMP=`#version 300 es
precision highp float;uniform sampler2D uC,uB,uX,uS;uniform vec2 uR;uniform vec3 uSs,uFc;uniform float uT,uF,uXa,uRow,uFl,uFi,uSh,uBm,uSt;out vec4 O;
vec3 aces(vec3 x){return clamp((x*(2.51*x+.03))/(x*(2.43*x+.59)+.14),0.,1.);}
float hh(vec2 p){return fract(sin(dot(p,vec2(12.9898,78.233)))*43758.5453);}
float n1(float x,float n){x=fract(x)*n;float i=floor(x),f=x-i;f=f*f*(3.-2.*f);return mix(hh(vec2(i,n)),hh(vec2(mod(i+1.,n),n)),f);} // noise round a circle
float hx(vec2 q,float R){q=abs(q);float d=max(q.x*.866+q.y*.5,q.y)/R;return smoothstep(1.,.9,d)*(.3+.7*d*d);} // a ghost: a soft hexagon, brighter at its rim
// what a bright sun does inside a lens: a veil, rays, the six spikes of the diaphragm, a streak, ghosts strung along the line through the middle of the frame, a halo
vec3 flare(vec2 p,vec2 s){
vec2 d=p-s;float r=length(d),a=atan(d.y,d.x)/6.2832+s.x*.07;
vec3 c=vec3(1.,.9,.75)*(.02/(r*r*30.+.03)+.012/(r+.03));
c+=vec3(1.,.85,.65)*(pow(n1(a,9.)*n1(a+.3,23.),2.)*2.2+pow(abs(cos(a*18.85+.4)),90.)*1.6)*.09/(r*5.+.12)*exp(-r*1.5);
c+=vec3(.35,.55,1.)*exp(-abs(d.y)*70.)/(1.+d.x*d.x*2.5)*.3;
c+=vec3(.5,.8,.4)*hx(p+s*.35,.07)*.06+vec3(.3,.5,1.)*hx(p+s*.7,.12)*.05+vec3(1.,.6,.3)*hx(p+s*1.15,.05)*.09
+vec3(.45,.3,.9)*hx(p+s*1.6,.22)*.035+vec3(.8,.9,1.)*hx(p-s*.45,.035)*.08;
vec3 hl=(vec3(r)-vec3(.4,.42,.44))/.018;
return c+exp(-hl*hl)*.05*n1(a,4.);}
void main(){
vec2 v=gl_FragCoord.xy/uR,c=v-.5,p=(gl_FragCoord.xy*2.-uR)/uR.y;float r2=dot(c,c);
vec2 o=c*r2*(.012+.03*uFl);
vec3 col=vec3(texture(uC,v-o).r,texture(uC,v).g,texture(uC,v+o).b);
col+=texture(uB,v).rgb*uBm;
if(uFi>0.)col+=flare(p,uSs.xy)*uFc*uFi;
col*=1.-1.1*r2;
col+=uFl*.3;
col=pow(aces(col*1.15),vec3(.4545));
float sp=texture(uS,vec2(abs(c.x)*2.,uRow)).r;
col+=uSt*.35*step(gl_FragCoord.y/uR.y,.003+.035*sp)*vec3(1.,.75,.45);
vec4 tx=texture(uX,vec2(gl_FragCoord.x/uR.x,1.-gl_FragCoord.y/uR.y));
col=mix(col,tx.rgb,tx.a*uXa);
col+=(hh(gl_FragCoord.xy+uT*61.)-.5)*.035;
col*=smoothstep(0.,.06,uSh*.6-abs(v.y-.5))*uF; // the shutter: two blades that meet in the middle
O=vec4(col,1);
}`;
/* ---------------- GL setup ---------------- */
const C=document.getElementById('c'),gl=C.getContext('webgl2',{antialias:false,alpha:false,powerPreference:'high-performance'});
if(!gl){document.body.innerHTML='<p style="color:#fff;font:16px sans-serif;padding:2em">This demo needs WebGL2.</p>';return}
const HF16=gl.getExtension('EXT_color_buffer_float')||gl.getExtension('EXT_color_buffer_half_float');
gl.getExtension('KHR_parallel_shader_compile');
const IF=HF16?gl.RGBA16F:gl.RGBA8,TY=HF16?gl.HALF_FLOAT:gl.UNSIGNED_BYTE;
const VA0=gl.createVertexArray(),VA1=gl.createVertexArray();
gl.bindVertexArray(VA0);
const tex=(unit,wrapT)=>{const t=gl.createTexture();gl.activeTexture(gl.TEXTURE0+unit);gl.bindTexture(gl.TEXTURE_2D,t);
gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,wrapT||gl.CLAMP_TO_EDGE);return t};
const target=(w,h)=>{const t=tex(1);gl.texImage2D(gl.TEXTURE_2D,0,IF,w,h,0,gl.RGBA,TY,null);
const f=gl.createFramebuffer();gl.bindFramebuffer(gl.FRAMEBUFFER,f);gl.framebufferTexture2D(gl.FRAMEBUFFER,gl.COLOR_ATTACHMENT0,gl.TEXTURE_2D,t,0);return{t,f,w,h}};
const prog=(fs,vs)=>{const p=gl.createProgram(),sh=[];
for(const[ty,src]of[[gl.VERTEX_SHADER,vs||VS],[gl.FRAGMENT_SHADER,fs]]){const s=gl.createShader(ty);gl.shaderSource(s,src);gl.compileShader(s);gl.attachShader(p,s);sh.push(s)}
gl.linkProgram(p);return{p,sh,u:null}};
const errs=[];
const use=o=>{
if(!o.u){o.u={};
if(!gl.getProgramParameter(o.p,gl.LINK_STATUS)){const e=gl.getProgramInfoLog(o.p)+'\n'+gl.getShaderInfoLog(o.sh[0])+'\n'+gl.getShaderInfoLog(o.sh[1]);errs.push(e);console.error('shader',e)}
for(let i=0,n=gl.getProgramParameter(o.p,gl.ACTIVE_UNIFORMS);i<n;i++){const a=gl.getActiveUniform(o.p,i);o.u[a.name.replace('[0]','')]=gl.getUniformLocation(o.p,a.name)}}
gl.useProgram(o.p);return o.u};
// set uniforms from an object: a number is a float, {i} an int, {m} a mat3, a short array a vector
const su=(u,o)=>{for(const k in o){const l=u[k],v=o[k];if(l==null)continue;
if(typeof v=='number')gl.uniform1f(l,v);else if(v.i!=null)gl.uniform1i(l,v.i);else if(v.m)gl.uniformMatrix3fv(l,false,v.m);
else if(v.length==2)gl.uniform2fv(l,v);else if(v.length==3)gl.uniform3fv(l,v);else gl.uniform4fv(l,v)}};
const PS={spc:prog(HEAD+SPC),gnd:prog(HEAD+GND),gal:prog(HEAD+GAL)},PP=prog(PF,PV),PL=prog(LF,PV),PD=prog(DOWN),PU=prog(UP),PC=prog(COMP);
// spectrogram texture: 256 log-frequency bins x 128 rows of history (ring buffer)
const NB=256,HR=128,cur=new Float32Array(NB),row8=new Uint8Array(NB);
const TS=tex(0,gl.REPEAT);gl.pixelStorei(gl.UNPACK_ALIGNMENT,1);
gl.texImage2D(gl.TEXTURE_2D,0,gl.R8,NB,HR,0,gl.RED,gl.UNSIGNED_BYTE,new Uint8Array(NB*HR));
// text overlay
const TX=tex(3),XC=document.createElement('canvas'),X=XC.getContext('2d');
// the two maps of the Earth
for(const[un,cv]of[[5,EC],[6,LC]]){tex(un);gl.texImage2D(gl.TEXTURE_2D,0,gl.RGBA,gl.RGBA,gl.UNSIGNED_BYTE,cv);gl.generateMipmap(gl.TEXTURE_2D);
gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR_MIPMAP_LINEAR);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.REPEAT)}
// the stars as points: where (in the world's axes), how bright, what colour; then room for whatever else a shot wants to mark
const NS=STAR.length/4,NXM=1600,SB=new Float32Array((NS+NXM)*8),VB=gl.createBuffer(),SCL=[[.62,.75,1],[.85,.9,1],[1,.96,.85],[1,.8,.55],[1,.55,.35]];
for(let i=0;i<NS;i++)SB.set([...w3(rad(STAR[i*4]*15,STAR[i*4+1])),STAR[i*4+2],...SCL[STAR[i*4+3]],0],i*8);
gl.bindVertexArray(VA1);gl.bindBuffer(gl.ARRAY_BUFFER,VB);gl.bufferData(gl.ARRAY_BUFFER,SB,gl.DYNAMIC_DRAW);
gl.enableVertexAttribArray(0);gl.vertexAttribPointer(0,4,gl.FLOAT,false,32,0);gl.enableVertexAttribArray(1);gl.vertexAttribPointer(1,4,gl.FLOAT,false,32,16);
gl.bindVertexArray(VA0);
let W=0,H=0,sc=1,scMax=1,S=null,B=[],txt='',txtDirty=1;
// draw once with every program now, so that none of them is first built in the middle of the music
gl.activeTexture(gl.TEXTURE1);{const t=target(1,1);gl.viewport(0,0,1,1);for(const o of[PS.spc,PS.gnd,PS.gal,PD,PU,PC]){use(o);gl.drawArrays(gl.TRIANGLES,0,3)}
use(PL);gl.drawArrays(gl.LINES,0,2);gl.bindVertexArray(VA1);use(PP);gl.drawArrays(gl.POINTS,0,1);gl.bindVertexArray(VA0);gl.deleteTexture(t.t);gl.deleteFramebuffer(t.f)}
gl.bindFramebuffer(gl.FRAMEBUFFER,null);gl.clearColor(0,0,0,1);gl.clear(gl.COLOR_BUFFER_BIT);
const free=o=>{if(o){gl.deleteTexture(o.t);gl.deleteFramebuffer(o.f)}};
const alloc=()=>{free(S);B.forEach(free);B=[];
let w=Math.max(2,W*sc|0),h=Math.max(2,H*sc|0);S=target(w,h);
for(let i=0;i<6;i++){w=Math.max(1,w>>1);h=Math.max(1,h>>1);B.push(target(w,h))}};
const resize=()=>{const d=Math.min(devicePixelRatio||1,2);W=C.width=Math.max(2,innerWidth*d|0);H=C.height=Math.max(2,innerHeight*d|0);
scMax=Math.min(1,Math.sqrt(3.6e6/(W*H)));sc=Math.min(scMax,Math.sqrt(1.4e6/(W*H)));alloc();txtDirty=1}; // start modest, grow if there is room
addEventListener('resize',resize);resize();
/* ---------------- audio + FFT ---------------- */
let ctx=null,an=null,node=null,t0=null,ext=null,extT=0,fb=null,lo=null,hi=null,mode='';
const start=async()=>{
if(ctx){ctx.resume();return}
ctx=new(window.AudioContext||window.webkitAudioContext)({latencyHint:'playback'});ctx.resume();
an=ctx.createAnalyser();an.fftSize=2048;an.smoothingTimeConstant=.35;an.minDecibels=-85;an.maxDecibels=-18;an.connect(ctx.destination);
fb=new Uint8Array(1024);
const hz=ctx.sampleRate/2048;lo=new Float32Array(NB);hi=new Float32Array(NB);
for(let i=0;i<NB;i++){lo[i]=35*2**(i/NB*8.8)/hz;hi[i]=35*2**((i+1)/NB*8.8)/hz}
try{ // data: URL, because Blob URL worklets fail to load from file:// in Chrome
await ctx.audioWorklet.addModule('data:text/javascript;charset=utf-8,'+encodeURIComponent(SYN+';registerProcessor("s",class extends AudioWorkletProcessor{constructor(){super();this.f=SYN(sampleRate);this.n=0}process(i,o){const p=this.f(o[0][0],o[0][1]);if(!(this.n++&31))this.port.postMessage([p,currentTime]);return true}})'));
node=new AudioWorkletNode(ctx,'s',{numberOfInputs:0,outputChannelCount:[2]});
node.port.onmessage=e=>{t0=e.data[1]-(e.data[0]-128)/ctx.sampleRate};mode='worklet';
}catch(e){ // no worklet: same synth on the main thread
const f=SYN(ctx.sampleRate);node=ctx.createScriptProcessor(2048,0,2);
node.onaudioprocess=e=>{const b=e.outputBuffer,p=f(b.getChannelData(0),b.getChannelData(1));t0=e.playbackTime-(p-2048)/ctx.sampleRate};mode='scriptprocessor: '+e;
}
if(!ext)node.connect(an);
};
// your own music: drop a file, the FFT does the rest
const play=async file=>{
await start();
const buf=await ctx.decodeAudioData(await file.arrayBuffer());
if(ext)ext.stop();else node.disconnect();
ext=ctx.createBufferSource();ext.buffer=buf;ext.loop=true;ext.connect(an);ext.start();extT=ctx.currentTime;
};
let steady=0; // S: no flicker in the cuts
addEventListener('dragover',e=>e.preventDefault());
addEventListener('drop',e=>{e.preventDefault();const f=e.dataTransfer.files[0];if(f)play(f).catch(e=>console.error(e))});
addEventListener('pointerdown',start);
addEventListener('keydown',e=>{
if(e.key=='f'||e.key=='F'){try{(document.fullscreenElement?document.exitFullscreen():document.documentElement.requestFullscreen()).catch(()=>{})}catch(e){}}
if(e.key=='s'||e.key=='S'){steady^=1;txtDirty=1}
start()});
const band=[0,0,0,0],peak=[.2,.2,.2,.2],A=[0,0,0,0],K=[0,0,0,0],RG=[0,52,116,186,256];
let pb=0,ph=0,row=0,racc=0;
const analyse=dt=>{
if(an&&ctx.state=='running'){
an.getByteFrequencyData(fb);
for(let i=0;i<NB;i++){
const a=lo[i],b=hi[i];let v=0,k=a|0;
if(b-a<1)v=fb[k]+(fb[k+1]-fb[k])*(a-k);else for(;k<b;k++)v=Math.max(v,fb[k]);
{const x=i/NB;v=Math.max(0,v/255-.3+.14*x)/.7*(.8+1.2*x)}v=Math.min(1,v*v*1.3);
cur[i]+=(v-cur[i])*(v>cur[i]?.7:1-Math.exp(-dt*9));
}
}else for(let i=0;i<NB;i++)cur[i]*=.9;
for(let j=0;j<4;j++){
let s=0;for(let i=RG[j];i<RG[j+1];i++)s+=cur[i];s/=RG[j+1]-RG[j];
band[j]=s;peak[j]=Math.max(peak[j]*Math.exp(-dt*.05),s,.12);
A[j]+=(Math.min(1,s/peak[j])-A[j])*.5;
}
const d=Math.exp(-dt*5);
K[0]=Math.max(K[0]*d,Math.min(1,Math.max(0,band[0]-pb)*7));pb=band[0];
K[1]=Math.max(K[1]*d,Math.min(1,Math.max(0,band[3]-ph)*9));ph=band[3];
K[2]+=dt*A[0];K[3]+=dt*(A[0]+A[1]+A[2]+A[3])*.25;
racc+=dt;
if(racc>=1/61){racc=Math.min(racc-1/60,.02);row=(row+1)%HR;
for(let i=0;i<NB;i++)row8[i]=cur[i]*255;
gl.activeTexture(gl.TEXTURE0);gl.bindTexture(gl.TEXTURE_2D,TS);gl.texSubImage2D(gl.TEXTURE_2D,0,0,row,NB,1,gl.RED,gl.UNSIGNED_BYTE,row8)}
};
/* ---------------- timeline ---------------- */
// Time runs in beats: ninety a minute, four to a bar, sixty-eight bars. Every cut is on a beat (the list of cuts lives in the synth,
// which has to click on each one). A shot is a function that fills in s: which picture, the camera, the exposure, what to write.
const{CUT,MAJ,BRK,RMP}=SYN(0);
const rows=(a,b,c)=>[a[0],b[0],c[0],a[1],b[1],c[1],a[2],b[2],c[2]],I3=[1,0,0,0,1,0,0,0,1]; // a matrix with these rows, the way GL takes it
const showJ=(d,r,R)=>{if(d>=R+r)return 1;if(d<=R-r)return 0;
const A=r*r*Math.acos(cl((d*d+r*r-R*R)/(2*d*r),-1,1))+R*R*Math.acos(cl((d*d+R*R-r*r)/(2*d*R),-1,1))-.5*Math.sqrt(Math.max((r+R-d)*(d+r-R)*(d-r+R)*(d+r+R),0));
return cl(1-A/(Math.PI*r*r))};
const wrapd=a=>((a%360)+360)%360*D2R,ez=x=>x*x*(3-2*x),MN=['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'],ML=[31,28,31,30,31,30,31,31,30,31,30,31];
const CTIO=[-30.16917,-70.80639,2207],GCW=[-.05488,-.48384,-.87344],SUNG=[.5,0,.14];
const place=(la,lo,th,r=1)=>mul(w3(site(la,lo,0,th).p),r); // a place on the ground, in the world
const bis=(f,a,b)=>{const fa=f(a)<0;for(let i=0;i<50;i++){const m=(a+b)/2;if((f(m)<0)==fa)a=m;else b=m}return a};
// second and third contact at Cerro Tololo: when the edge of the umbra passes over it
const fC=h=>{const c=circ(sol(h),...CTIO);return c.m+c.L2},C2=bis(fC,20.5,20.66),C3=bis(fC,20.66,20.8);
// the line down the middle of the Moon's shadow, as places on the ground
const TRK=[];for(let h=18.04;h<20.74;h+=.0125){const a=axis(sol(h));if(a)TRK.push(a)}
// the planets, well enough to put each in the right part of the sky: a, e, inclination, node, perihelion, mean longitude, degrees a century; then magnitude and colour
const PLN=[[.3871,.2056,7.005,48.33,77.46,252.25,149472.67,1.4,3],[.7233,.0068,3.395,76.68,131.6,181.98,58517.82,-3.9,2],[1,.0167,0,0,102.94,100.46,35999.37],
[1.5237,.0934,1.85,49.56,336.04,355.45,19140.3,1.8,4],[5.2026,.0484,1.303,100.46,14.73,34.4,3034.75,-2.5,2],[9.5549,.0555,2.489,113.67,92.6,49.95,1222.49,.2,2]];
const helio=(k,T)=>{const[a,e,i,Om,w,L,n]=PLN[k],M=(L+n*T-w)*D2R,c=Math.cos,s=Math.sin;let E=M;for(let j=0;j<9;j++)E=M+e*s(E);
const x=a*(c(E)-e),y=a*Math.sqrt(1-e*e)*s(E),p=(w-Om)*D2R,O=Om*D2R,I=i*D2R;
return[(c(p)*c(O)-s(p)*s(O)*c(I))*x-(s(p)*c(O)+c(p)*s(O)*c(I))*y,(c(p)*s(O)+s(p)*c(O)*c(I))*x+(c(p)*c(O)*c(I)-s(p)*s(O))*y,s(p)*s(I)*x+c(p)*s(I)*y]};
const planets=(s,jd)=>{const T=(jd-2451545)/36525,e=helio(2,T);for(const k of[0,1,3,4,5])s.pts.push([...w3(nrm(equ(sub(helio(k,T),e)))),PLN[k][7],...SCL[PLN[k][8]],0])};
const base=()=>({P:'spc',co:[0,0,5],ta:[0,0,0],up:[0,1,0],fv:1.8,roll:0,ex:1,mw:1,bm:.16,dk:1,tk:0,ho:-2,sf:I3,oc:[[0,0,0,0],[0,0,0,0]],pts:[],fl:0,t:{},
Q:{uEc:{i:0},uCn:0,uNi:1,uRf:1.7,uSc:.5,uSe:0,uUb:1,uSk:1,uHd:0,uFl:0,uGd:0,uPx:0}});
// everything the picture from space needs: during the lunar eclipse, during the solar one, and (evenly, roughly) on the days between
const spc=(s,E,md,jd)=>{s.M=w3(E.M);s.S=w3(E.S);s.sd=w3(E.sd);s.E=E;s.oc=[[0,0,0,1],[...s.M,.2725]];
Object.assign(s.Q,{uSd:s.sd,uSp:s.S,uMp:s.M,uGs:wrapd(E.th),uMb:{m:rows(...mframe(md,jd).map(w3))}});planets(s,jd);return E};
const spcL=(s,h)=>{const L=lun(h);Object.assign(s.Q,{uEc:{i:1},uAx:w3(L.a),uF:[Math.tan(LE.f2*D2R),Math.tan(LE.f1*D2R)]});s.t.d='2019 JAN 21 '+hms(h)+' UTC';return spc(s,L,L.md,L.jd)};
const spcS=(s,h)=>{const E=sol(h);Object.assign(s.Q,{uEc:{i:2},uSb:{m:rows(w3(E.i),w3(E.j),w3(E.k))},uBe:[E.x,E.y,E.l1,E.l2],uSe:1});s.t.d='2019 JUL 02 '+hms(h)+' UTC';return spc(s,E,E.md,E.jd)};
const orb=(Om,u,i=5.145*D2R)=>equ([Math.cos(Om)*Math.cos(u)-Math.sin(Om)*Math.sin(u)*Math.cos(i),Math.sin(Om)*Math.cos(u)+Math.cos(Om)*Math.sin(u)*Math.cos(i),Math.sin(u)*Math.sin(i)]);
const spcO=(s,dy)=>{const jd=LE.jd+5.2/24+dy,Om=(125.0445-1934.1363*(jd-2451545)/36525)*D2R,lm=(120.86+13.1606*dy)*D2R,ls=(300.86+.9828*dy)*D2R,
md=orb(Om,lm-Om),sd=equ([Math.cos(ls),Math.sin(ls),0]);
let d=20.217+dy,m=0;while(d>=ML[m]){d-=ML[m];m++}s.t.d='2019 '+MN[m]+' '+String(Math.floor(d)+1).padStart(2,'0');
s.Q.uEc={i:3};s.Q.uSe=cl(dy/160);s.Om=Om;s.be=Math.asin(Math.sin(lm-Om)*Math.sin(5.145*D2R))/D2R;s.el=((lm-ls)/D2R%360+360)%360;
return spc(s,{M:mul(md,57),S:mul(sd,23400),sd,th:gmst(jd)},md,jd)};
// and the picture from the ground at Cerro Tololo
const gndS=(s,h)=>{const E=sol(h),c=circ(E,...CTIO),o=c.o,G=v=>[dot(v,o.E),dot(v,o.Z),dot(v,o.N)],sv=sub(E.S,o.p),mv=sub(E.M,o.p),
sd=nrm(G(sv)),mg=G(mv),ty=nrm(sub([0,1,0],mul(sd,sd[1]))),tx=cross(ty,sd),sr=109.123/len(sv),mz=dot(mg,sd),
mo=[dot(mg,tx)/mz/sr,dot(mg,ty)/mz/sr,.272281/len(mv)/sr],pa=G(SPOLE),pan=Math.atan2(dot(pa,tx),dot(pa,ty)),
ax=G(add(mul(E.i,E.x-dot(o.p,E.i)),mul(E.j,E.y-dot(o.p,E.j)))).map(v=>v*6378.137),um=(c.L1+c.L2)/2*6378.137,
lit=x=>{const v=sub(x,ax);return showJ(len(sub(v,mul(sd,dot(v,sd))))/um,1,mo[2])},
am=(lit([250,5,0])+lit([-250,5,0])+lit([0,5,250])+lit([0,5,-250]))/4*.02+2e-5;
s.P='gnd';s.co=[0,0,0];s.E=E;s.g={sd,tx,ty,mo,sr,pa:pan,vis:showJ(Math.hypot(mo[0],mo[1]),1,mo[2]),lit:lit([0,0,0])};
Object.assign(s.Q,{uSd:sd,uTx:tx,uTy:ty,uMo:mo,uSr:sr,uPa:pan,uAp:ax,uUm:um,uAm:[.3*am,.45*am,.9*am],uGd:1,uSz:Math.atan2(sd[0],sd[2]),
uMb:{m:rows(...mframe(E.md,E.jd).map(G).map(b=>[dot(b,tx),dot(b,ty),-dot(b,sd)]))},uHq:{m:[...w3(o.E),...w3(o.Z),...w3(o.N)]}});
s.sf=rows(w3(o.E),w3(o.Z),w3(o.N));s.ho=.01;s.tk=.3;s.mw=0;s.oc=[[...mg,.2725],[0,0,0,0]];s.dk=.6*(1-ss(0,.004,s.g.lit));
planets(s,E.jd);s.t.d='2019 JUL 02 '+hms(h)+' UTC';return E};
// cameras. Through a telescope on the Earth, at the Moon; low over the Moon, a quarter-turn ph round from the middle of its near side; from the mountain
const tele=(s,fv,off)=>{s.co=mul(nrm(s.M),1.5);s.ta=off?add(s.M,off):s.M;s.fv=fv};
const lowm=(s,ph,alt,ahead)=>{const e1=mul(nrm(s.M),-1),e2=nrm(cross(e1,[0,1,0])),at=a=>add(mul(e1,Math.cos(a)),mul(e2,Math.sin(a)));
s.co=add(s.M,mul(at(ph),.2725*(1+alt)));s.ta=add(s.M,mul(at(ph+ahead),.2725));s.up=at(ph)};
const aim=(s,x,y)=>{const g=s.g;s.ta=add(g.sd,add(mul(g.tx,x*g.sr),mul(g.ty,y*g.sr)))}; // at a point x, y solar radii from the Sun's centre
const wide=(s,da,el)=>{const a=s.Q.uSz+da;s.ta=[Math.sin(a)*Math.cos(el),Math.sin(el),Math.cos(a)*Math.cos(el)]};
const onsun=(s,th,r)=>{const x=-Math.sin(th)*r,y=Math.cos(th)*r,c=Math.cos(s.g.pa),q=Math.sin(s.g.pa);return[c*x+q*y,c*y-q*x]}; // a place on the Sun's limb, on the sky
// an exposure that follows the Moon into the shadow, as a camera's would
const aex=L=>3.6/(showJ(L.rho,LE.f3,LE.f2)+1.8e-4);
const track=(s,E)=>{for(const a of TRK)s.pts.push([...place(a[0],a[1],E.th,1.002),2.2,1.6,.9,.3,1])};
const mark=(s,E,la,lo,c=[.3,1.6,1.4])=>{s.pts.push([...place(la,lo,E.th,1.003),5,...c,1]);for(let i=0;i<24;i++){const a=i*TAU/24;s.pts.push([...place(la+.9*Math.cos(a),lo+1.05*Math.sin(a),E.th,1.003),2,...c,1])}};
const SH=[
// 0: the galaxy from outside
(s,b,u)=>{s.P='gal';const a=.5+.045*b;s.co=[1.75*Math.cos(a),1.05-.25*u,1.75*Math.sin(a)];s.fv=2;s.ex=1.2*ss(0,3,b);s.dk=0;
s.t.a='THE MILKY WAY';s.t.b=b>4?'two hundred thousand million stars · 100 000 light-years across':'';
if(b>8){s.pts.push([...SUNG,9,2.5,2,1,2],[...SUNG,26,.25,.2,.1,2]);s.lab=[SUNG,'THE SUN','26 000 light-years from the centre']}},
// 4: falling in
(s,b,u)=>{s.P='gal';const e=1-(1-u)**2.2,a=.5+.045*(16+b*.3),A=[1.75*Math.cos(a),.8,1.75*Math.sin(a)];
s.co=lerp(A,add(SUNG,[.02,.012,.01]),e);s.ta=lerp([0,0,0],add(SUNG,[-.4,-.03,-.2]),ss(.2,1,u));s.fv=2-.6*u;s.ex=1.2;s.dk=0;
s.streak={n:5000,box:[.5,.3,.5],vel:mul(nrm(sub(SUNG,A)),.003+.05*u*(1-u)*4),dk:.2*ss(.1,.5,u),fall:60};
s.pts.push([...SUNG,9,2.5,2,1,2]);s.t.a='THE MILKY WAY';s.t.b='the Sun is one of them, about half-way out'},
// 6: the Milky Way from inside; and backing away from it, the Earth
(s,b,u)=>{spcL(s,1.2+.1*u);const sd=s.sd,side=nrm(sub(sd,mul(GCW,dot(sd,GCW)))),e=ez(cl(u*1.05));
s.co=add(add(mul(GCW,mix(2.6,-5.2,e)),mul(side,mix(1.3,2,e))),[0,mix(-.2,.6,e),0]);
s.ta=add(s.co,lerp(mul(GCW,10),mul(s.co,-1),ss(.55,1,u)*.8));s.fv=mix(4.5,1.7,ss(0,.6,u));s.mw=mix(3.4,1.5,u);s.fl=1;
s.streak={n:6000,box:[8,8,8],vel:mul(GCW,-.5*(1-u)),dk:.25*(1-u)**2,fall:.5};
s.t.d='';s.t.a=u<.55?'THE MILKY WAY, FROM INSIDE':'EARTH';s.t.b=u<.55?'looking towards its centre, in Sagittarius':'21 January 2019'},
// 8: sunrise over the edge of the Earth
(s,b,u)=>{spcL(s,2+.2*u);const sd=s.sd,p=nrm(cross(sd,[0,1,0])),th=(37.3+12*u)*D2R,R=1.55;
s.co=add(add(mul(sd,-R*Math.cos(th)),mul(p,R*Math.sin(th))),[0,.25,0]);s.ta=add(mul(sd,3),mul(p,.9));s.up=nrm(s.co);s.fv=1.5;s.ex=1.1;s.fl=1;s.Q.uNi=1.5;
s.t.a='EARTH';s.t.b='the night of the full Moon'},
// 10: the terminator, and the lights
(s,b,u)=>{const L=spcL(s,2.2+.4*u);s.co=place(18-6*u,-112+10*u,L.th,3.1);s.fv=2.3;s.ex=1.05;s.fl=1;s.Q.uNi=1.6;
s.t.a='THE AMERICAS TURN INTO THE DARK';s.t.b='Sun, Earth and Moon are coming into line'},
// 12: the Earth's shadow, and the Moon going into it
(s,b,u)=>{const L=spcL(s,2.7+2.2*u),a=w3(L.a),p=nrm(cross(a,[0,1,0])),e=ez(u);
s.co=lerp(add(add(mul(a,32),mul(p,38)),[0,7,0]),add(add(s.M,mul(p,3.2)),add([0,.9,0],mul(a,-1.5))),e);s.ta=lerp(mul(a,29),s.M,e);s.fv=2;s.ex=1.3;s.Q.uCn=1;s.Q.uUb=600;s.mw=1.3;
s.t.a="THE EARTH'S SHADOW";s.t.b='1.4 million km long · lit red inside by every sunrise and sunset at once'},
// 14: the Moon from the Earth: the penumbra, then the first bite
(s,b,u)=>{const L=spcL(s,3.2+.38*u);tele(s,105);s.ex=aex(L);s.dk=.3;s.t.a='PENUMBRAL ECLIPSE';s.t.b='seen from the Moon, the Earth has begun to cover the Sun'},
// 16-20: the partial eclipse, in four looks
(s,b,u)=>{const L=spcL(s,3.58+.27*u);tele(s,105);s.ex=aex(L);s.dk=.3;s.t.a='PARTIAL ECLIPSE';s.t.b='the umbra, from 03:33:35'},
(s,b,u)=>{const L=spcL(s,3.85+.27*u),a=w3(L.a),t=sub(mul(a,dot(s.M,a)),s.M),d=len(t);tele(s,430,mul(t,cl(d-.751,-.24,.24)/d));s.ex=aex(L);s.Q.uUb=2200;s.dk=0;s.Q.uRf=2.4;
s.t.a='PARTIAL ECLIPSE';s.t.b='the edge of the shadow: turquoise, from light that crossed the ozone layer'},
(s,b,u)=>{const L=spcL(s,4.12+.27*u);tele(s,6.5,add([0,4.6,0],mul(w3(L.e),-4.2)));s.ex=aex(L)*.5;s.dk=1.6;s.mw=2;s.Q.uSk=1.4;s.t.a='PARTIAL ECLIPSE';s.t.b='in Cancer, with Castor and Pollux'},
(s,b,u)=>{const L=spcL(s,4.39+.31*u);tele(s,118);s.ex=aex(L);s.dk=.5;s.t.a='PARTIAL ECLIPSE';s.t.b='the last of the direct sunlight'},
// 20: totality
(s,b,u)=>{const L=spcL(s,4.75+.35*u);tele(s,88+26*u);s.ex=aex(L);s.dk=1;s.mw=2;s.Q.uSk=1.5;s.t.a='TOTAL LUNAR ECLIPSE';s.t.b='04:41 to 05:43 · the Moon overhead in Cuba'},
// 22: out to it
(s,b,u)=>{const L=spcL(s,5.1+.1*u),md=nrm(s.M),q=nrm(cross(md,[0,1,0]));s.co=add(sub(s.M,mul(md,.2725*(1.2+200*(1-u)**3.2))),mul(q,.12*u));s.ta=add(s.M,[0,.1*u,0]);
s.fv=2.4;s.ex=aex(L)*1.2;s.dk=1;s.mw=2;s.t.a='TOTAL LUNAR ECLIPSE';s.t.b='357 700 km away'},
// 24: low over the red Moon
(s,b,u)=>{const L=spcL(s,5.2+.1*u);lowm(s,(12+52*u)*D2R,.1,.55);s.fv=1.5;s.ex=aex(L)*2;s.Q.uRf=2.4;s.dk=1;s.t.a='OVER THE MOON';s.t.b='its only light is sunlight bent through the air of the Earth'},
// 26: over the edge, to the far side
(s,b,u)=>{const L=spcL(s,5.3+.1*u);lowm(s,(64+34*u)*D2R,.1+.12*u,.6);s.fv=1.5;s.ex=aex(L)*2.4;s.Q.uRf=2.6;s.dk=1;
s.t.a='OVER THE MOON';s.t.b='towards the edge, where the Earth is setting'},
// 28: the Earth from behind the Moon: a ring of every sunrise and sunset
(s,b,u)=>{spcL(s,5.3+.3*u);const md=nrm(s.M);s.co=add(s.M,add(mul(md,.7),[0,.325+.02*u,0]));s.ta=[0,.25,0];s.fv=13+2*u;s.ex=.5;s.Q.uSc=4;s.Q.uNi=1.2;s.dk=.6;
s.t.a='THE EARTH, FROM THE MOON';s.t.b='a total eclipse of the Sun, by the Earth'},
// 30: and the Sun comes out from behind it
(s,b,u)=>{spcL(s,5.6+.21*u);const md=nrm(s.M);s.co=add(s.M,add(mul(md,.7),[0,.345,0]));s.ta=[0,.25,0];s.fv=15;s.Q.uSc=4;s.Q.uNi=1.2;s.dk=.5;s.fl=1;s.ex=.5/(1+40*svis(s));
s.t.a='THE EARTH, FROM THE MOON';s.t.b='05:43 · the Sun returns'},
// 32: six months of orbits. The Moon's path is tilted five degrees: most months it passes above or below the line
(s,b,u)=>{const dy=162.59*ez(u);spcO(s,dy);const a=.9+.25*u;s.co=mul(nrm([Math.cos(a),.95,Math.sin(a)]),165);s.fv=2.6;s.ex=1.5;s.Q.uCn=1.6;s.mw=.8;
for(let i=0;i<240;i++)s.pts.push([...w3(mul(orb(s.Om,i*TAU/240),57)),1.6,.35,.5,.9,1]);
s.pts.push([0,0,0,7,.5,1,2,2],[...s.M,5,1.5,1.5,1.5,2]);
const f=Math.min(s.el,360-s.el)<25?'NEW MOON':Math.abs(s.el-180)<25?'FULL MOON':'';
s.t.a='SIX MONTHS';s.t.b=(f?f+' · ':'')+'the Moon '+Math.abs(s.be).toFixed(1)+'° '+(s.be>0?'above':'below')+" the plane of the Earth's orbit";
s.t.f1="the Moon's path is tilted 5°: most months its shadow misses, and it misses ours"},
// 36: the Moon's shadow reaches the Earth
(s,b,u)=>{spcS(s,18+.6*u);const k=s.sd,p=nrm(cross(k,[0,1,0])),e=ez(u);
s.co=lerp(add(add(mul(k,30),mul(p,44)),[0,9,0]),add(add(mul(k,3.2),mul(p,-6.2)),[0,2.2,0]),e);s.ta=lerp(mul(k,28),[0,0,0],e);s.fv=2.1;s.Q.uCn=1.5;s.fl=1;s.mw=1.3;
s.t.a="THE MOON'S SHADOW";s.t.b='a cone 373 000 km long: its point just reaches the ground'},
// 38: across the Pacific
(s,b,u)=>{const E=spcS(s,18.55+1.55*u),a=axis(E)||[-17,-109];s.co=place(a[0]+13,a[1]-12,E.th,2.5);s.ta=place(a[0],a[1]+4,E.th,1);s.fv=2.5;s.fl=1;track(s,E);
s.t.a='TOTAL SOLAR ECLIPSE';s.t.b='greatest at 19:22:58 · 17°23′S 109°00′W · 4 min 33 s of totality';s.t.f1='the shadow: '+dms(a[0],'N','S')+' '+dms(a[1],'E','W')},
// 40: from beyond the Moon
(s,b,u)=>{const E=spcS(s,20+.42*u),md=nrm(s.M),q=nrm(cross(md,[0,1,0]));s.co=add(s.M,add(mul(md,.75),add([0,.31+.03*u,0],mul(q,.1))));s.ta=[0,.3,0];s.fv=11;s.ex=.9;track(s,E);
s.t.a='TOTAL SOLAR ECLIPSE';s.t.b='from beyond the Moon: its far side in sunlight, its shadow on the Earth'},
// 42: landfall in Chile
(s,b,u)=>{const E=spcS(s,20.3+.355*u);s.co=place(-33,-80+2*u,E.th,1.2);s.ta=place(-29.5,-70.5,E.th,1);s.up=nrm(s.co);s.fv=1.9;s.ex=1.05+2.2*u*u;track(s,E);mark(s,E,CTIO[0],CTIO[1]);
s.t.a='LANDFALL · CHILE';s.t.b='Cerro Tololo observatory · 30°10′S 70°48′W · 2 207 m';s.t.f1='totality there: 20:38:35 to 20:40:39'},
// 44: the mountain, late afternoon; the Sun already bitten
(s,b,u)=>{gndS(s,20.2+.02*u);wide(s,-.12,.19);s.fv=1.9;s.ex=.9;s.fl=1;s.Q.uPx=b*.25;s.t.a='CERRO TOLOLO';s.t.b='the Sun '+Math.round(Math.asin(s.g.sd[1])/D2R)+'° up in the north-west, '+Math.round(100-100*s.g.vis)+'% covered'},
// 45: through a filter
(s,b,u)=>{gndS(s,20.3+.3*u);aim(s,0,0);s.fv=95;s.Q.uFl=1;s.Q.uGd=0;s.dk=0;s.t.a='PARTIAL ECLIPSE';s.t.b=Math.round(100-100*s.g.vis)+'% covered';s.t.cam='SOLAR FILTER · 1/500 s'},
// 46: the light goes
(s,b,u)=>{gndS(s,20.6+.04*u);wide(s,-.12,.19);s.fv=1.9;s.ex=.9/(s.g.lit+.03)**.75;s.fl=1;s.Q.uPx=4+b*.25;s.t.a='THE LIGHT GOES';s.t.b='the shadow is coming in off the Pacific at 2.5 km a second'},
// 47: the last of the Sun, breaking into beads between the mountains of the Moon
(s,b,u)=>{gndS(s,C2-(13-13.6*u)/3600);const m=s.g.mo,n=Math.hypot(m[0],m[1]);aim(s,-m[0]/n*.55,-m[1]/n*.55);s.fv=120;s.ex=.6;s.Q.uGd=0;s.fl=1.5;s.dk=0;
s.t.a="BAILY'S BEADS";s.t.b='sunlight through the valleys on the edge of the Moon'},
// 48: totality
(s,b,u)=>{gndS(s,C2+(3+20*u)/3600);wide(s,-.1+.03*u,.19);s.fv=2+.5*u;s.ex=55;s.Q.uPx=8+b*.2;s.t.a='TOTALITY';s.t.b='20:38:35 · 124 seconds · Venus below the Sun; Orion and Sirius off to the left'},
// 50: the corona
(s,b,u)=>{gndS(s,C2+(25+15*u)/3600);aim(s,0,0);s.fv=20+11*u;s.ex=2.2;s.Q.uHd=.45;s.Q.uGd=0;s.t.a='THE CORONA';s.t.b="the Sun's outer atmosphere, a million degrees, combed by its magnetic field"},
// 52: prominences
(s,b,u)=>{gndS(s,C2+(42+14*u)/3600);aim(s,...onsun(s,2.02-.1*u,1.06));s.fv=250;s.ex=.5;s.Q.uGd=0;s.dk=0;s.t.a='PROMINENCES';s.t.b='hydrogen, held above the edge of the Sun; the limb of the Moon in front'},
// 54: a long exposure: the Moon lit by the Earth
(s,b,u)=>{gndS(s,C2+(58+10*u)/3600);aim(s,0,0);s.fv=78-10*u;s.ex=45;s.bm=.012;s.Q.uGd=0;s.t.a='EARTHSHINE';s.t.b='expose for long enough and the Moon is there, lit by the Earth';s.t.cam='1.6 s · ƒ/5 · ISO 100'},
// 56: nine exposures, a stop apart, one a beat
(s,b,u)=>{const k=cl(Math.floor(b),0,8);gndS(s,C2+(70+2*b)/3600);aim(s,0,0);s.fv=52;s.ex=.4*2**k;s.Q.uGd=0;s.dk=.3;
s.t.a='NINE EXPOSURES';s.t.b='the corona is a thousand times brighter at the Sun than three radii out';s.t.cam=['1/160','1/80','1/40','1/20','1/10','1/5','0.4','0.8','1.6'][k]+' s · ƒ/5 · ISO 100';s.t.f1='EXPOSURE '+(k+1)+' OF 9'},
// 58.25: all of them together
(s,b,u)=>{gndS(s,C2+(92+12*u)/3600);aim(s,0,0);s.fv=41-5*u;s.ex=1.6;s.Q.uHd=1;s.Q.uGd=0;s.roll=-s.g.pa*ez(u);s.dk=1;
s.t.a='ALL NINE TOGETHER';s.t.b='inspired by the composites Nicolas Lefaudeux made from this mountain'},
// 60: the diamond ring
(s,b,u)=>{gndS(s,C3+(-1.5+9.5*u)/3600);const m=s.g.mo,n=Math.hypot(m[0],m[1]);aim(s,-m[0]/n*.3,-m[1]/n*.3);s.fv=62-8*u;s.ex=.6;s.Q.uGd=0;s.fl=1.7;s.dk=0;
s.t.a='THIRD CONTACT';s.t.b='20:40:39 · the diamond ring'},
// 62: daylight comes back
(s,b,u)=>{gndS(s,C3+(6+60*u)/3600);wide(s,-.1,.19);s.fv=2;s.ex=.9/(s.g.lit+.006)**.8;s.fl=1;s.Q.uPx=14+b*.2;s.t.a='THE LIGHT RETURNS';s.t.b='the shadow goes on east, over the Andes'},
// 64: away
(s,b,u)=>{const E=spcS(s,20.7+.05*u),e=u*u*u;s.co=place(-38+10*e,-64-20*e,E.th,1.5+46*e);s.ta=add(place(-36,-60,E.th,1-e),[0,-13*e,0]);s.fv=2.2;s.fl=1;s.mw=1+2*e;track(s,E);
s.t.a=u<.4?'SUNSET, NEAR BUENOS AIRES':'';s.t.b=u<.4?'20:44:49 · the shadow leaves the Earth':'';
if(b>6){s.t.d='';s.t.big='ECLIPSE';s.t.sub='21 January and 2 July 2019';s.t.sub2='the next long one: 2 August 2027 · Luxor · 6 min 23 s'}}
];
const dms=(v,p,n)=>{const a=Math.abs(v),d=Math.floor(a+1/120),m=Math.min(59,Math.floor((a-d)*60+.5));return d+'°'+String(Math.max(m,0)).padStart(2,'0')+'′'+(v<0?n:p)};
// how much of the Sun's face a camera in space can see past the Earth and the Moon
function svis(s){const ds=sub(s.S,s.co),D=len(ds),as=109.123/D,f=(c,R)=>{const dc=sub(c,s.co),d=len(dc);return dot(dc,ds)<0?1:showJ(Math.acos(cl(dot(dc,ds)/d/D,-1,1))/as,1,Math.asin(Math.min(1,R/d))/as)};
return f([0,0,0],1)*f(s.M,.2725)}
const ev=(i,bt)=>{const s=base(),b0=CUT[i]*4;SH[i](s,bt-b0,cl((bt-b0)/(CUT[i+1]*4-b0)));return s};
let flash=0,fade=0,lt=0,ft=1/60,hold=0,frames=0,dbg=-1,tmin=.05,pdt=.05,cap=1,capT=0,kf=1,bpNow=0,shN=0;
const drawText=T=>{txtDirty=0;
const w=XC.width=Math.min(W,1600),h=XC.height=Math.max(1,Math.round(w*H/W));X.clearRect(0,0,w,h);X.fillStyle='#fff';X.textBaseline='middle';X.shadowColor='rgba(0,0,0,.85)';X.shadowBlur=h*.014;
let ls=0;const sans='"Helvetica Neue",Helvetica,Arial,sans-serif',mono='ui-monospace,Menlo,Consolas,monospace',sp=v=>{ls=h*v;try{X.letterSpacing=ls+'px'}catch(e){}},
put=(s,f,x,y,a)=>{if(s){X.font=f;const m=X.measureText(s).width,mx=(X.textAlign=='left'?w-x:X.textAlign=='right'?x:w)-h*.05,k=Math.min(1,mx/m*.98),l=ls;
if(k<1){X.font=f.replace(/([\d.]+)px/,(q,z)=>z*k+'px');try{X.letterSpacing=l*k+'px'}catch(e){}} // a line too long for a narrow screen is set smaller
X.globalAlpha=a||1;X.fillText(s,x,y);X.globalAlpha=1;if(k<1)try{X.letterSpacing=l+'px'}catch(e){}}};
X.textAlign='center';sp(.09);put(T.big,`200 ${h*.13}px ${sans}`,w/2+h*.045,h*.45);
sp(.008);put(T.sub,`400 ${h*.026}px ${mono}`,w/2,h*.6);put(T.sub2,`400 ${h*.02}px ${mono}`,w/2,h*.65,.75);
X.textAlign='left';
put(T.d,`300 ${h*.05}px ${mono}`,h*.06,h*.085); // the date and the clock
put(T.a,`400 ${h*.026}px ${mono}`,h*.062,h*(T.d?.143:.085)); // what this is
put(T.b,`400 ${h*.021}px ${mono}`,h*.062,h*(T.d?.18:.122),.8); // and a line about it
put(T.f1,`400 ${h*.022}px ${mono}`,h*.062,h*.9,.9);
X.textAlign='right';put(T.cam,`400 ${h*.026}px ${mono}`,w-h*.062,h*.9); // what the camera is set to
if(T.lab){const x=(T.lab[0]*.5+.5)*w,y=(.5-T.lab[1]*.5)*h;X.textAlign='left';X.strokeStyle='#fff';X.lineWidth=h*.0015;X.globalAlpha=.7;X.beginPath();X.moveTo(x+h*.012,y-h*.012);X.lineTo(x+h*.05,y-h*.05);X.lineTo(x+h*.07,y-h*.05);X.stroke();
put(T.lab[2],`400 ${h*.022}px ${mono}`,x+h*.078,y-h*.05);put(T.lab[3],`400 ${h*.017}px ${mono}`,x+h*.078,y-h*.022,.8)}
gl.activeTexture(gl.TEXTURE3);gl.bindTexture(gl.TEXTURE_2D,TX);gl.texImage2D(gl.TEXTURE_2D,0,gl.RGBA,gl.RGBA,gl.UNSIGNED_BYTE,XC)};
const frame=now=>{
requestAnimationFrame(frame);frames++;
const t=now/1e3,dt=Math.min(.1,Math.max(.001,t-lt));lt=t;
analyse(dt);
let run=0,mt=0;
if(ext){mt=(ctx.currentTime-extT)%LEN;run=1}
else if(t0!=null&&ctx.state=='running'){mt=Math.max(0,ctx.currentTime-t0-(ctx.outputLatency||0))%LEN;run=1}
if(dbg>=0){mt=dbg*BAR;run=1}
const bt=run?mt/BEAT:9+Math.sin(t*.1),tm=run?mt:t%1e3,asp=W/H;bpNow=bt/4;
// which shot; and the shutter. It closes for an instant at every cut. Before a big one it blinks on the beat, then twice a beat,
// four times, eight - and in the gaps there are glimpses of what is coming.
let i=0;while(i<SH.length-1&&bt>=CUT[i+1]*4)i++;
let j=i,gb=bt,near=9;
if(run&&!steady){
for(const c of CUT)near=Math.min(near,Math.abs(bt-c*4));
for(const m of MAJ){const x=bt-m*4+4;if(x>=0&&x<4){let k=0;while(x>=RMP[k+1])k++;for(const r of RMP)near=Math.min(near,Math.abs(x-r));if(k>2&&(k&1)){j=CUT.indexOf(m);gb=m*4+(x-RMP[k])}}}
if(bt>BRK*4&&bt<BRK*4+9)near=Math.min(near,Math.abs(bt-Math.round(bt)));
}
const shut=run&&!steady?cl(near*BEAT/.04):1,s=ev(j,gb),T=s.t;
if(j!=shN){shN=j;if(run)flash=.5}
flash*=Math.exp(-dt*9);fade=Math.min(1,fade+dt*1.5);
if(!run){for(const k in T)delete T[k];T.big='ECLIPSE';T.sub='click to start · F fullscreen · S steady: no flicker';T.sub2='the cuts flicker: flashing images';s.lab=null}
else if(bt<12&&!T.cam)T.cam=steady?'STEADY · NO FLICKER':'PRESS S FOR NO FLICKER'; // the cuts flash: say so, while there is time
// adaptive resolution, by frame pacing: tmin is this display's frame interval (the shortest pair of frames seen); while frames
// arrive on time, grow a little now and then; as soon as they start arriving late, shrink, and stay below that size for a while.
ft+=(dt-ft)*.05;tmin=Math.min((dt+pdt)/2,tmin*1.0005);pdt=dt;hold-=dt;
// And if it is late even when small, on a fast display: settle for every second frame (kf) rather than a blur.
if(hold<0&&t>2){hold=.5;const lim=t<capT?Math.min(scMax,cap):scMax,tg=tmin*kf;
if(ft>1.2*tg){if(sc>.5||kf>3&&sc>.3){cap=sc*.94;capT=t+15;sc*=.88;alloc();ft=tg;hold=1}else if(kf<4){kf++;ft=tmin*kf;hold=1}}
else if(kf>1&&ft<tmin*(kf-.5)){kf--;hold=1}
else if(ft<1.04*tg&&sc<lim){sc=Math.min(lim,sc*1.06);alloc();hold=1.5}}
// camera; where a thing in the world falls on the screen
const co=s.co,cm=look(co,s.ta,s.up,s.roll),fv=s.fv,pr=p=>{const d=sub(p,co),z=dot(d,cm.slice(6));return[dot(d,cm.slice(0,3))*fv/z,dot(d,cm.slice(3,6))*fv/z,z]};
// the Sun in the lens: how strong depends on how much of its face shows, and on the exposure
let fi=0,s3=[0,0,0];
if(s.fl){let v,p;
if(s.P=='gnd'){const g=s.g,m=g.mo,n=Math.hypot(m[0],m[1])||1,o=-(1-g.vis)*.98/n;v=g.vis*1e6;p=add(g.sd,add(mul(g.tx,m[0]*o*g.sr),mul(g.ty,m[1]*o*g.sr)))}
else{v=svis(s)*3e4;p=sub(s.S,co)}
s3=pr(add(co,mul(nrm(p),1e3)));fi=s3[2]>0?.16*s.fl*Math.log10(1+v*s.ex)*(1-ss(1.1,2,Math.max(Math.abs(s3[0])/asp,Math.abs(s3[1])))):0}
if(s.lab){const q=pr(s.lab[0]);T.lab=[q[0]/asp,q[1],s.lab[1],s.lab[2]]}
{const n=JSON.stringify(T);if(n!==txt||txtDirty){txt=n;drawText(T)}}
const xa=run?.92:.8+.2*Math.sin(t*3),fo=run&&dbg<0?Math.min(1,(LEN-mt)/3):1;
// the picture into the HDR target
let u=use(PS[s.P]);
gl.disable(gl.BLEND);
gl.bindFramebuffer(gl.FRAMEBUFFER,S.f);gl.viewport(0,0,S.w,S.h);
su(u,{uR:[S.w,S.h],uT:tm,uRow:(row+.5)/HR,uA:A,uK:K,uS:{i:0},uE:{i:5},uL:{i:6},uCo:co,uCm:{m:cm},uFv:fv,uEx:s.ex,uMw:s.mw});
if(s.M)s.Q.uCr=sub(co,s.M);
su(u,s.Q);
gl.drawArrays(gl.TRIANGLES,0,3);
// the stars, and whatever the shot has marked, on top of it
gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);
const pu={uCm:{m:cm},uSf:{m:s.sf},uCo:co,uFv:fv,uAsp:asp,uPx:S.h/1080,uT:tm,uDk:s.dk,uHo:s.ho,uMd:0,uTk:s.tk,uO0:s.oc[0],uO1:s.oc[1],uBx:[1,1,1],uVl:[0,0,0]};
if(s.streak){u=use(PL);su(u,pu);su(u,{uMd:s.streak.fall,uBx:s.streak.box,uVl:s.streak.vel,uDk:s.streak.dk});gl.drawArrays(gl.LINES,0,s.streak.n*2)}
{const n=Math.min(s.pts.length,NXM);for(let k=0;k<n;k++)SB.set(s.pts[k],(NS+k)*8);
gl.bindVertexArray(VA1);gl.bindBuffer(gl.ARRAY_BUFFER,VB);if(n)gl.bufferSubData(gl.ARRAY_BUFFER,NS*32,SB.subarray(NS*8,(NS+n)*8));
u=use(PP);su(u,pu);gl.drawArrays(gl.POINTS,0,NS+n);gl.bindVertexArray(VA0)}
gl.disable(gl.BLEND);
// bloom down
gl.activeTexture(gl.TEXTURE1);
u=use(PD);gl.uniform1i(u.uC,1);
let src=S;
for(let k=0;k<B.length;k++){const d=B[k];gl.bindFramebuffer(gl.FRAMEBUFFER,d.f);gl.viewport(0,0,d.w,d.h);gl.bindTexture(gl.TEXTURE_2D,src.t);
gl.uniform2f(u.uR,d.w,d.h);gl.uniform2f(u.uI,1/src.w,1/src.h);gl.uniform1f(u.uTh,k?0:1);gl.drawArrays(gl.TRIANGLES,0,3);src=d}
// bloom up (additive)
u=use(PU);gl.uniform1i(u.uC,1);gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);
for(let k=B.length-1;k>0;k--){const d=B[k-1];src=B[k];gl.bindFramebuffer(gl.FRAMEBUFFER,d.f);gl.viewport(0,0,d.w,d.h);gl.bindTexture(gl.TEXTURE_2D,src.t);
gl.uniform2f(u.uR,d.w,d.h);gl.uniform2f(u.uI,1/src.w,1/src.h);gl.drawArrays(gl.TRIANGLES,0,3)}
gl.disable(gl.BLEND);
// composite
u=use(PC);gl.bindFramebuffer(gl.FRAMEBUFFER,null);gl.viewport(0,0,W,H);
gl.bindTexture(gl.TEXTURE_2D,S.t);gl.activeTexture(gl.TEXTURE2);gl.bindTexture(gl.TEXTURE_2D,B[0].t);
su(u,{uC:{i:1},uB:{i:2},uX:{i:3},uS:{i:0},uR:[W,H],uT:t%100,uF:fade*fo,uXa:xa,uRow:(row+.5)/HR,uFl:flash,uBm:s.bm,uSt:run?1:0,
uFi:fi*(1+.2*K[0]),uFc:[1,.95,.85],uSs:s3,uSh:shut});
gl.drawArrays(gl.TRIANGLES,0,3);
};
requestAnimationFrame(frame);
// if this page was opened by a press (a host's start screen) audio may already be allowed: try now, else wait for a click
start().catch(()=>{});
// inspection hook
window.ECL={SYN,errs,C2,C3,get state(){return{bar:bpNow,sc,ft,tmin,kf,frames,mode,A:[...A],K:[...K],t0,W,H,sw:S.w,ctx:ctx&&ctx.state}},set seek(v){dbg=v}};
})();
</script>
</body>
</html>