-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
2 lines (2 loc) · 29.1 KB
/
main.js
1
2
!function(e){var t={};function n(o){if(t[o])return t[o].exports;var a=t[o]={i:o,l:!1,exports:{}};return e[o].call(a.exports,a,a.exports,n),a.l=!0,a.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(o,a,function(t){return e[t]}.bind(null,a));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";function o(e,t){return{x:e,y:t}}function a({x:e,y:t}){return o(e,t)}function i(e,t){return t.x=e.x,t.y=e.y,t}function r(e,t,n=o()){return n.x=e.x-t.x,n.y=e.y-t.y,n}function c(e,t,n=o()){return n.x=e.x+t.x,n.y=e.y+t.y,n}function s(e,t,n=o()){return n.x=e.x/t,n.y=e.y/t,n}function l(e,t,n,a=o()){a.x=(1-n)*e.x+n*t.x,a.y=(1-n)*e.y+n*t.y}function u(e,t,n,a){function i(i,r=o()){const c=i*i,s=c*i,l=1-i,u=l*l,h=u*l;return r.x=h*e.x+3*u*i*t.x+3*l*c*n.x+s*a.x,r.y=h*e.y+3*u*i*t.y+3*l*c*n.y+s*a.y,r}return{at:i,getPoints:function(e){const t=new Array(e);for(let n=0;n<e;n++)t[n]=i(n/(e-1));return t}}}n.r(t);const h=[["First Day Of Work",[0,.5],[["An Easy Day",.75,[200,30,1,[0,0,0]]],["Ignore Distractions",.8,[800,30,2,[0,0,0]]],["First Decision",.75,[600,30,2,[0,1]]],["Think Fast",.8,[600,30,2,[0,1]]],["Think Faster",.85,[400,30,2,[0,1]]],["Gotta be twice as good",.85,[400,30,2,[0,1,0]]],["Swinging the cable",.87,[400,80,2,[0,1,0,1]]],["Learn a Pattern",.89,[400,80,2,[0,1,0,1]]]],"The Electron Gods are pleased with your work"],["A Bit of Thrust",[.5,.9],[["Following Orders",.87,[420,60,2,[0,1,0,1,0,1,0,1,0,1]]],["Long Distane Call",.88,[420,60,2,[0,1,0,1,0,1,0,1,0,1,0,1,0,1]]],["Flipped Bit",.88,[450,60,2,[0,1,0,1,0,1,1,1,0,1]]],["The Shift",.88,[450,60,2,[1,0,1,0,1,1,1,0,1,0]]],["Third Element",.87,[420,30,3,[0,2,0,2,0,2,2,2,0,2]]],["Get On Through",.87,[420,30,3,[0,2,0,2,1,2,2,2,0,2]]],["Confusing Management",.9,[420,34,3,[1,2,1,2,0,1,2,1,2]]],["New Orders",.92,[420,50,4,[1,2,1,2,0,1,2,1,3]]],["Responsabilities",.93,[420,60,4,[1,2,1,2,0,1,2,1,4]]]],"The Electrons Gods notice your focus and agility"],["High Width Mountain Flows",[0,1],[["Think Fast Act Slow",.5,[140,30,8,[1,7,1]]],["A Taste Of Deja-vu",.7,[420,35,8,[1,7,1,7,1,7]]],["Mind All The Gaps",.85,[520,35,8,[1,7,1,7,1,7,6,1,7]]],["Doing the Same Thing",.9,[520,35,8,[1,7,1,7,1,7,6,1,7]]],["The Repeating Task",.925,[520,35,8,[1,7,1,7,1,7,6,1,7]]],["Nothing Can Happen To Me",.5,[520,35,8,[1,7,1,7,1,7,6,1,7]]],["Caught by surprise",.9,[520,35,8,[1,7,1,7,1,7,6,6,1,7]]]],"You were The Right Electron for the Mission, the Electron Gods says"],["Airplane Company",[.25,.7],[["The Landing",.8,[800,80,5,[0,1,2,3,4]]],["Taking off",.85,[800,200,8,[7,6,5,3,0]]],["Descent",.9,[800,100,5,[0,1,2,3,4]]],["Touch And Go",.91,[800,80,5,[0,1,2,3,4,4,3,2,0]]],["Two In a Row",.92,[900,80,5,[0,1,2,3,4,2,2,1,2,3,4]]],["Distortions",.95,[1e3,80,5,[0,1,2,3,4,2,0,1,2,3,4]]],["Direct Connection",.92,[1e3,80,5,[0,1,2,3,4,0,1,2,3,4]]]],"The Electron Gods are delighted by your ease of manoeuver"],["Fives ways to do it",[.8,.35],[["The Way of the last",.9,[200,30,3,[1,1,1,1,0]]],["The Way of the Follower",.9,[200,30,3,[1,1,1,0,1]]],["The Way of the Middle",.9,[200,30,3,[1,1,0,1,1]]],["The Way of the Abrupt",.9,[200,30,3,[1,0,1,1,1]]],["The Way of the Early",.9,[200,30,3,[0,1,1,1,1]]]],"By achieving the five ways, you stand closer to the Electron Gods"],["Same boss Everyday",[.45,.5],[["A Morning",.9,[200,30,4,[1,3,2,1,3,2,1]]],["The Same Morning",.9,[250,30,4,[1,3,2,1,3,2,1,3,2,1]]],["The Same Dinner",.9,[300,30,4,[1,3,2,1,3,2,1,3,2,1,3,2,1]]],["The Same Night",.9,[400,30,4,[1,3,2,1,3,2,1,3,2,1,3,2,1,3,2]]]],"The Electron Gods know you need something else"],["Blind Routing",[.6,.7],[["Pattern Fidelity",.95,[800,20,2,[0,1,0,1,0,1,0,1,0,1]]],["Specialisation",.97,[800,20,2,[0,1,0,1,0,1,0,1,0,1]]],["Become the Automata",.98,[800,20,2,[0,1,0,1,0,1,0,1,0,1]]],["Electron-Machine",.99,[800,20,2,[0,1,0,1,0,1,0,1,0,1]]],["Detached/1",1,[600,20,2,[0,1,0,1,0,1,0,1,0,1]]],["Detached/2",1,[500,20,2,[0,1,0,1,0,1,0,1,0,1]]],["Detached/3",1,[400,20,2,[0,1,0,1,0,1,0,1,0,1]]],["Detached/4",1,[380,20,2,[0,1,0,1,0,1,0,1,0,1]]],["Detached/5",1,[380,25,2,[0,1,0,1,0,1,0,1,0,1]]],["Detached/6",1,[380,30,2,[0,1,0,1,0,1,0,1,0,1]]],["Detached/7",1,[380,40,2,[0,1,0,1,0,1,0,1,0,1]]],["Detached/8",1,[380,50,2,[0,1,0,1,0,1,0,1,0,1]]],["Detached/9",1,[380,57,2,[0,1,0,1,0,1,0,1,0,1]]],["You've changed",1,[380,57,2,[0,1,0,1,0,1,0,1,0,0]]]],"The Electron Gods recognised something bright in you"],["Patience",[.75,0],[["On Rails",.8,[2e3,30,2,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]],["Trunkin'",.65,[2e3,30,2,[0,0,0,0,0,0,0,0,0,0,1,0,0,1,1]]],["Slow Memory",.5,[600,50,4,[0,3,2,3,1,3,0]]]],"Your obedience to the Electron Gods is noticed as extreme"],["The Final Enlightenment",[.172,1.5],[["The Golden Path",.1,[6e3,50,1,[0,1,0]]]],"The Electron Gods made you one of them"]].map(([e,t,n,o])=>({name:e,hs:t,subs:n.map(([e,t,n])=>({name:e,spd:t,level:n})),cleared:o}));function d(e,t){const n=h[e].subs[t].level,[i,l,d,f]=n,g=i,m=l,p=d,y=f.length,v=f,x=e=>e%g,w=e=>Math.floor(e/g),A=(e,t)=>e+t*g,M=new Array(p).fill(0).map((e,t)=>m*(t+1)/(p+1)),b=new Array(y+3).fill(0).map((e,t)=>{const n=v[Math.max(0,t-2)];return{x:t*g/(y+2),good:n,ys:M}});b[1].ys=[b[2].ys[b[2].good]],b[1].good=0,b[0].ys=[b[1].ys[b[1].good]],b[0].good=0,b[b.length-1].ys=[b[b.length-2].ys[b[b.length-2].good]],b[b.length-1].good=0;const T=new Array(g*m).fill(0).map((e,t)=>"*");for(let e=0;e<b.length-1;e++){const t=b[e],n=b[e+1],a=t.ys[t.good];n.ys.forEach((i,r)=>{const c=r===n.good,s=c?1:.8,l=[o(t.x,a),o((t.x+n.x)/2,a),o((t.x+n.x)/2,i+.01),o((1-s)*t.x+s*n.x,i)],h=Math.ceil(n.x-t.x),d=u(...l).getPoints(h);0===e?E(d,"O"):e===b.length-2?E(d,"G"):E(d,c?"M":"S")})}const S=b.slice(2,b.length-1).map(({good:e})=>e);function E(e,t){const n=[];for(let t=1;t<e.length;t++){const o=e[t-1],i=r(e[t],o),l=Math.ceil(Math.max(i.x,i.y)),u=s(i,l);let h=a(o);for(let e=0;e<l;e++){const e=Math.round(h.x),t=Math.round(h.y);n.push(A(e,t)),c(h,u,h)}}return n.forEach(e=>{const n=x(e),o=w(e),a=Math.ceil(2);for(let e=-1*a;e<=a;e++){const a="G"===t&&n>g-5;T[A(n+0,o+e)]=a?"G":"B"}}),n.forEach(e=>{T[e]=t}),n}return{startPosition:{x:b[0].x,y:b[0].ys[0]},choices:b,width:g,height:m,idx2i:x,idx2j:w,ij2idx:A,outij:(e,t)=>e<0||e>=g||t<0||t>=m,map:T,directions:S}}function f(e,t,n){return(1-n)*e+n*t}function g(e,t,n){return Math.max(t,Math.min(e,n))}const m=[],p=["ABCDEFGHIJKLMNOPQR","STUVWXYZabcdefghij","klmnopqrstuvwxyz","0123456789",".,\"'?!@_*#$%&()+-/",":;(=)[\\]{|}~~~~~~~"].map(e=>e.padEnd(18," ")).join("").split("");p.forEach((e,t)=>{const n=e.charCodeAt(0),o=t%18,a=Math.floor(t/18),i=8*o,r=8*a;n<128&&(m[n]={idx:t,i:o,j:a,x:i,y:r})});const y={dim:8,table:p,codeIndex:m,src:"data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAJAAAAAwAgMAAACDNBvFAAAACVBMVEUAAAAAAAD///+D3c/SAAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAALiMAAC4jAXilP3YAAAAHdElNRQfkCQMVOzPHK9EeAAAAGXRFWHRDb21tZW50AENyZWF0ZWQgd2l0aCBHSU1QV4EOFwAAAjZJREFUOMutVUGO2zAMJHgi9ArCJ0GvFPakZxA9GXllZ0jbcZptESyqZB1bHpHD0VAr8snQOaLFiLGPvYVbm2LuLm64j3qHGePXMJ0vVDA1XXrv5sdHiHcxG3Pg1dgJGliwre0JGjujHJH2irRV1OU2whfSZaqXdJ7pcO3O2SJIwiTuUsRxdTxZEWmIJ/9nTGEKkDvrQBrBHAZTxHHPn6RacmFVmxsEbKuFgtMWWpFOkE7N4ClizzohaKaTLNp8WwSptJmFo2bQADRBfoC4CwoqfkbignWAmA5/s4SEZuvixF00hWr/rL5FXudnWhkc9YfDvgGB2nIPanLwmZe4RnEJcpm/VsNErxJv4tJuBZoyv9IuVfhd3N4PKs1PUE8QxDVKtS3otuzkpEFQcYKBQ/Crk8kuTs/htfdvOn06gIZhcYWXNGjlb9Z7r30TNhYe8/4NtCACyKsP9irb4B20GV9k4x0N1fY3EL1XJkuV5VL5lXhLunB3ZJ/Fp9b4wSjvqEto2ri2XMG0oXP0tNzhhLCsDNWi+0Z092wwPfaLMtCd6JVtp6Mf+xdeN7lAt0IwAc2kByMh6iKIAivPTLn2aouKpGbd44xkNxAmqDU5PdC7bUl29EHp3h2PR1X3evZ886h/PajqqBCFeXmHmdDdzgU6j7XT0k9SB5CAPKS5/iNASBwUVFKfIJIOu6WO1J1yp6QFHdiDqzMqHSLNTPYSiW6+0p3EaeMTZDzRnseOvpqiqpM04jF+AzdFs2vmLgJlAAAAAElFTkSuQmCC"};function v(e,t){let n=void 0;return function(e,t){let n=new Image;n.onload=function(){const e=document.createElement("canvas");e.width=n.width,e.height=n.height;const o=e.getContext("2d");o.drawImage(n,0,0),t(e,o)},n.src=e}(e.src,(e,o)=>{if(1===t)n=o.getImageData(0,0,e.width,e.height);else{const e=function(e,t){const n=e.canvas,o=e.getImageData(0,0,n.width,n.height).data,a=document.createElement("canvas");a.width=n.width*t,a.height=n.height*t;const i=a.getContext("2d"),r=i.getImageData(0,0,a.width,a.height),c=r.data;for(let e=0;e<c.length;e++){const i=Math.floor(e/4),r=e%4,s=i%a.width,l=Math.floor(i/a.width),u=4*(Math.floor(s/t)+Math.floor(l/t)*n.width)+r;c[e]=o[u]}return i.putImageData(r,0,0),{canvas:a,ctx:i,imageData:c}}(o,t);n=e.ctx.getImageData(0,0,e.canvas.width,e.canvas.height)}}),{getImageData:()=>n,fontInfo:{dim:e.dim*t,table:e.table,codeIndex:e.codeIndex.map(e=>({...e,x:e.x*t,y:e.y*t}))}}}const x=v(y,1);v(y,2),v(y,4);function w(e){return e/1e3}function A(e){return 69+12*Math.log2(e/440)}function M(e){return 440*Math.pow(2,(e-69)/12)}function b(e,t){return e.reduce((e,t)=>[...e,e[e.length-1]+t],[t])}const T=e=>t=>t[e],S=T("gain"),E=T("frequency"),G=T("Q"),k=(T("playbackRate"),T("delayTime"),T("detune")),D=e=>(t,n)=>e.linearRampToValueAtTime(t,n),R=e=>(t,n)=>e.linearRampToValueAtTime(t,n),I=e=>t=>e.value=t;function C(e,{values:t,durations:n},o){const a=b(n,o),i=R(e),r=D(e);return i(0,a[0]),r(t[0],a[1]),r(t[1],a[2]),r(t[1],a[3]),r(0,a[4]),a[4]}function L(e){return function(t,n){const o=t.sampleRate*n,a=t.createBuffer(1,o,t.sampleRate),i=a.getChannelData(0);for(let t=0;t<o;t++)i[t]=e(t,o);return a}}const O=L(e=>2*Math.random()-1),F=L(e=>Math.random()>.985?1:0),P=L((e,t)=>e<t/2?0:1);function W(e,t,n,o,a=!1){const i=e.createBufferSource();return i.buffer=t,i.connect(n),i.loop=a,i.start(o),i}function B(e){const t=e.createGain();return t.gain.value=0,t}function j(...e){const t={};return function(e,t,n,o,a,i){i(0);const r=new OfflineAudioContext(e,t,n),c=setInterval(()=>{i(r.currentTime/t*n)},1e3);o(r),r.startRendering().then(e=>{clearInterval(c),i(1),a(e)})}(1,44100*e[0],44100,t=>{!function(e,t=1,n,o,a,i,r,c,s,l,u,h,d){const f=e.createOscillator(),g=O(e,t),m=e.createGain(),p=W(e,g,m,0,!0),y=e.createOscillator(),v=e.createDelay(),x=e.createGain(),w=e.createGain(),A=e.createGain(),M=e.createGain(),b=e.createDynamicsCompressor(),T=e.createBiquadFilter();function S(e,t){if(!t)return;e.setValueAtTime(t[0],0);let n=0;for(let o=1;o<t.length;o++){let a=t[o];o%2?n=a:e[(n<0?"exponential":"linear")+"RampToValueAtTime"].bind(e)(a,0+Math.abs(n))}}T.type="lowpass",m.connect(M),y.connect(w).connect(f.detune),w.connect(p.detune),f.connect(x).connect(M),A.connect(v).connect(M),M.connect(b).connect(T).connect(e.destination),T.connect(A),S(M.gain,n),S(f.frequency,o),S(x.gain,a),S(m.gain,i),S(p.playbackRate,r),S(y.frequency,c),S(w.gain,s),S(T.frequency,l),S(T.Q,u),S(v.delayTime,h),S(A.gain,d),f.start(0),y.start(0)}(t,...e)},e=>{t.b=e},e=>{}),t}document.body.style="background:#111;";const V=new AudioContext;let q;q={nxt:[.1],start:[2,[1,2,0],,[0],,[.01,-1,4],,,,,[.1],[1,1,.5]],checkl:[.1,[1.3],[200,.05,800,.1,600]],mssn:[.5,[1.5],[1,400,.3,200],[1,0,.01,4,.04],[1,.01,0],,[1,1,1e3],[200],[5e3,-.5,100,1,300],[10,.5,1,1,20],[.1,1,.05,1.5,5],[.8,1,.9]],slw:[1,[0,.05,.5,.3,1,.2,0],[250,.2,520],[0,.01,.4,2,.01,3,1],[0],[1,.01,5,.1,.2,.5,0],[1],[0],[1e3,-.35,2e3,.5,800,.45,2e3,4,4e3],[1,.5,5,1,0],[1,.5,.25,.25,.75,.1,.1,1,0],[1,.5,.25,1,.3]],sll:[.1,[1],,[0,.001,1,.015,1,.02,0],[0,.001,3,.015,3,.02,0],[1,.5,.9],[100],[1e3,.05,100,.5,1e3],[1e3,.5,.1],[10],[.002,.5,.2],[.9,.5,1]],l2:[.5,,,[1],[0],,[100],[1e3,.5,100],,,,]};const N=function(e,t){const n=B(e),o=Object.fromEntries(Object.entries(t).map(([e,t])=>[e,j(...t)]).map(([t,o])=>[t,()=>{W(e,o.b,n,e.currentTime)}]));return{globalGain:n,players:o}}(V,q),H=N.players,J=function(e){const t=B(e),n=function(){const n=e.createOscillator(),o=e.createGain(),a=e.createBufferSource(),i=e.createGain();return{build:function(){const r=e.currentTime,c=P(e,1);return n.frequency.value=0,o.gain.value=0,a.playbackRate.value=1,a.buffer=c,a.loop=!0,a.loopEnd=c.length,i.gain.value=0,n.connect(o).connect(i).connect(t),a.connect(i.gain),n.start(r+.1),a.start(r+.1),e},gain:o,osc:n,osc01:a}}();n.build();const o=function(){const n=e.createBufferSource(),o=e.createGain(),a=e.createBiquadFilter();return{build:function(){const i=e.currentTime,r=F(e,2);n.playbackRate.value=1,n.buffer=r,n.loop=!0,n.loopEnd=r.length,a.type="bandpass",a.frequency.value=300,a.Q.value=.1,o.gain.value=1,a.frequency.value,n.connect(a).connect(o).connect(t),n.start(i+.1)},gain:o,biquad:a}}();return o.build(),{update:function(a){const i=e.currentTime+1/32;if(void 0!==a.wallDist){const e=Math.pow(a.wallDist,3);n.gain.gain.linearRampToValueAtTime(.2,i),n.osc.frequency.linearRampToValueAtTime(440+20*e,i),n.osc01.playbackRate.linearRampToValueAtTime(1+10*e,i)}else n.gain.gain.linearRampToValueAtTime(0,i),n.osc01.playbackRate.linearRampToValueAtTime(1,i);a.hasCollision?(o.gain.gain.linearRampToValueAtTime(1.75,i),o.biquad.frequency.linearRampToValueAtTime(300,i)):(o.gain.gain.linearRampToValueAtTime(0,i),o.biquad.frequency.linearRampToValueAtTime(0,i)),a.gain?t.gain.linearRampToValueAtTime(a.gain,i):t.gain.linearRampToValueAtTime(0,i)},globalGain:t}}(V),U=function(e){let t,n=0;e.onstatechange=()=>{"running"===e.state&&setInterval(()=>{const a=e.currentTime;(!t||e.currentTime>t-1)&&(t=function(t){const a=n%s.length,r=s[a],l=[1.4,1.1,.3,.97,1.6,.7],u=l.reduce((e,t)=>e+t,0),h=1.5,g=l.map(e=>h*e/u),m=function(t,n,o){const a=function(e,t,{size:n,nearestBins:o}){const a=new Float32Array(n),i=new Float32Array(n);return t.forEach(e=>{const[t]=o(e);a[t.i]=.5}),e.createPeriodicWave(a,i,{disableNormalization:!0})}(e,t,c),i=e.createOscillator(),r=E(i),s=I(r),l=R(r),u=D(r),h=e.createGain(),d=S(h);i.setPeriodicWave(a);const g={values:[20,22],durations:[.5,1.5,.3]},m={values:[1,.4].map(e=>e*n),durations:[w(16),w(20),2,.5]},p=e.createOscillator();I(E(p))(5);const y=e.createGain(),v=function(e,{values:t,durations:n},o){const a=b(n,o),i=R(e),r=D(e);return a[0]===a[1]?i(t[0],a[1]):(i(1,a[0]),r(t[0],a[1])),r(t[1],a[2]),a[2]===a[3]||r(1,a[3]),a[3]}(S(y),g,o);y.connect(k(i)),p.connect(y),p.start(o),p.stop(v),i.connect(h).connect(f.input),s(c.f0);const x=C(d,m,o);return l(c.f0,o),u(1.02*c.f0,x),i.start(o),i.stop(x),o+=1*(x-o)}(r,g[0],t),p=m-t;a>3&&function(e,t,n,a){const r=e[0]%12,c=[41,55],s=o.filter(e=>r===e%12).filter(e=>e>=c[0]&&e<=c[1]);if(0===s.length)return;1===s.length&&s.push(s[0]-1);M(s[0]);const l={values:[1,.8].map(e=>e*n),durations:[i(100),i(100),i(4e3),i(500)]};d.forEach((e,n)=>{if(e){const e=a+t*n/d.length,o=(C(oe,l,e),M(s[n%s.length]));te(o,e)}})}(r,p,g[1],t);a>7&&function(e,t,n,o){let a=[2,0,1,0,1,0,1,0,2,0,1,0,1,0,1,1];$(1),X(0);const r={values:[1,.8].map(e=>e*n),durations:[i(20),i(500),i(3e3),i(500)]};let c,s=t/a.length;a.forEach((t,n)=>{const a=o+n*s;1===t&&(c=C(K,r,a),z(4*M(e[0]),a),_(M(e[0])/4,c))})}(r,p,g[3],t);a>12&&function(e,t,n,o){const a=[1,1,1,0,1,0,1,0],r=t/a.length;let c;a.forEach((e,t)=>{if(e){let e=o+t*r;c=e+Math.min(r-i(10),.5),j(100,e),V(0,c),N(0,e),H(n,e+i(100)),H(0,c)}})}(0,p,g[4],t);a>16&&function(e,t,n,o){const a=2*d.length+Math.floor(3*Math.random()),i=e.flatMap(e=>[e,e+3,e-3,e+1,e-1]),r=[];for(let e=0;e<a;e++){const e=i[Math.floor(Math.random()*i.length)];r.push(e)}const c=t/r.length;let s;x(M(r[0]),o),F(0,o),r.forEach((e,a)=>{const i=M(e);let r=o+a*c;s=r+c;const l=r+.01*t,u=r+.99*t;v(i,l),v(i,u),L(0,r),L(n,(r+l)/2),L(n,(s+u)/2),L(0,s)}),F(0,o+t+1)}(r,p,g[5],t);return n++,m}(t||a))},500)};const o=new Array(128).fill(0).map((e,t)=>t),a=O(e,1),i=(r=e.sampleRate,function(e){return e/r});var r;const c=function(e,t){const n=new Array(e);for(let o=0;o<e;o++){const e=o*t,a=A(e);n[o]={f:e,k:a,i:o}}const o={};return{size:e,f0:t,bins:n,nearestBins:function(e){return void 0===o[e]&&(o[e]=[...n].sort((t,n)=>{const o=t.k,a=n.k;return Math.abs(o-e)-Math.abs(a-e)})),o[e]}}}(256,7.25);let s=[];const l=[60,63,67,72,75,79],u=[60,64,67,70],h=[0,1,0,1,6,3,0,-3,-6];for(let e=0;e<600;e++){for(let e=0;e<96;e++)h.forEach(t=>{s.push(l.map(n=>n+t+7*e%12))}),8===e&&h.forEach(t=>{s.push(u.map(n=>n+t+7*e%12))});h[Math.floor(Math.random()*h.length)]=Math.floor(12*Math.random()-2)}const d=[1,1,0,1,1,1,0,1],f=function(e,t){const n=[];for(let o=0;o<t.length;o++){const a=e.createGain(),i=e.createDelay();a.gain.value=t[o][1],i.delayTime.value=t[o][0],a.connect(i),o>0&&n[n.length-1].connect(a),n.push(a,i)}const o=n[0],a=n[n.length-1];return a.connect(o),{input:o,output:a}}(e,[[.3,.6]]),g=e.createGain();f.output.connect(g);const m=e.createOscillator(),p=e.createGain(),y=E(m),v=D(y),x=R(y),T=S(p),L=D(T),F=R(T);m.start(0),m.connect(p),p.connect(f.input),F(0,0);const P=e.createOscillator(),W=e.createGain(),B=E(P),j=R(B),V=D(B),q=S(W),N=R(q),H=D(q);P.start(0),P.connect(W).connect(g),N(0,0);const J=e.createBufferSource(),U=e.createBiquadFilter(),Z=e.createGain(),K=S(Z),X=I(K),Q=G(U),$=I(Q),Y=E(U),z=R(Y),_=D(Y);J.buffer=a,J.loop=!0,J.loopEnd=a.duration,U.type="bandpass",X(0),J.connect(Z).connect(U).connect(g),J.start();const ee=e.createOscillator(),te=R(E(ee)),ne=e.createGain(),oe=S(ne);return ee.type="triangle",ee.connect(ne).connect(g),te(0,0),ee.start(0),{globalGain:g,ac:e}}(V),Z=V.createBiquadFilter();Z.type="lowpass",Z.frequency.value=2500,Z.connect(V.destination),N.globalGain.connect(Z),N.globalGain.gain.value=.6,J.globalGain.connect(Z),J.globalGain.gain.value=1,U.globalGain.connect(Z),U.globalGain.gain.value=.9;const K={width:256,height:Math.floor(144)};function X(e,t,n,o=1){return`rgba(${Math.floor(256*e)},${Math.floor(256*t)},${Math.floor(256*n)},${o})`}function Q(e,t,n){return`hsl(${360*e},${100*t}%,${100*n}%)`}function $(e,t,n){const{ij2idx:o,map:a,outij:i}=e,r=Math.round(t.x),c=Math.round(t.y);if(!i(r,c)){const e=a[o(r,c)];return n.includes(e)}}const Y=function(e,t){const n=new Uint8Array(e*t);function o(t,o,a){let i=t+o*e;for(let e=0;e<a.length;e++)n[i+e]=a.charCodeAt(e)}function a(t,n){o(Math.max(0,Math.floor((e-n.length)/2)),t,n)}return{data:n,print:o,printCenter:a,cls:function(e){for(let e=0;e<n.length;e++)n[e]=0},width:e,height:t,printParagraphs:function(t,n,o=2){var i,r;return(i=n.split("\n").map(e=>" ".repeat(o)+e).join("\n"),r=e,i.replace(new RegExp(`(?![^\\n]{1,${r}}$)([^\\n]{1,${r}})\\s`,"g"),"$1\n")).split("\n").forEach((e,n)=>{a(t,e),t++}),t}}}(30,16),z=function(){const e=["ArrowLeft","ArrowDown","ArrowRight","ArrowUp"],t=[],n=[],o=o=>({key:a,repeat:i,timeStamp:r})=>{if(!i){o&&(n[0]=1);const i=e.findIndex(e=>e==a);i>=0&&t.push([o,i,r])}};window.addEventListener("keydown",o(1)),window.addEventListener("keyup",o(0));const a=[["ArrowLeft","ArrowRight"],["ArrowDown","ArrowUp"],["+","-"]],i=[[0,0],[0,0],[0,0]],r=e=>({key:t})=>{a.forEach((n,o)=>{n.forEach((n,a)=>{n===t&&(i[o][a]=e?1:0)})})};return window.addEventListener("keydown",r(1)),window.addEventListener("keyup",r(0)),{keyStrokes:t,anyKeyStroke:n,resetKeyStrokes:function(){t.length=0,n.length=0},axesCtrlState:i}}(),_=function(){const e={name:"I",T:0,t:0},t=[];function n(...t){Object.assign(e,...t)}let o=0,a=0;const i=parseInt(new URL(document.URL).searchParams.get("level")),r=parseInt(new URL(document.URL).searchParams.get("sublevel"));isNaN(i)||isNaN(r)||(console.log("setting level to ",i),console.log("setting sublevel to ",r),o=i,a=r);const c={I:{start:e=>n({name:"I0"})},I0:{">":()=>{s(()=>l("next"),4e3)},next:()=>{n({name:"I1"}),H.nxt()}},I1:{">":()=>{s(()=>l("story"),1e4)},next:()=>{H.start(),n({name:"I2"})},story:()=>{n({name:"I1S"})}},I1S:{">":()=>{s(()=>l("next"),1e4)},next:()=>{H.nxt(),n({name:"I1"})}},I2:{next:()=>{H.nxt(),n({name:"I3",level:o,sublevel:a,L:3,lives:3,energy:1,nlevels:h.length})}},I3:{next:()=>{H.mssn(),n({name:"M1"})}},M1:{">":()=>{n({nsublevels:h[e.level].subs.length})},next:()=>{n({name:"S1"})}},S1:{">":()=>{H.mssn(),n({choices:d(e.level,e.sublevel),energy:1})},next:()=>{n({name:"S2"})}},S2:{">":()=>{H.nxt(),s(()=>l("next"),4e3)},next:()=>{n({name:"S3"}),H.checkl()}},S3:{checkLine:e=>{H.checkl()},damage:t=>{const o=e.energy-t;o>0?n({energy:o}):l("sublevel-lose")},"sublevel-win":e=>{n({name:"W1"}),H.slw()},"sublevel-lose":t=>{H.sll(),n({name:"L1",lives:e.lives-1})}},W1:{next:()=>{const t=e.sublevel+1;t<e.nsublevels?n({sublevel:t,name:"S1"}):n({sublevel:t,name:"W2"})}},W2:{next:()=>{const t=e.level+1;if(t<e.nlevels){const o=Math.min(8,e.lives+1);n({sublevel:0,level:t,lives:o,L:Math.max(e.L,o),name:"M1"})}else n({level:t,name:"W3"})}},W3:{">":e=>{H.slw()}},L1:{">":e=>{},next:t=>{n(e.lives>0?{name:"S1"}:{name:"L2"})}},L2:{next:e=>n({name:"I0"})}};function s(n,o){const a=e.T,i=a+o,r=t.findIndex(e=>e.end>i),c={start:a,end:i,delay:o,f:n};t.splice(r>0?r:0,0,c)}function l(n,o){t.length=0;const a=e.name;try{(0,c[a][n])(o)}catch(e){}if(a!==e.name){e.t=e.T;const t=c[e.name][">"];t&&t()}}return{state:e,event:l,checkTimeouts:function(n){e.T=n;const o=t[0];if(o){return n>=o.end&&o.f(),g((o.end-n)/o.delay,0,1)}}}}(),ee=function(){const e=document.createElement("canvas");e.width=K.width,e.height=K.height,e.setAttribute("name","MONMON"),e.style="\n padding: 0;\n margin: auto;\n display: block;\n width: 100%;\n height: auto;\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n// border-top : 1px solid white;\n// border-bottom : 1px solid white;\n",document.body.appendChild(e);const t=e.getContext("2d"),n=function(){let e;const t={a:1};return{alter:function(n,o=t.a){const{width:a,height:i}=n.canvas;if(1===o)return;const r=n.getImageData(0,0,a,i);if(e){const t=e.data,a=r.data;for(let e=0;e<t.length;e+=4)a[e]=f(t[e],a[e],o),a[e+1]=f(t[e+1],a[e+1],o),a[e+2]=f(t[e+2],a[e+2],o),a[e+3]=t[e+3];n.putImageData(r,0,0)}e=r},o:t}}(),o=function(e,t){const{fontInfo:n}=t,{dim:o,codeIndex:a}=n,{width:i,height:r}=e,c=document.createElement("canvas");c.width=e.width*o,c.height=e.height*o;const s=c.getContext("2d");return{draw:function(){const n=t.getImageData();s.clearRect(0,0,i*o,r*o);const c=e.data;for(let e=0;e<i;e++)for(let t=0;t<r;t++){const r=c[e+t*i],l=o*e,u=o*t,h=a[r];n&&h?s.putImageData(n,Math.floor(l-h.x),Math.floor(u-h.y),h.x,h.y,o,o):(s.fillStyle="rgba(0,0,0,0)",s.fillRect(l+1,u+1,o-2,o-2))}},textScreen:e,canvas:c}}(Y,x),a={center:{x:0,y:0},scale:8,nominalScale:8},i=e.width/2,r=e.height/2;return{draw:function({center:c,scale:s},l,u,h,d,f,m,p){function y(e,t,n,o,a){return a[0]=(e-n/2-c.x)*s+i,a[1]=(t-o/2-c.y)*s+r,a[2]=n*s,a[3]=o*s,a}t.fillStyle="rgba(0,0,0,1)",t.fillRect(0,0,e.width,e.height),l&&l.vis&&function(){const{map:e,width:n,height:o,ij2idx:a,outij:u}=l,h=c.x+.5,d=c.y+.5,f=g(Math.floor(h-i/s),0,n-1),m=g(Math.ceil(h+i/s),0,n-1),y=g(Math.floor(d-r/s),0,o-1),v=g(Math.ceil(d+r/s),0,o-1);for(let n=f;n<m;n++)for(let o=y;o<v;o++){let c;if(u(n,o))c=[1,0,0];else{const t=e[a(n,o)];c=p[t]||[1,0,0]}c=[...c];const l=Q(...c),f=Math.floor((n-h)*s+i),g=Math.floor((o-d)*s+r);t.fillStyle=l,t.fillRect(f,g,s,s)}}(),o.vis&&o.draw();const v=Math.floor((e.width-o.canvas.width)/2),x=Math.floor((e.height-o.canvas.height)/2);o.vis&&t.drawImage(o.canvas,v,x),u.vis&&function(e,{center:t,scale:n}){let o;o=u.hasCollision?[u.energy/2,.2*Math.random(),.05*Math.random()]:[Math.pow(u.energy,.25),0,0],e.fillStyle=X(...o),e.fillRect(...y(u.position.x,u.position.y,1,1,[]))}(t,a),h.els.forEach((e,n)=>{e.vis&&function(e,{center:t,scale:n},{color:o,position:a,dim:i},r){e.fillStyle=X(...o),e.fillRect(...y(a.x,a.y,i,i,[]))}(t,a,e)}),d.vis&&(t.fillStyle=X(1,1,1,.25),t.fillRect(0,e.height-10,e.width*d.remain,e.height)),n.alter(t),f.vis&&function(){let{l:e,L:n}=f,o=2;function a(){t.fillRect(o,2,10,10),o+=12}t.fillStyle=X(0,0,0,.5),t.fillRect(0,0,12*n+2,14),t.fillStyle=X(1,0,0,1);for(let t=1;t<=e;t++)a();t.fillStyle=X(.2,.2,.2,1);for(let t=e+1;t<=n;t++)a()}()},camera:a,feedbackBuffer:n,textMode:o}}(),te={vis:!0,position:o(0,0),lastpos:o(0,0)},ne=function(){const e=[];for(let t=0;t<25;t++)e[t]={dim:.25,vis:!0,position:{x:10,y:10},color:[1,1,1,1]};return{idx:0,els:e}}(),oe={vis:!0},ae={vis:!0,l:5,L:5};!function(e){let t,n=0;requestAnimationFrame((function o(a){requestAnimationFrame(o),void 0===t&&(t=a);const i=Math.min(a-t,80);n+=i,e(i,n),t=a}))}((e,t)=>{const n=["S2","S3","W1","W2","L1"];function r(){return _.state.name}function c(e){return _.state.name===e}function s(...e){return e.flat().includes(r())}c("S2")&&i(_.state.choices.startPosition,te.position);const u=ee.camera,d=_.state.choices,m=_.checkTimeouts(t);oe.remain=m,oe.vis=void 0!==m&&s(["G1","S1","S2","L1"]),z.anyKeyStroke.length;const p=t-_.state.t;s("S2","S3")||p>1e3&&(z.anyKeyStroke.length&&_.event("next"),Y.print(15,14,"any key to skip"));const[[y,v],[x,w],[A,M]]=z.axesCtrlState;z.resetKeyStrokes();let b,T=!1,S=0,E=void 0;if(s(["S3","W1"])){const{level:t,sublevel:n,nsublevels:o}=_.state,r=h[t].subs[n].spd||.5,l=(1-r)*160+r*15;let u,f;c("S3")?(u=1,f=-1*w+x):(u=2,f=0),b=function(e,t,n,o,r,c){const s=e.position,l=a(s);l.y+=r/1e6;let u=!1,h=0;for(let e=3;e>=1&&(1&e&&(l.x+=n*r/c),2&e&&(l.y+=o*r/c),$(t,l,["*"]));e--)u=!0,h=e,i(s,l);return{nextPosition:l,hasCollision:u,collisionType:h,dx:n,dy:o}}(te,d,u,f,e,l);const{nextPosition:g,hasCollision:m,collisionType:p}=b;if(i(te.position,te.lastpos),i(g,te.position),s(["S3"])&&($(d,g,"G")&&_.event("sublevel-win"),m)){T=!0;const t=e/1500*(2!==p?5:1);S=t,_.event("damage",t)}}if(c("S3")){const e=_.state.choices.choices;let t=-1;for(let n=0;n<e.length;n++){const o=e[n].x;if(te.lastpos.x<o&&o<=te.position.x){t=n;break}}-1!==t&&_.event("checkLine",t,e.length-2);const n=60,o=function(e,t,n){const{ij2idx:o,map:a}=_.state.choices,i=Math.round(e.x),r=Math.round(e.y);for(let e=0;e<t;e++)if(n.includes(a[o(i+e,r)]))return e}(te.position,n,["*"]);if(void 0!==o){E=g((n-o-1)/(n-2),0,1)}}u.scale*=1+(-1*A+M)/10,u.scale=g(u.scale,4,32),d&&(d.vis=s(n)),te.vis=s(["S2","S3"]),te.energy=_.state.energy,te.hasCollision=T,ne.hasCollision=T;{const e=te.position;!function(e,t,n,a,r,c){if("S3"===c){const i=o();for(let o=0;o<4;o++){e.idx=(e.idx+1)%e.els.length;const o=e.els[e.idx];if(o.color=n?[.5+Math.random()/2,0,0]:[r,Math.random()*r,Math.random()*r],n){const{dx:e,dy:n}=a,r=2*Math.PI*Math.random(),c=.5+1*Math.pow(Math.random(),4);i.x=t.x+e/2+Math.cos(r)*c,i.y=t.y+n/2+Math.sin(r)*c,l(o.position,i,.9,o.position)}else{const e=Math.PI*(10/12+1/3*Math.random()),n=.5+2.5*Math.pow(Math.random(),4);i.x=t.x+Math.cos(e)*n,i.y=t.y+Math.sin(e)*n,l(o.position,i,.8,o.position)}}}else if("S2"===c){const n=o();for(let o=0;o<e.els.length;o++){const a=e.els[o];i(t,n),l(a.position,n,.3,a.position)}}else{const n=o();for(let o=0;o<e.els.length;o++){i(t,n);const a=e.els[o],r=Math.cos(o/10+Date.now()/1e3)*(6+Math.cos(Date.now()/1e3));n.x+=Math.cos(o+Date.now()/1e3)*r,n.y+=Math.sin(o+Date.now()/1e3)*r,["L1","L2"].includes(c)?a.color=[.5+Math.random()/2,f(Math.random()/4,a.color[1],.5),f(Math.random()/4,a.color[2],.5)]:a.color=[Math.random(),Math.cos(o/10),o],l(a.position,n,.1,a.position)}}}(ne,e,T,b,_.state.energy,r())}void 0!==_.state.lives&&void 0!==_.state.lives&&(ae.l=_.state.lives,ae.L=_.state.L),ae.vis=["S1","S2","S3","W1","W2","L1"].includes(r()),i(te.position,u.center),J.update({energy:_.state.energy,hasCollision:T,damage:S,wallDist:E,gain:1});const G=Y.printCenter;function k(e,t,n,o){const{level:a,sublevel:i,nsublevels:r}=_.state,c=h[a],s=c.subs[i];if(G(1,"Mission #"+(a+1)),G(3,`"${c.name}"`),o||(G(5,`Hop #${i+1}/${r}`),G(7,`"${s.name}"`)),e&&(G(9,"you follow the route:"),G(11,_.state.choices.directions.join("."))),t&&(G(9,"you did not make it!"),G(11,"* hop failed *")),n&&(G(9,"* hop successful *"),G(11,"you made it!")),o){const e=_.state.level,t=h[e].cleared;G(8,"* mission cleared! *"),Y.printParagraphs(12,t+"\n",0)}for(let e=0;e<a+1;e++);}if(ee.textMode.vis=!0,Y.cls(),["I2","I1S"].includes(r())){G(1,"The Odyssey Begins...");const e="So many years have passed since your days as a newborn electron, freely roaming in some metallic conductor...\n\nThe time has come for you to start your wondeful journey and fulfill your duty for the almighty gods of electrons to be pleased.";Y.printParagraphs(3,e,0)}else if(["I3"].includes(r())){G(1,"The Odyssey Begins...");const e="Now your destiny will always be to Follow the Correct Route In Pipes and lead the Sacred Data to its Destination. Every electron knows what happens when you fail to Follow the Correct Route...\n\n404 : Electronic DEATH!\n\nSo ALWAYS remember the ordered up and down Numbers of the Correct Route!\n\nGOOD LUCK!";Y.printParagraphs(3,e,0)}else["M1"].includes(r())?k():["G1"].includes(r())?(G(6,"level presentation"),writeMission(Y,_.state.level)):["G2"].includes(r())?G(6,"sublevel"+_.state.sublevel,!0):["I1"].includes(r())?G(7,"electron life simulator"):["I0"].includes(r())?G(6,"lespin presents"):["L1"].includes(r())?k(!1,!0):["L2"].includes(r())?G(7,"404"):["W1"].includes(r())?k(!1,!1,!0):["W2"].includes(r())?k(!1,!1,!1,!0):["W3"].includes(r())?(G(5,"You Won It All!"),G(7,"Electron Gods are pleased"),G(8,"to welcome you !"),G(10,"Thanks for playing!")):["S1"].includes(r())?k(!0):["S2"].includes(r())&&G(9,"ready?");const{feedbackBuffer:D}=ee;if(s("S2","S3")){const e=D.o.a;D.o.a=g(e+1/60/3,0,1)}else D.o.a=.05;let R;if(s(n)){let e=h[_.state.level].hs;e||(e=[0,1],console.error("no color for level",_.state.level)),R=function(e=0,t=.5,n={}){return[["O",15/16,.6,.5],["G",1/16,.6,.5],["*",2/6,.4,.25],["M",6/16,.5,.5],["S",10/6,.5,.5],["B",7/6,.5,.5]].forEach(([o,a,i,r])=>{n[o]=[(a+e)%1,.5*i*t,r]}),n}(...e)}ee.draw(u,d,te,ne,oe,ae,m,R)});_.event("start")}]);
//# sourceMappingURL=main.js.map