Deck.scene({ id:'lamp', title:'How far you can see', enterWith:'fade', post:{bloom:.9,threshold:1,vignette:.28,grain:.03}, beats:[{dur:3,hold:5},{dur:4.5,hold:5},{dur:5,hold:6}], notes:[ 'Forget test scores. Intelligence is how far you can see. This is one person, with one lantern, in the dark. Everything inside the pool you can think about. Everything outside it is not there.', 'Now light the brightest lantern anyone ever carried. Einstein. Look at how much more of the field he lights. Almost nothing. Now everyone alive, all eight billion of us, together. It is beautiful. It is also still night.', 'So what does it look like when the sun comes up? All of this was always here. What we called the world was one small fold in it.' ], setup(d){ const rnd=i=>{ const x=Math.sin(i*127.1+31.7)*43758.5453; return x-Math.floor(x); }; const blades=[]; for(let i=0;i<64;i++){ blades.push({ x:-220+i*38+rnd(i)*34, b:950+rnd(i+50)*170, h:150+rnd(i+90)*340, l:(rnd(i+140)-.5)*115, w:3+rnd(i+7)*5 }); } return { blades, sat:v=>v<0?0:v>1?1:v, sky:d.pass(`uniform float uPull, uCrowd, uSun; uniform vec2 uM; float field(vec2 g){ float m=0.; for(int i=0;i<2;i++){ float sc=(i==0)?30.:12.; vec2 gg=g*sc; vec2 id=floor(gg); vec2 fr=fract(gg)-.5; float rn=hash12(id+float(i)*7.31); vec2 of=(vec2(hash12(id+1.7),hash12(id+9.1))-.5)*.72; float dd=length(fr-of); m+=(1.-smoothstep(.02,.17,dd))*step(.42,rn); } return m; } vec3 nightScene(vec2 q){ float hz=700.; float spread=1.-.88*uPull; vec2 foc=vec2(1240.,575.); vec2 s=foc+(q-foc)/spread; vec3 warm=vec3(1.,.55,.20); float up=clamp((hz-s.y)/900.,0.,1.); vec3 skyc=mix(vec3(.100,.120,.190),vec3(.022,.030,.055),up); vec3 grd=vec3(.070,.052,.032)*(.55+.9*fbm(s*vec2(.012,.05))); vec3 c=mix(grd,skyc,step(s.y,hz)); vec2 L=vec2(1240.,575.); float d=length(s-L); c+=warm*vec3(1.,.72,.42)*(.55/(1.+d*d*.00006)); c+=warm*vec3(1.,.94,.78)*12.*exp(-d*d*.01); float v=max(s.y-hz,1.); float z=1800./max(v,60.); vec2 g=vec2((s.x-1240.)*z*.0009,z*.05); float dens=smoothstep(.30,.70,fbm(g*vec2(.8,1.6)+vec2(0.,uTime*.006))); float fl=field(g)*dens*uCrowd*step(hz,s.y); float aa=max(fwidth(g.x),fwidth(g.y))*30.; fl=mix(fl,dens*uCrowd*.18,clamp(aa*1.5-.4,0.,1.)); c+=warm*fl*2.4*exp(-z*.055); c+=warm*.05*uCrowd*exp(-v/60.); return c; } vec3 dayScene(vec2 q,float sun){ float hz=660.; vec2 C=vec2(960.,hz+40.); vec2 dv=q-C; vec2 de=dv/vec2(1.,1.18); float dd=length(de); float ang=atan(dv.y,dv.x); float dist=length(dv); float up=clamp((hz-q.y)/900.,0.,1.); vec3 c=mix(vec3(.95,.74,.55),vec3(.09,.22,.50),pow(up,.55)); float sy=hz-30.-40.*sun; float ds=length(q-vec2(960.,sy)); c+=vec3(1.,.86,.62)*1.1/(1.+ds*ds*.00003); c+=vec3(1.,.98,.94)*5.*(1.-smoothstep(46.,56.,ds)); float ry=pow(.5+.5*sin(ang*26.+fbm(vec2(ang*3.,uTime*.04))*7.),8.); c+=vec3(1.,.92,.78)*ry*.30*exp(-dist*.0016); for(int i=0;i<5;i++){ float f=float(i)/4.; float R=900.-f*176.; float th=46.-f*6.; float e=abs(dd-R); float m=1.-smoothstep(th-13.,th,e); float band=.76+.30*sin(dv.y*.08+float(i)*2.1+sin(dv.x*.009)*2.6); vec3 rock=vec3(.52,.20,.12)*band; rock=mix(rock,vec3(.68,.76,.88),.14+.52*f); c=mix(c,rock,m*(1.-.12*f)); } if(q.y>hz){ float v=q.y-hz; vec3 sea=mix(vec3(.55,.68,.78),vec3(.05,.14,.26),smoothstep(0.,340.,v)); float w=fbm(vec2(q.x*.012,v*.09+uTime*.02)); sea*=.88+.28*w; sea+=vec3(1.,.9,.70)*(1.-smoothstep(0.,320.,v))*exp(-abs(q.x-960.)/120.)*(.35+.9*w); c=sea; } c*=(1.-.55*(1.-smoothstep(260.,780.,q.x))*smoothstep(560.,880.,q.y)); return c; } void main(){ vec2 q=design(vUv)+uM*vec2(16.,9.); vec3 c; if(uSun<.995){ c=nightScene(q); if(uSun>.005) c=mix(c,dayScene(q,uSun),smoothstep(0.,1.,uSun)); } else { c=dayScene(q,uSun); } o=vec4(c,1.); }`,'lamp night') }; }, draw(s,d,r){ const E=d.E, L=E.lin, sat=r.sat, c=d.ctx2d; const pull=s.k(1,.2,4.2,E.io3); const crowd=s.k(1,.9,3.8,E.io3); const sun=s.k(2,.2,4.6,E.io3); r.sky.draw({uPull:pull,uCrowd:crowd,uSun:sun,uM:[s.mouse.x,s.mouse.y]}); const spread=1-.88*pull; const grassA=sat(1-(pull-.10)/.45); const lampA=sat(1-(pull-.65)/.35)*(1-sun); c.save(); c.translate(1240,575); c.scale(spread,spread); c.translate(-1240,-575); c.lineCap='round'; c.globalAlpha=grassA; c.strokeStyle='#07060a'; for(let i=0;i