transport/main.min.js
2018-04-16 17:53:47 -04:00

2 lines
7.1 KiB
JavaScript

!function(t){function o(o){for(var i,r,a=o[0],l=o[1],c=o[2],h=0,p=[];h<a.length;h++)r=a[h],e[r]&&p.push(e[r][0]),e[r]=0;for(i in l)Object.prototype.hasOwnProperty.call(l,i)&&(t[i]=l[i]);for(d&&d(o);p.length;)p.shift()();return s.push.apply(s,c||[]),n()}function n(){for(var t,o=0;o<s.length;o++){for(var n=s[o],i=!0,a=1;a<n.length;a++){var l=n[a];0!==e[l]&&(i=!1)}i&&(s.splice(o--,1),t=r(r.s=n[0]))}return t}var i={},e={1:0},s=[];function r(o){if(i[o])return i[o].exports;var n=i[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}r.m=t,r.c=i,r.d=function(t,o,n){r.o(t,o)||Object.defineProperty(t,o,{configurable:!1,enumerable:!0,get:n})},r.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},r.n=function(t){var o=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(o,"a",o),o},r.o=function(t,o){return Object.prototype.hasOwnProperty.call(t,o)},r.p="";var a=window.webpackJsonp=window.webpackJsonp||[],l=a.push.bind(a);a.push=o,a=a.slice();for(var c=0;c<a.length;c++)o(a[c]);var d=l;s.push([110,0]),n()}({107:function(t,o,n){t.exports=n.p+"726c2296b05703758a8f65fd9097f683.png"},110:function(t,o,n){"use strict";n.r(o);var i=n(109),e=n(8),s=n(108),r=n(12);class a{constructor(t,o){this.station=t,this.line=o}}const l=(t,o)=>Math.floor(Math.random()*(o-(t+1)))+t,c=(t,o)=>{const n=o.reduce((t,o)=>t+o,0),i=l(0,n);let e=0;for(let n=0;n<o.length;n+=1)if(i<(e+=o[n]))return t[n]},d=()=>new e.Point(l(0,window.innerWidth),l(0,window.innerHeight)),h=(t,o)=>Math.abs(t.x-o.x)<1&&Math.abs(t.y-o.y)<1,p=(t,o)=>{const n=t.x-o.x,i=t.y-o.y;return Math.sqrt(n*n+i*i)},u=(t,o,n,i,e)=>(t-o)*(e-i)/(n-o)+i;var f,w;(w=f||(f={}))[w.North=0]="North",w[w.Northeast=1]="Northeast",w[w.East=2]="East",w[w.Southeast=3]="Southeast",w[w.South=4]="South",w[w.Southwest=5]="Southwest",w[w.West=6]="West",w[w.Northwest=7]="Northwest";const g=(t,o)=>{const n=((t,o)=>180+((t,o)=>Math.atan2(-(o.x-t.x),o.y-t.y))(t,o)*(180/Math.PI))(t,o);let i=null;if(n>=337.5||n<22.5)i=f.North;else if(n>=22.5&&n<67.5)i=f.Northeast;else if(n>=67.5&&n<112.5)i=f.East;else if(n>=112.5&&n<157.5)i=f.Southeast;else if(n>=157.5&&n<202.5)i=f.South;else if(n>=202.5&&n<247.5)i=f.Southwest;else if(n>=247.5&&n<292.5)i=f.West;else{if(!(n>=292.5&&n<337.5))throw Error("Angle between points is not a valid degree");i=f.Northwest}return i};let x=0;class y{static largestStation(t){let o=null;for(const n of t)(null===o||n.population>o.population)&&(o=n);return o}static stationsWithinRadius(t,o,n){return t.filter(t=>p(o,t.location)<=n)}static stationsInDirection(t,o,n){return t.filter(t=>g(o,t.location)===n)}static closestStation(t,o){return t.reduce((t,n)=>p(o,t.location)<p(o,n.location)?t:n)}static randomCloseLargeStation(t,o,n){const i=y.stationsWithinRadius(t,o,n),e=i.map(t=>t.population);return c(i,e)}static isPointDistant(t,o,n){for(const i of o)if(p(t,i.location)<n)return!1;return!0}static randomDistantPoint(t,o){let n=100;for(;n>0;){const i=d();if(y.isPointDistant(i,t,o))return i;n-=1}return null}constructor(t,o,n,i){this.location=t,this.population=o,this.color=n,this.connections=i||[],x+=1,this.id=x,this.label=new PIXI.Text(`${this.id}`,{fill:"#FFA500",fontFamily:"monospace",fontSize:"12px"})}}const m=Math.floor(Math.sqrt(Math.pow(window.innerWidth,2)+Math.pow(window.innerHeight,2))/8);class b{constructor(t,o){this.name=t,this.color=o}connectStations(t,o,n,i){n.push(t);const e=o.filter(o=>o!==t),s=y.stationsWithinRadius(e,t.location,m);for(let o=0;o<i&&!(s.length<1);o+=1){const o=y.largestStation(s);t.connections.push(new a(o,this)),s.splice(s.indexOf(o),1)}for(const e of t.connections)-1===n.indexOf(e.station)&&this.connectStations(e.station,o,n,i)}}let S=0;class v{constructor(t,o,n,i,e,s){this.location=t,this.speed=o,this.origin=i,this.destination=e,this.passengers=n,this.color=s,this.sprite=new PIXI.Sprite(PIXI.loader.resources.nodeImg.texture),S+=1,this.id=S,this.label=new PIXI.Text(`${this.id}`,{fill:"#AEAEAE",fontFamily:"monospace",fontSize:"12px"})}boardPassengers(){this.location,this.origin.location}}var M=n(107);n(239),e.loader.add("nodeImg",M).load(()=>{const t=new e.Application({antialias:!0,height:window.innerHeight,width:window.innerWidth}),o=new i({screenHeight:window.innerHeight,screenWidth:window.innerWidth,worldHeight:1e3,worldWidth:1e3}),n=new s;n.showPanel(0),document.body.appendChild(n.dom);const a=new e.ticker.Ticker,d=new e.Graphics,f=(t=>{const o=[];for(let t=0;t<30;t+=1)o.push(new y(y.randomDistantPoint(o,30),l(300,2e3),r.random()));return o})(),w=(((t,o)=>{const n=[];for(let t=0;t<4;t+=1){let i=r.random();for(;i.isDark();)i=r.random();const e=o.filter(t=>0===t.connections.length),s=y.largestStation(e),a=new b(`line-${t}`,r.random()),l=o.slice(0);a.connectStations(s,l,[],5),n.push(a)}})(0,f),((t,o)=>{const n=[],i=f.filter(t=>t.connections.length>0);for(let t=0;t<50;t+=1){const t=i[Math.floor(Math.random()*i.length)];n.push(new v(new e.Point(t.location.x,t.location.y),0,0,t,void 0,r("grey")))}return n})());a.stop(),a.add(t=>{n.begin(),((t,o)=>{for(const o of t){if(0===o.origin.connections.length)continue;if(void 0===o.destination){const t=o.origin.connections.map(t=>t.station),n=t.map(t=>t.population);o.destination=c(t,n);const i=l(0,Math.min(50-o.passengers,o.origin.population));0===o.passengers?o.color=o.origin.color:o.color=r.mix(o.color,o.origin.color,Math.round(i/o.passengers*100)),o.passengers+=i,o.origin.population-=i}if(h(o.location,o.destination.location)){o.speed=0,o.destination.color=r.mix(o.destination.color,o.origin.color,Math.round(o.passengers/o.destination.population*100));const t=l(0,o.passengers);o.destination.population+=t,o.passengers-=t,o.origin=o.destination,o.destination=void 0;continue}const t=p(o.location,o.destination.location);o.speed/.025>=t/o.speed-3&&.025!==o.speed?o.speed-=.025:o.speed<10&&(o.speed+=.025);const n=o.speed/t;o.location.x+=(o.destination.location.x-o.location.x)*n,o.location.y+=(o.destination.location.y-o.location.y)*n}})(w),d.clear(),d.lineStyle(1,16753920,1),((t,o)=>{for(const n of t){const t=n.population/150;o.beginFill(parseInt(n.color.toHex(),16),.5),o.drawCircle(n.location.x,n.location.y,t),o.endFill(),n.label.x=n.location.x+t+1,n.label.y=n.location.y+t+1}})(f,d),d.lineStyle(1,11447982,1),((t,o)=>{for(const o of t){const t=u(o.passengers,0,50,1,5)/100;o.sprite.x=o.location.x,o.sprite.y=o.location.y,o.sprite.scale.x=t,o.sprite.scale.y=t,o.sprite.tint=parseInt(o.color.toHex(),16),o.label.x=o.location.x+t+1,o.label.y=o.location.y+t+1}})(w),((t,o)=>{for(const n of t)for(const t of n.connections){let i=!1;for(const o of t.station.connections)o.station===n&&(i=!0);o.lineStyle(i?2:1,parseInt(t.line.color.toHex(),16),1),o.moveTo(n.location.x,n.location.y),o.lineTo(t.station.location.x,t.station.location.y)}})(f,d),n.end()}),a.start(),o.addChild(d);for(const t of w)o.addChild(t.sprite);for(const t of w)o.addChild(t.label);for(const t of f)o.addChild(t.label);document.body.appendChild(t.view),t.stage.addChild(o),o.drag().pinch().wheel().clampZoom({maxHeight:4e3,maxWidth:4e3,minHeight:100,minWidth:100}).decelerate(),window.addEventListener("resize",()=>{t.renderer.resize(window.innerWidth,window.innerHeight)})})},116:function(t,o){},239:function(t,o){}});
//# sourceMappingURL=main.min.js.map