PageSourceSearch

https://dustinbrett.com/_next/static/chunks/fly-brains.0693c536baeab3a0.js

js dustinbrett.com collected 2026-10-03 19:15:25 UTC 13,372 bytes, 1 lines download raw bytes

1(()=>{"use strict";let t,e=14,s=3,a=4,i=7,r=6,l=12,n=8,h=2,o=25,c=18,p=16,g=17,m=11,f=0,u=10,d=1,y=22,b=19,A=5,w=9,k=21,L=15,M=13,R=24,v=23,E=20,U=0,x=1,I=[0,5],S=["other","sensory","ascending"],P=t=>t===f||t===d,F=t=>t===l||t===M||t===e||t===L,C=(t,e)=>(t<<e|t>>>32-e)>>>0;class B{constructor(t){let e=(t=>{let e=t>>>0;return()=>{let t=e=e+2654435769>>>0;return((t=Math.imul((t=Math.imul(t^t>>>16,569420461))^t>>>15,1935289751))^t>>>15)>>>0}})(t);this.s=[e(),e(),e(),e()],this.s.every(t=>0===t)&&(this.s[0]=1)}nextU32(){let{s:t}=this,e=C(t[0]+t[3]>>>0,7)+t[0]>>>0,s=t[1]<<9>>>0;return t[2]=(t[2]^t[0])>>>0,t[3]=(t[3]^t[1])>>>0,t[1]=(t[1]^t[2])>>>0,t[0]=(t[0]^t[3])>>>0,t[2]=(t[2]^s)>>>0,t[3]=C(t[3],11),e}float(){return(this.nextU32()>>>8)/16777216}range(t,e){return t+this.float()*(e-t)}rangeInt(t,e){return t+this.nextU32()%(e-t+1)}}let O=1/120,D=2*Math.PI,T=(t,e)=>1e3*t/Math.max(e,1),j=(t,e)=>t+(e-t)*O;class G{constructor(t){let{edgeCount:I,edgePost:S,edgePre:C,edgeSyn:B,neurons:O}=t,D=O.length,T=new Uint8Array(D),j=new Uint8Array(D),G={ascend:[],dnaL:[],dnaR:[],epg:[],escw:[],fwd:[],gf:[],groom:[],kc:[],lc11L:[],lc11R:[],loomLeft:[],loomRight:[],mbonApp:[],mbonAvd:[],mdn:[],pam:[],penL:[],penR:[],pfn:[],pn:[],ppl1:[],sens:[]},q=[],H=[],N=new Float32Array(D);O.forEach(({angle:t,cellType:w,role:x,side:I},S)=>{switch(T[S]=x,j[S]=I,x){case f:case u:case m:case d:I===U?G.loomLeft.push(S):G.loomRight.push(S),N[S]=.004;break;case h:G.gf.push(S),N[S]=.002;break;case s:case a:I===U?G.dnaL.push(S):G.dnaR.push(S),N[S]=.036;break;case A:G.mdn.push(S),N[S]=.036;break;case r:G.fwd.push(S),N[S]=.038;break;case i:G.groom.push(S),N[S]=.036;break;case n:G.escw.push(S),N[S]=.036;break;case l:void 0!==t&&(G.epg.push(S),q.push(t)),N[S]=.035;break;case M:I===U?G.penL.push(S):G.penR.push(S),N[S]=.03;break;case e:case L:N[S]=.03;break;case g:I===U?G.lc11L.push(S):G.lc11R.push(S),N[S]=.004;break;case p:N[S]=.004;break;case c:G.kc.push(S),N[S]=.002;break;case b:I===U?G.mbonApp.push(S):G.mbonAvd.push(S),N[S]=.03;break;case E:G.ppl1.push(S),N[S]=.004;break;case k:G.pam.push(S),N[S]=.004;break;case v:G.pn.push(S),N[S]=.004;break;case R:G.pfn.push(S),N[S]=.03;break;case o:N[S]=.03;break;case y:N[S]=.02;break;default:"ascending"===w?G.ascend.push(S):"sensory"===w&&G.sens.push(S),H.push(S)}});let Q=Object.fromEntries(Object.entries(G).map(([t,e])=>[t,Int32Array.from(e)])),K=new Uint8Array(D);Q.loomLeft.forEach(t=>{K[t]=1}),Q.loomRight.forEach(t=>{K[t]=1});let _=new Uint8Array(D);Q.dnaL.forEach(t=>{_[t]=1});let V=new Int32Array(D).fill(-1);Q.kc.forEach((t,e)=>{V[t]=e});let $=new Int32Array(D).fill(-1);Q.epg.forEach((t,e)=>{$[t]=e});let z=new Float32Array(I),J=new Uint8Array(I),W=new Uint32Array(D),X=0;for(let t=0;t<I;t+=1){let s=C[t],a=S[t],i=T[s],r=T[a],l=35e-5*B[t];i!==E&&i!==k||r!==c?((P(i)||i===w&&"sensory"===O[s].cellType)&&r===h&&(l*=2),F(i)&&F(r)&&(l<0?(l*=i===e&&r===e?6:12,J[t]=1):l*=i===M&&r===M?3:10),i===v&&r===c&&l>0&&(l*=24),i===c&&r===b&&l>0&&(l*=10)):l=0,z[t]=l,0!==l&&(W[s]+=1,X+=1)}let Y=new Uint32Array(D+1);for(let t=0;t<D;t+=1)Y[t+1]=Y[t]+W[t];let Z=new Uint32Array(X),tt=new Float32Array(X),et=new Uint8Array(X),st=Y.slice(0,D),at=[],it=[],rt=[],lt=[];for(let t=0;t<I;t+=1){let e=z[t];if(0!==e){let s=C[t],a=S[t],i=st[s];T[s]===c&&T[a]===b&&e>0&&(at.push(i),it.push(V[s]),rt.push(+(j[a]===x)),lt.push(e)),Z[i]=a,tt[i]=e,et[i]=J[t],st[s]=i+1}}this.n=D,this.roles=T,this.sides=j,this.rowStart=Y,this.colIdx=Z,this.wBase=tt,this.imm=et,this.isLoomNeuron=K,this.groups=Q,this.epgAngles=Float64Array.from(q),this.epgIndexOf=$,this.kcIndexOf=V,this.dnaIsLeft=_,this.plSlot=Uint32Array.from(at),this.plKc=Int32Array.from(it),this.plAvd=Uint8Array.from(rt),this.plBase=Float32Array.from(lt),this.baselineTemplate=N,this.jitteredBaseline=Int32Array.from(H);let nt=new Uint8Array(D);Q.gf.forEach(t=>{nt[t]=1}),this.noiseExempt=nt}}class q{constructor(t,e){this.inputs={activityScale:1,airPuff:0,gaitDrive:0,gaitPhase:0,loomL:0,loomR:0,rotation:0,sensoryGate:1,smallObjL:0,smallObjR:0},this.sbScale=-1,this.eligScale=1,this.adaptLive=!1,this.dirtyCount=0,this.punishAcc=0,this.rewardAcc=0,this.spikeCount=0,this.rates={central:0,dnaL:0,dnaR:0,escw:0,fwd:0,groom:0,lc11:0,lc11L:0,lc11R:0,loom:0,loomLeft:0,loomRight:0,mbApp:0,mbAvd:0,mdn:0,pop:0},this.gfLatch=!1,this.simMs=0,this.qHead=0,this.burstUntil=0,this.burstNext=12e3,this.stims=[];let{groups:s,n:a}=t,i=new B(e);if(this.c=t,this.n=a,this.rng=i,this.v=new Float32Array(a),this.refr=new Float32Array(a),this.adapt=ne
1w Float32Array(a),this.spiked=new Int32Array(a),this.epgRate=new Float32Array(t.epgAngles.length),this.epgFired=new Uint8Array(t.epgAngles.length),this.elig=new Float32Array(s.kc.length),this.w=new Float32Array(t.wBase),this.plDirty=new Uint8Array(t.plSlot.length),this.dirtyList=new Uint32Array(t.plSlot.length),this.ascendPhase=Float32Array.from({length:s.ascend.length},()=>i.range(0,D)),this.baseline=new Float32Array(t.baselineTemplate),t.jitteredBaseline.forEach(t=>{this.baseline[t]=i.range(.01,.07)}),this.sb=new Float32Array(a),this.inhQueue=Array.from({length:5},()=>new Float32Array(a)),this.inhTouched=Array.from({length:5},()=>new Int32Array(a)),this.inhCount=new Int32Array(5),s.epg.length>0){let e=i.range(-Math.PI,Math.PI),{epgAngles:a}=t,r=[];s.epg.forEach((t,s)=>{Math.cos(a[s]-e)>.4&&r.push(t)}),this.stimulate(r,.1,250)}}get neuronCount(){return this.n}getGroups(){return this.c.groups}getRates(){return this.rates}consumeGf(){let t=this.gfLatch;return this.gfLatch=!1,t}stimulate(t,e,s){0!==t.length&&(this.stims.push({idx:t,strength:e,untilMs:this.simMs+s}),this.stims.length>8&&this.stims.shift())}step(t){for(let e=0;e<t;e+=1)this.stepOneMs()}applyPlasticity(){let t=Math.min(this.punishAcc/40,1),e=Math.min(this.rewardAcc/40,1),{elig:s,eligScale:a,w:i}=this,{plAvd:r,plBase:l,plKc:n,plSlot:h}=this.c;if(t>.05||e>.05)for(let o=0;o<h.length;o+=1){let c=1===r[o]?e:t;if(c>.05){let t=s[n[o]]*a;if(t>.3){let e=h[o],s=l[o];i[e]=Math.max(i[e]*(1-.3*c*t),.15*s),0===this.plDirty[o]&&(this.plDirty[o]=1,this.dirtyList[this.dirtyCount]=o,this.dirtyCount+=1)}}}let{dirtyList:o,plDirty:c}=this,p=0;for(let t=0;t<this.dirtyCount;t+=1){let e=o[t],s=h[e],a=l[e],r=i[s]+1e-4*(a-i[s]);Math.abs(a-r)<1e-4*Math.abs(a)?(i[s]=a,c[e]=0):(i[s]=r,o[p]=e,p+=1)}this.dirtyCount=p}renormaliseEligibility(){let{elig:t,eligScale:e}=this;for(let s=0;s<t.length;s+=1)t[s]*=e;this.eligScale=1}eligibility(t){return this.elig[t]*this.eligScale}stepOneMs(){this.simMs+=1;let t=this.simMs;this.stims.some(({untilMs:e})=>t>=e)&&(this.stims=this.stims.filter(({untilMs:e})=>t<e)),t>=this.burstNext&&(this.burstUntil=t+400,this.burstNext=t+this.rng.rangeInt(15e3,4e4));let{inputs:e,n:s,refr:a,rng:i,sb:r,v:l}=this,n=(t<this.burstUntil?.0132:.0022)*e.activityScale,h=e.activityScale;if(h!==this.sbScale){let{baseline:t}=this;for(let e=0;e<s;e+=1)r[e]=t[e]*h;this.sbScale=h}if(1===t)for(let t=0;t<s;t+=1)a[t]>0?(a[t]-=1,l[t]*=.9512):l[t]=.9512*l[t]+r[t];if(n>0){let{noiseExempt:t}=this.c,e=Math.log(1-n),r=Math.floor(Math.log(1-i.float())/e);for(;r<s;)a[r]<=0&&0===t[r]&&(l[r]+=.42),r+=1+Math.floor(Math.log(1-i.float())/e)}let{groups:o}=this.c;if(e.loomL>.001){let t=.3*e.loomL*e.sensoryGate;o.loomLeft.forEach(e=>{l[e]+=t})}if(e.loomR>.001){let t=.3*e.loomR*e.sensoryGate;o.loomRight.forEach(e=>{l[e]+=t})}if(e.gaitDrive>.001){let t=e.gaitPhase*D;o.ascend.forEach((s,a)=>{l[s]+=.09*e.gaitDrive*(.5+.5*Math.sin(t+this.ascendPhase[a]))});let s=.02*e.gaitDrive;
1o.pfn.forEach(t=>{l[t]+=s})}if(e.airPuff>.001){let t=.12*e.airPuff*e.sensoryGate;o.sens.forEach(e=>{l[e]+=t})}if(Math.abs(e.rotation)>.001){let t=.35*Math.min(Math.abs(e.rotation),8)*e.activityScale,s=e.rotation>0?o.penR:o.penL,a=e.rotation>0?o.penL:o.penR;s.forEach(e=>{l[e]+=t}),a.forEach(e=>{l[e]=Math.max(l[e]-.6*t,-2)})}if(e.smallObjL>.001){let t=.25*e.smallObjL*e.sensoryGate;o.lc11L.forEach(e=>{l[e]+=t})}if(e.smallObjR>.001){let t=.25*e.smallObjR*e.sensoryGate;o.lc11R.forEach(e=>{l[e]+=t})}this.eligScale*=.99967,this.eligScale<1e-6&&this.renormaliseEligibility(),this.punishAcc*=.98,this.rewardAcc*=.98,t%50==0&&this.applyPlasticity(),this.stims.forEach(({idx:t,strength:e})=>{t.forEach(t=>{l[t]+=e})});let c=this.inhQueue[this.qHead],p=this.inhTouched[this.qHead],g=this.inhCount[this.qHead];for(let t=0;t<g;t+=1){let e=p[t];0!==c[e]&&(l[e]=Math.max(l[e]+c[e],-2),c[e]=0)}this.inhCount[this.qHead]=0;let{isLoomNeuron:m}=this.c,{adapt:f,spiked:u}=this,d=0;if(this.adaptLive){let t=0;for(let e=0;e<s;e+=1)if(a[e]>0)a[e]-=1,l[e]*=.9512,f[e]>1e-4&&(f[e]*=.9876,t+=1);else if(l[e]>=1)l[e]=0,a[e]=1,1===m[e]?(f[e]=.9876*(f[e]+.4),t+=1):f[e]>1e-4&&(f[e]*=.9876,t+=1),u[d]=e,d+=1;else{let s=.9512*l[e]+r[e];f[e]>1e-4&&(s-=f[e],f[e]*=.9876,t+=1),l[e]=s}0===t&&(this.adaptLive=!1)}else for(let t=0;t<s;t+=1)a[t]>0?(a[t]-=1,l[t]*=.9512):l[t]>=1?(l[t]=0,a[t]=1,1===m[t]&&(f[t]=.9876*(f[t]+.4),this.adaptLive=!0),u[d]=t,d+=1):l[t]=.9512*l[t]+r[t];this.spikeCount=d;let y=(this.qHead+4)%5,b=this.inhQueue[y],A=this.inhTouched[y],{colIdx:w,imm:k,rowStart:L}=this.c,{w:M}=this,R=this.inhCount[y];for(let t=0;t<d;t+=1){let e=u[t],a=L[e+1];for(let t=L[e];t<a;t+=1){let e=w[t],a=M[t];a>=0?l[e]+=.9512*a:1===k[t]?l[e]=Math.max(l[e]+.9512*a,-1.9024+r[e]):(0===b[e]&&R<s&&(A[R]=e,R+=1),b[e]+=a)}}this.inhCount[y]=R,this.qHead=(this.qHead+1)%5,this.updateRates()}compass(){let t=0,e=0,s=0,{epgAngles:a}=this.c;for(let i=0;i<this.epgRate.length;i+=1){let r=this.epgRate[i];t+=Math.cos(a[i])*r,e+=Math.sin(a[i])*r,s+=r}return{angle:Math.atan2(e,t),strength:s>1?Math.hypot(t,e)/s:0}}updateRates(){let t=0,e=0,l=0,o=0,p=0,y=0,w=0,L=0,M=0,R=0,v=0,I=0,S=0,P=0,{dnaIsLeft:F,epgIndexOf:C,kcIndexOf:B,roles:O,sides:D}=this.c,{epgFired:G,spiked:q}=this,H=this.spikeCount;G.fill(0);for(let T=0;T<H;T+=1){let j=q[T],H=C[j];switch(H>=0&&(G[H]=1),O[j]){case f:case u:case m:case d:t+=1,D[j]===U?e+=1:l+=1;break;case s:case a:1===F[j]?o+=1:p+=1;break;case A:y+=1;break;case r:w+=1;break;case i:L+=1;break;case n:M+=1;break;case h:this.gfLatch=!0;break;case g:D[j]===U?R+=1:v+=1;break;case c:{let t=B[j];if(P+=1,t>=0){let e=1/this.eligScale;this.elig[t]=Math.min(this.elig[t]+.15*e,e)}break}case b:D[j]===x?S+=1:I+=1;break;case E:this.punishAcc+=1;break;case k:this.rewardAcc+=1}}let{rates:N}=this,{groups:Q}=this.c,K=Q.loomLeft.length+Q.loomRight.length;N.loom=j(N.loom,T(t,K)),N.loomLeft=j(N.loomLeft,T(e,Q.loomLeft.length)),N.loomRight=j(N.loomRight,T(l,Q.loomRight.length)),N.dnaL=j(N.dnaL,T(o,Q.dnaL.length)),N.dnaR=j(N.dnaR,T(p,Q.dnaR.length)),N.mdn=j(N.mdn,T(y,Q.mdn.length)),N.fwd=j(N.fwd,T(w,Q.fwd.length)),N.groom=j(N.groom,T(L,Q.groom.length)),N.escw=j(N.escw,T(M,Q.escw.length)),N.lc11=j(N.lc11,T(R+v,Q.lc11L.length+Q.lc11R.length)),N.lc11L=j(N.lc11L,T(R,Q.lc11L.length)),N.lc11R=j(N.lc11R,T(v,Q.lc11R.length)),N.mbApp=j(N.mbApp,T(I,Q.mbonApp.length)),N.mbAvd=j(N.mbAvd,T(S,Q.mbonAvd.length)),N.pop=j(N.pop,T(H,this.n)),N.central=j(N.central,T(H-P,this.n-Q.kc.length));for(let t=0;t<this.epgRate.length;t+=1)this.epgRate[t]+=(1e3*(1===G[t])-this.epgRate[t])/60}}let H=(t,e,s)=>Math.min(Math.max(t,e),s);class N{make(t,e){let s=t.getRates(),a=s.dnaL-s.dnaR;return this.dnaBaseline+=(a-this.dnaBaseline)*Math.min(e/8,1),{arousal:H(s.central/20,0,1),backward:s.mdn>8,clock:1,escape:t.consumeGf(),groomDrive:s.groom/8,lc11:H(s.lc11/16,0,1),lc11Bias:H((s.lc11L-s.lc11R)/16,-1,1),loomBias:H((s.loomLeft-s.loomRight)/8,-1,1),mbApproach:s.mbApp,mbAvoid:s.mbAvd,nervous:H(s.loom/16,0,1),sleep:!1,tempo:1,turnBias:H(.04*(a-this.dnaBaseline),-1,1),walkDrive:H(s.fwd/10,0,1.3),wingDrive:H(s.escw/10,0,1.3)}}constructor(){this.dnaBaseline=0}}let Q=[],K=[],_=0,V=Promise.resolve();globalThis.addEventListener("message",({data:e})=>{V=V.then(async()=>{switch(e.type){case"init":{let s=await fetch(e.url);t=new G((t=>{let e=new DataView(t);if(1179408707!==e.getUint32(0,!1))throw Error("desktop-fly: bad circuit magic");let s=e.getUint8(4),a=I[s];if(!a)throw Error(`desktop-fly: unsupported circuit format ${s}`);let i=e.getUint16(6,!0),r=e.getUint32(8,!0),l=[],n=12;for(let t=0;t<i;t+=1){let t=e.getUint8(n),s=e.getUint8(n+1),i=e.getUint8(n+2),r=e.getInt16(n+3,!0);l.push({...32767===r?{}:{angle:r/1e4},cellType:S[i]??"other",role:t,side:s}),n+=a}let h=n%2==0?t:t.slice(n,n+6*r),o=h===t?n:0,c=new Uint16Array(h,o,3*r),p=new Int16Array(h,o,3*r),g=new Uint16Array(r),m=new Uint16Array(r),f=new Int16Array(r);for(let t=0,e=0;t<r;t+=1,e+=3)g[t]=c[e],m[t]=c[e+1],f[t]=p[e+2];return{edgeCount:r,edgePost:m,edgePre:g,edgeSyn:f,neurons:l}})(await s.arrayBuffer())),globalThis.postMessage({type:"ready"});break}case"add":t&&(Q.push(new q(t,e.seed)),K.push(new N));break;case"remove":Q.splice(e.index,1),K.splice(e.index,1);break;case"reset":Q.length=0,K.length=0,_=0;break;case"frame":(({dt:t,inputs:e,roster:s,stims:a})=>{let i=Math.min(Math.floor(_+=1e3*t),50);_-=i,a.forEach(({durationMs:t,group:e,index:s,key:a,salt:i,strength:r})=>{let l=Q[s];if(!l)return;let n=l.getGroups(),h=e?n[e]:((t,e,s,a=4)=>{let i=[],r=2166136261^s;for(let t=0;t<e.length;t+=1)r^=e.codePointAt(t)??0,r=Math.imul(r,16777619);return t.forEach((t,e)=>{let s=r^e;s=Math.imul(s^s>>>15,2246822519),((s^=s>>>13)>>>0)%a==0&&i.push(t)}),i})(n.pn,a??"",i??0);l.stimulate(h,r,t)}),globalThis.postMessage({roster:s,signals:Q.map((s,a)=>{s.inputs=e[a],s.step(i);let r=K[a].make(s,t),l=s.compass();return l.strength>.05&&(r.compass=l),r}),type:"signals"})})(e)}}).catch(()=>{})},{passive:!0})})(),_N_E={};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.