Deck.transition('line',{dur:1.2,frag:`void main(){ float e=p<.5?1.-p*2.:p*2.-1.; float h=max(e*e*(3.-2.*e),.0005); float y=(vUv.y-.5)/h+.5, ins=step(0.,y)*step(y,1.); vec2 u=vec2(vUv.x,sat(y)); vec3 c=(p<.5?texture(tA,u).rgb:texture(tB,u).rgb)*ins; float g=sin(3.14159*p), dy=abs(vUv.y-.5); c+=vec3(1.,.82,.55)*g*(smoothstep(.006,0.,dy)*1.2+.35*exp(-dy*40.)); o=vec4(c,1.); }`}); Deck.scene({ id:'aim', title:'Aim', enterWith:'line', post:{bloom:.9,threshold:1,vignette:.3,grain:.035}, beats:[{dur:1.8,hold:4},{dur:3.6,hold:5},{dur:3.4,hold:5},{dur:4.5,hold:5}], notes:[ 'Everything so far assumed one thing: that it aims where we meant it to. Alignment is the question of what it actually wants.', 'Suppose we get it almost right. One degree off. At ten metres that is seventeen centimetres. Every demo and every test happens at ten metres.', 'But the same degree keeps going. At the Moon you miss by about 6,700 kilometres, almost two whole Moons. At the nearest star you miss by 4,700 times the distance from the Earth to the Sun. It is only geometry: the tangent of one degree times the distance.', 'Here is the nearest star. The two lines left the bow as one line. Once the arrow is in the air, nobody can steer it. (Pause.) So the aim is the whole job, and we only get to set it before we let go.' ], setup(d){ return { bg:d.pass(`uniform float uZ,uSpace,uBow; uniform vec4 uL1,uL2; uniform vec2 uLa,uSh; uniform vec3 uMoon,uStar,uHit; float seg(vec2 q,vec2 a,vec2 b){ vec2 pa=q-a,ba=b-a; float h=sat(dot(pa,ba)/max(dot(ba,ba),1e-4)); return length(pa-ba*h); } float winD(vec2 w,float cx){ return min(sdBox(w-vec2(cx,450.),vec2(110.,190.)),length(w-vec2(cx,260.))-110.); } vec3 hall(vec2 q){ float Z=1.+2.2*uZ; vec2 S=vec2(960.,540.)+vec2(190.,40.)*uZ, C=vec2(960.,540.)+vec2(390.,60.)*uZ; vec2 w=C+(q-S)/Z+uSh; vec3 c=vec3(.11,.07,.042)*(.75+.5*fbm(w*vec2(.03,.004))); c*=mix(.4,1.,smoothstep(100.,130.,w.y)); float sh=0., x0=w.x+(w.y-450.)*.55; for(int i=0;i<3;i++){ float cx=i==0?820.:(i==1?1560.:1820.); float dw=winD(w,cx); vec2 g=abs(fract((w-vec2(cx,0.))/vec2(55.,64.)+.5)-.5)*vec2(55.,64.); vec3 lt=vec3(1.2,.9,.58)*(.85+.3*fbm(w*.012+float(i)))*smoothstep(1.5,3.5,min(g.x,g.y)); c=mix(c,vec3(.04,.025,.015),smoothstep(1.,-1.,dw)); c=mix(c,lt,smoothstep(1.,-1.,dw+5.)); sh+=smoothstep(110.,70.,abs(x0-cx))*smoothstep(450.,650.,w.y); } if(w.y>760.){ float dy=w.y-700., u=(w.x-960.)/dy, bu=fract(u*3.); vec3 wood=vec3(.3,.18,.09)*(.7+.5*fbm(vec2(u*20.,3000./dy)))*(.7+.3*smoothstep(0.,.025,min(bu,1.-bu))); c=wood*(.45+.25*smoothstep(760.,1080.,w.y))*(1.+1.2*sh); } c+=vec3(.9,.6,.32)*.1*sh*(.6+.8*fbm(w*.008+vec2(uTime*.03,-uTime*.015))); vec2 T=vec2(1350.,600.); c=mix(c,vec3(.03,.02,.012),smoothstep(1.,-1.,sdBox(w-vec2(1350.,700.),vec2(7.,62.)))); float rr=length(w-T), a=fwidth(rr)+.5; vec3 wh=vec3(.72,.68,.6)*(.85+.25*fbm(w*.08)), bk=vec3(.025); vec3 tc=vec3(1.,.62,.14); tc=mix(tc,wh,smoothstep(18.-a,18.+a,rr)); tc=mix(tc,bk,smoothstep(30.-a,30.+a,rr)); tc=mix(tc,wh,smoothstep(44.-a,44.+a,rr)); tc=mix(tc,bk,smoothstep(60.-a,60.+a,rr)); tc=mix(tc,wh,smoothstep(70.-a,70.+a,rr)); return mix(c,tc,smoothstep(90.+a,90.-a,rr)); } vec3 space(vec2 q){ vec2 s=q+uSh*.6; vec3 c=vec3(.004,.006,.013); c+=vec3(.05,.045,.06)*exp(-pow((s.y+s.x*.35-900.)/260.,2.))*fbm(s*.004+3.); vec2 g=s/9.; float h=hash12(floor(g)); c+=vec3(.75,.82,1.)*step(.982,h)*smoothstep(.45,0.,length(fract(g)-.5))*(h-.982)*55.*(.7+.3*sin(uTime*1.3+h*80.)); vec2 m=(q-uMoon.xy)/max(uMoon.z,1.); float dd=length(m); if(dd<1.05){ vec3 n=vec3(m.x,-m.y,sqrt(max(1.-dd*dd,0.))); float alb=.5*(.75+.4*fbm(m*4.+7.))-.18*smoothstep(.5,.65,fbm(m*1.6+2.)); vec2 cg=m*5.; alb*=1.-.3*step(.6,hash12(floor(cg)))*smoothstep(.35,.2,length(fract(cg)-.5)); c=mix(c,vec3(1.,.97,.92)*alb*(sat(dot(n,normalize(vec3(.9,.25,.35))))*1.4+.015),smoothstep(1.,1.-1.5/max(uMoon.z,1.),dd)); } vec2 a=abs(q-uStar.xy); float sd=length(a); c+=vec3(1.,.88,.7)*uStar.z*(8.*exp(-sd*.4)+.25*exp(-sd*.025)+.5*exp(-a.y*.6-a.x*.03)+.5*exp(-a.x*.6-a.y*.03)); return c; } void main(){ vec2 q=design(vUv); vec3 c=vec3(0.); if(uSpace<.999) c=hall(q); if(uSpace>.001) c=mix(c,space(q),uSpace); float ba=uBow*(1.-uSpace); if(ba>.001){ vec2 b=q+vec2(500.*uZ,0.)-uSh*2.5; float sy=(b.y-560.)/700.; float dl=abs(b.x-900.-140.*(1.-sy*sy))-(11.-5.*abs(sy)); float ds=min(seg(b,vec2(900.,-140.),vec2(640.,560.)),seg(b,vec2(640.,560.),vec2(900.,1260.)))-1.2; float da=seg(b,vec2(600.,558.),vec2(1080.,584.))-3.5; c=mix(c,vec3(.04,.025,.015),max(smoothstep(4.,-4.,min(dl,da)),.8*smoothstep(1.5,-1.5,ds))*ba); } c*=1.-.45*(1.-uSpace)*smoothstep(1050.,450.,q.x)*smoothstep(560.,250.,q.y); float d1=seg(q,uL1.xy,uL1.zw), d2=seg(q,uL2.xy,uL2.zw); c+=vec3(.55,.75,1.)*uLa.x*(1.8*smoothstep(1.6,0.,d1)+.18*exp(-d1*.12)); c+=vec3(1.,.72,.38)*uLa.y*(2.4*smoothstep(1.8,0.,d2)+.25*exp(-d2*.12)); float hd=length(q-uHit.xy); c+=vec3(1.,.8,.5)*uHit.z*(4.*exp(-hd*.25)+.3*exp(-hd*.03)); o=vec4(c,1.); }`,'aim hall') } }, draw(s,d,r){ const E=d.E, L=E.lin, c=d.ctx2d, cream='#f2e6cf', blue='#a9cdf5', lp=(a,b,t)=>a+(b-a)*t; const z=s.k(1,0,2.6,E.io3), sp=s.k(2,0,1.6), shot=s.k(1,1.4,3.4,E.out3), ext=s.k(2,0,3.4,E.out3), k3=s.k(3,0,4.5,E.io3); const shx=(s.mouse.x*12+8*Math.sin(s.t*.15))*(1-z*.5), shy=(s.mouse.y*6+3*Math.sin(s.t*.11))*(1-z*.5); const Z=1+2.2*z, W=(x,y)=>[960+190*z+(x-960-390*z-shx)*Z, 540+40*z+(y-540-60*z-shy)*Z]; const B=W(500,1000), T=W(1350,600), H=W(1380,594); const Ox=-200+400*k3, Y=640, mX=1250-870*k3, mR=70-60*k3, ratio=3.86*mR/(mX-Ox); const sIx=Ox+(lp(mX,1680,k3)-Ox)*ext, sAx=Ox+(lp(d.view.x1+60,1680,k3)-Ox)*ext, sAy=Y-ratio*(sAx-Ox); const la=Math.min(1,shot*4), q=s.k(3,2.5,4.5); r.bg.draw({ uZ:z, uSpace:sp, uBow:1-s.k(1,0,1.6,L), uSh:[shx,shy], uL1:[lp(B[0],Ox,sp),lp(B[1],Y,sp),lp(lp(B[0],T[0],shot),sIx,sp),lp(lp(B[1],T[1],shot),Y,sp)], uL2:[lp(B[0],Ox,sp),lp(B[1],Y,sp),lp(lp(B[0],H[0],shot),sAx,sp),lp(lp(B[1],H[1],shot),sAy,sp)], uLa:[.7*la*(1-.3*q),la*(1-.2*q)], uMoon:[mX,Y,mR], uStar:[1680,640,(.15+.85*k3)*sp], uHit:[H[0],H[1],s.k(1,3,3.4)*(1-sp)] }); const br=(x,y1,y2,a)=>{ c.save(); c.globalAlpha=a; c.strokeStyle=cream; c.lineWidth=3; c.beginPath(); c.moveTo(x-10,y1); c.lineTo(x,y1); c.lineTo(x,y2); c.lineTo(x-10,y2); c.stroke(); c.restore(); }; const ring=(x,y,rad,a)=>{ c.save(); c.globalAlpha=a; c.strokeStyle=blue; c.lineWidth=2.5; c.beginPath(); c.arc(x,y,rad,0,6.2832); c.stroke(); c.restore(); }; const a1=s.k(1,2.8,3.6,L)*(1-sp); if(a1>0){ const by=T[1]+90*Z+44; c.save(); c.globalAlpha=a1; c.strokeStyle=cream; c.lineWidth=3; c.beginPath(); c.moveTo(T[0],by-12); c.lineTo(T[0],by); c.lineTo(H[0],by); c.lineTo(H[0],by-12); c.stroke(); c.restore(); d.text('10 metres: 17 cm',{x:(T[0]+H[0])/2,y:by+16,size:32,font:'mono',color:cream,align:'center',alpha:a1}); } const a2=s.k(2,1.6,2.4,L)*(1-k3), a3=s.k(2,2.6,3.4,L)*(1-k3); if(a2>0) ring(mX,Y,mR*1.6,a2); if(a3>0){ const bx=mX+mR*1.6+40, y2=Y-ratio*(bx-Ox); br(bx,Y,y2,a3); d.text('6,700 km',{x:bx+20,y:(Y+y2)/2-20,size:36,font:'mono',color:cream,alpha:a3}); } const a4=s.k(3,3,4,L); if(a4>0){ const bx=1740, y2=Y-ratio*(bx-Ox); ring(1680,Y,30,a4); br(bx,Y,y2,a4); d.text('4,700 AU',{x:bx-24,y:(Y+y2)/2-30,size:36,font:'mono',color:cream,align:'right',alpha:a4}); d.text('nearest star, illustration',{x:bx-24,y:(Y+y2)/2+18,size:26,font:'mono',color:'#b9b2a6',align:'right',alpha:a4}); } d.text('What does\nit want?',{x:150,y:150,size:120,font:'display',color:cream,show:s.k(0,.3,1.6,L),hide:s.k(1,0,.6,L)}); d.text('Miss by\none degree.',{x:150,y:150,size:120,font:'display',color:cream,show:s.k(1,.8,2.2,L),hide:s.k(3,0,.6,L)}); } });