var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.arrayIteratorImpl=function(n){var d=0;return function(){return d<n.length?{done:!1,value:n[d++]}:{done:!0}}};$jscomp.arrayIterator=function(n){return{next:$jscomp.arrayIteratorImpl(n)}};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1;$jscomp.ISOLATE_POLYFILLS=!1;$jscomp.FORCE_POLYFILL_PROMISE=!1;$jscomp.FORCE_POLYFILL_PROMISE_WHEN_NO_UNHANDLED_REJECTION=!1;
$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(n,d,e){if(n==Array.prototype||n==Object.prototype)return n;n[d]=e.value;return n};$jscomp.getGlobal=function(n){n=["object"==typeof globalThis&&globalThis,n,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var d=0;d<n.length;++d){var e=n[d];if(e&&e.Math==Math)return e}throw Error("Cannot find global object");};$jscomp.global=$jscomp.getGlobal(this);
$jscomp.IS_SYMBOL_NATIVE="function"===typeof Symbol&&"symbol"===typeof Symbol("x");$jscomp.TRUST_ES6_POLYFILLS=!$jscomp.ISOLATE_POLYFILLS||$jscomp.IS_SYMBOL_NATIVE;$jscomp.polyfills={};$jscomp.propertyToPolyfillSymbol={};$jscomp.POLYFILL_PREFIX="$jscp$";var $jscomp$lookupPolyfilledValue=function(n,d){var e=$jscomp.propertyToPolyfillSymbol[d];if(null==e)return n[d];e=n[e];return void 0!==e?e:n[d]};
$jscomp.polyfill=function(n,d,e,a){d&&($jscomp.ISOLATE_POLYFILLS?$jscomp.polyfillIsolated(n,d,e,a):$jscomp.polyfillUnisolated(n,d,e,a))};$jscomp.polyfillUnisolated=function(n,d,e,a){e=$jscomp.global;n=n.split(".");for(a=0;a<n.length-1;a++){var b=n[a];if(!(b in e))return;e=e[b]}n=n[n.length-1];a=e[n];d=d(a);d!=a&&null!=d&&$jscomp.defineProperty(e,n,{configurable:!0,writable:!0,value:d})};
$jscomp.polyfillIsolated=function(n,d,e,a){var b=n.split(".");n=1===b.length;a=b[0];a=!n&&a in $jscomp.polyfills?$jscomp.polyfills:$jscomp.global;for(var c=0;c<b.length-1;c++){var f=b[c];if(!(f in a))return;a=a[f]}b=b[b.length-1];e=$jscomp.IS_SYMBOL_NATIVE&&"es6"===e?a[b]:null;d=d(e);null!=d&&(n?$jscomp.defineProperty($jscomp.polyfills,b,{configurable:!0,writable:!0,value:d}):d!==e&&(void 0===$jscomp.propertyToPolyfillSymbol[b]&&(e=1E9*Math.random()>>>0,$jscomp.propertyToPolyfillSymbol[b]=$jscomp.IS_SYMBOL_NATIVE?
$jscomp.global.Symbol(b):$jscomp.POLYFILL_PREFIX+e+"$"+b),$jscomp.defineProperty(a,$jscomp.propertyToPolyfillSymbol[b],{configurable:!0,writable:!0,value:d})))};$jscomp.initSymbol=function(){};
$jscomp.polyfill("Symbol",function(n){if(n)return n;var d=function(c,f){this.$jscomp$symbol$id_=c;$jscomp.defineProperty(this,"description",{configurable:!0,writable:!0,value:f})};d.prototype.toString=function(){return this.$jscomp$symbol$id_};var e="jscomp_symbol_"+(1E9*Math.random()>>>0)+"_",a=0,b=function(c){if(this instanceof b)throw new TypeError("Symbol is not a constructor");return new d(e+(c||"")+"_"+a++,c)};return b},"es6","es3");
$jscomp.polyfill("Symbol.iterator",function(n){if(n)return n;n=Symbol("Symbol.iterator");for(var d="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),e=0;e<d.length;e++){var a=$jscomp.global[d[e]];"function"===typeof a&&"function"!=typeof a.prototype[n]&&$jscomp.defineProperty(a.prototype,n,{configurable:!0,writable:!0,value:function(){return $jscomp.iteratorPrototype($jscomp.arrayIteratorImpl(this))}})}return n},"es6",
"es3");$jscomp.iteratorPrototype=function(n){n={next:n};n[Symbol.iterator]=function(){return this};return n};function _typeof(n){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(d){return typeof d}:function(d){return d&&"function"==typeof Symbol&&d.constructor===Symbol&&d!==Symbol.prototype?"symbol":typeof d},_typeof(n)}
function _get(){_get="undefined"!==typeof Reflect&&Reflect.get?Reflect.get.bind():function(n,d,e){var a=_superPropBase(n,d);if(a)return a=Object.getOwnPropertyDescriptor(a,d),a.get?a.get.call(3>arguments.length?n:e):a.value};return _get.apply(this,arguments)}function _superPropBase(n,d){for(;!Object.prototype.hasOwnProperty.call(n,d)&&(n=_getPrototypeOf(n),null!==n););return n}
function _inherits(n,d){if("function"!==typeof d&&null!==d)throw new TypeError("Super expression must either be null or a function");n.prototype=Object.create(d&&d.prototype,{constructor:{value:n,writable:!0,configurable:!0}});Object.defineProperty(n,"prototype",{writable:!1});d&&_setPrototypeOf(n,d)}function _setPrototypeOf(n,d){_setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,a){e.__proto__=a;return e};return _setPrototypeOf(n,d)}
function _createSuper(n){var d=_isNativeReflectConstruct();return function(){var e=_getPrototypeOf(n);if(d){var a=_getPrototypeOf(this).constructor;e=Reflect.construct(e,arguments,a)}else e=e.apply(this,arguments);return _possibleConstructorReturn(this,e)}}function _possibleConstructorReturn(n,d){if(d&&("object"===_typeof(d)||"function"===typeof d))return d;if(void 0!==d)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(n)}
function _assertThisInitialized(n){if(void 0===n)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return n}function _isNativeReflectConstruct(){if("undefined"===typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"===typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(n){return!1}}
function _getPrototypeOf(n){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(d){return d.__proto__||Object.getPrototypeOf(d)};return _getPrototypeOf(n)}function _defineProperty(n,d,e){d in n?Object.defineProperty(n,d,{value:e,enumerable:!0,configurable:!0,writable:!0}):n[d]=e;return n}function _classCallCheck(n,d){if(!(n instanceof d))throw new TypeError("Cannot call a class as a function");}
function _defineProperties(n,d){for(var e=0;e<d.length;e++){var a=d[e];a.enumerable=a.enumerable||!1;a.configurable=!0;"value"in a&&(a.writable=!0);Object.defineProperty(n,a.key,a)}}function _createClass(n,d,e){d&&_defineProperties(n.prototype,d);e&&_defineProperties(n,e);Object.defineProperty(n,"prototype",{writable:!1});return n}
var Camera=function(){function n(d){var e=this;_classCallCheck(this,n);this._screenDiv=d;this._height=this._width=0;this._size=1E3;this._zoom=1;this._mouseMovementEnabled=this._leftButtonEnabled=!0;this._contextMenuDisableTime=-Infinity;this.camera=new THREE.OrthographicCamera(0,0,0,0,1,2);this.camera.position.z=1;this._grab=null;var a=this;d.addEventListener("pointerdown",function(b){a._mouseMovementEnabled&&(0==b.button&&a._leftButtonEnabled||1==b.button||2==b.button)&&(a._grab={pos:a.screenToWorld(b.clientX,
b.clientY),button:b.button},a._contextMenuDisableTime=(new Date).getTime())});window.addEventListener("contextmenu",function(b){a._mouseMovementEnabled&&(new Date).getTime()<a._contextMenuDisableTime+250&&b.preventDefault()});window.addEventListener("pointermove",function(b){a._mouseMovementEnabled&&null!=a._grab&&(b=a.screenToWorld(b.clientX,b.clientY),a.camera.position.x+=a._grab.pos.x-b.x,a.camera.position.y+=a._grab.pos.y-b.y,a._contextMenuDisableTime=(new Date).getTime())});window.addEventListener("pointerup",
function(b){a._mouseMovementEnabled&&null!=a._grab&&(0==b.button&&(a._leftButtonEnabled||0==a._grab.button)||1==b.button||2==b.button)&&(a._grab=null,a._contextMenuDisableTime=(new Date).getTime())});this._moveFast=this._moveLeft=this._moveDown=this._moveRight=this._moveUp=!1;window.addEventListener("keydown",function(b){81!=b.keyCode&&"KeyQ"!=b.code||null!=a._grab||(a.setZoom(a._zoom/1.2),b.preventDefault());69!=b.keyCode&&"KeyE"!=b.code||null!=a._grab||(a.setZoom(1.2*a._zoom),b.preventDefault());
if(87==b.keyCode||"KeyW"==b.code||38==b.keyCode||"ArrowUp"==b.code)e._moveUp=!0,b.preventDefault();if(68==b.keyCode||"KeyD"==b.code||39==b.keyCode||"ArrowRight"==b.code)e._moveRight=!0,b.preventDefault();if(83==b.keyCode||"KeyS"==b.code||40==b.keyCode||"ArrowDown"==b.code)e._moveDown=!0,b.preventDefault();if(65==b.keyCode||"KeyA"==b.code||37==b.keyCode||"ArrowLeft"==b.code)e._moveLeft=!0,b.preventDefault();if(65==b.keyCode||"KeyA"==b.code||37==b.keyCode||"ArrowLeft"==b.code)e._moveLeft=!0,b.preventDefault();
if(16==b.keyCode||"ShiftLeft"==b.code||"ShiftRight"==b.code)e._moveFast=!0,b.preventDefault()});window.addEventListener("keyup",function(b){if(87==b.keyCode||"KeyW"==b.code||38==b.keyCode||"ArrowUp"==b.code)e._moveUp=!1,b.preventDefault();if(68==b.keyCode||"KeyD"==b.code||39==b.keyCode||"ArrowRight"==b.code)e._moveRight=!1,b.preventDefault();if(83==b.keyCode||"KeyS"==b.code||40==b.keyCode||"ArrowDown"==b.code)e._moveDown=!1,b.preventDefault();if(65==b.keyCode||"KeyA"==b.code||37==b.keyCode||"ArrowLeft"==
b.code)e._moveLeft=!1,b.preventDefault();if(16==b.keyCode||"ShiftLeft"==b.code||"ShiftRight"==b.code)e._moveFast=!1,b.preventDefault()});d.addEventListener("wheel",function(b){var c=a.screenToWorld(b.clientX,b.clientY);0>b.deltaY?a.setZoom(1.2*a._zoom):0<b.deltaY&&a.setZoom(a._zoom/1.2);var f=a.screenToWorld(b.clientX,b.clientY);a.camera.position.x-=f.x-c.x;a.camera.position.y-=f.y-c.y;b.preventDefault()})}_createClass(n,[{key:"moveScreen",value:function(d,e){this.camera.position.x+=d/this._width*
this.aspect*this._size/this._zoom;this.camera.position.y+=e/this._height*this._size/this._zoom}},{key:"setPosition",value:function(d,e){this._grab=null;this.camera.position.x=d;this.camera.position.y=e}},{key:"disableLeftButton",value:function(){this._leftButtonEnabled=!1}},{key:"enableLeftButton",value:function(){this._leftButtonEnabled=!0}},{key:"disableMouseMovement",value:function(){this._mouseMovementEnabled=!1;this._grab=null}},{key:"enableMouseMovement",value:function(){this._mouseMovementEnabled=
!0}},{key:"screenToWorld",value:function(d,e){return{x:this.camera.position.x+(d-this._screenDiv.offsetLeft-this._width/2)/this._zoom/this._width*this._size*this.aspect,y:this.camera.position.y-(e-this._height/2)/this._zoom/this._height*this._size}}},{key:"reset",value:function(){this.setZoom(1);this.camera.position.set(0,0,1);this._grab=null}},{key:"setSize",value:function(d,e){this._width=d;this._height=e;this.camera.left=-this._size*this.aspect/2/this._zoom;this.camera.right=this._size*this.aspect/
2/this._zoom;this.camera.bottom=-this._size/2/this._zoom;this.camera.top=this._size/2/this._zoom;this.camera.updateProjectionMatrix()}},{key:"setZoom",value:function(d){this._zoom=d;this.setSize(this._width,this._height)}},{key:"aspect",get:function(){return this._width/this._height}},{key:"zoom",get:function(){return this._zoom}},{key:"size",get:function(){return this._size}},{key:"update",value:function(d){if(null==this._grab){var e=1200/this._zoom;this._moveFast&&(e*=2.5);(this._moveUp&&!this._moveDown||
this._moveDown&&!this._moveUp)&&(this._moveLeft&&!this._moveRight||this._moveRight&&!this._moveLeft)&&(e/=Math.SQRT2);this._moveUp&&(this.camera.position.y+=e*d);this._moveRight&&(this.camera.position.x+=e*d);this._moveDown&&(this.camera.position.y-=e*d);this._moveLeft&&(this.camera.position.x-=e*d)}}}]);return n}(),DialogManager=function(){function n(d){var e=this;_classCallCheck(this,n);this._body=d;this._overlay=null;window.addEventListener("keydown",function(a){27!=a.keyCode&&"Escape"!=a.code||
e.hide()})}_createClass(n,[{key:"showImportExportDialog",value:function(d,e,a,b,c){function f(){return new Promise(function(q,t){function w(){try{u.select(),document.execCommand("copy")?q():t()}catch(y){console.error(y),t()}}try{navigator.clipboard?navigator.clipboard.writeText(u.value).then(function(){q()},function(y){console.error(y);w()}):w()}catch(y){console.error(y),w()}})}var l=this;this.hide();this._overlay=document.createElement("div");this._overlay.className="dialog exporter";var m=null,
g=function(q){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:!1;null!=m&&(l._overlay.removeChild(m),m=null);m=document.createElement("div");m.className="message";var w=document.createElement("p");t&&(w.className="error");w.textContent=q;m.appendChild(w);l._overlay.appendChild(m)},k=document.createElement("div"),h=document.createElement("button");h.className="selected";h.textContent="Compressed";h.addEventListener("click",function(){u.value=d.currentScenario.getSaveString(!0);h.className=
"selected";p.className="";r.className=""});k.appendChild(h);var p=document.createElement("button");p.textContent="Plain";p.addEventListener("click",function(){u.value=d.currentScenario.getSaveString(!1);h.className="";p.className="selected";r.className=""});k.appendChild(p);var r=document.createElement("button");r.textContent="Hyperlink";r.addEventListener("click",function(){var q=d.currentScenario.getSaveString(!0);2E3<q.length?(u.value="",g("Scenario is too big for hyperlinking",!0)):u.value="https://www.kodub.com/apps/dustsim?load="+
q;h.className="";p.className="";r.className="selected"});k.appendChild(r);var u=document.createElement("textarea");u.value=d.currentScenario.getSaveString(!0);u.addEventListener("keydown",function(q){"Escape"!=q.key&&27!=q.keyCode&&q.stopPropagation()});var x=!0;u.addEventListener("focus",function(){u.select()});u.addEventListener("blur",function(){x=!0});u.addEventListener("click",function(){x&&(u.select(),x=!1)});k.appendChild(u);var v=document.createElement("button");v.textContent="Close";v.addEventListener("click",
function(){l.hide()});k.appendChild(v);v=document.createElement("button");v.textContent="Copy";v.addEventListener("click",function(){f().then(function(){g("Copied!",!1)})["catch"](function(){g("Error: Failed to copy",!0)})});k.appendChild(v);v=document.createElement("button");v.textContent="Load";v.addEventListener("click",function(){var q=u.value;q=q.replace(/\s/g,"");-1!=q.indexOf("load=")&&(q=q.substr(q.indexOf("load=")+5),-1!=q.indexOf("&")&&(q=q.substr(0,q.indexOf("&"))));var t=new Scenario;
t.setSaveString(q)?(a.reset(),d.setScenario(t),e.loadScenario(t,a,b,c),l.hide()):g("Error: Failed to load scenario",!0)});k.appendChild(v);this._overlay.appendChild(k);this._body.appendChild(this._overlay);h.focus();k.addEventListener("pointerdown",function(q){q.target==k&&(h.focus(),q.preventDefault())});this._overlay.addEventListener("focusout",function(){setTimeout(function(){k.contains(document.activeElement)||l.hide()},0)})}},{key:"hide",value:function(){null!=this._overlay&&(this._body.removeChild(this._overlay),
this._overlay=null)}}]);return n}(),Graphics=function(){function n(d,e){_classCallCheck(this,n);this._screenDiv=d;this.renderer=this._canvas=null;this._scene=new THREE.Scene;this._camera=e;this._scene.add(e.camera);this._particlesAndPolesScene=new THREE.Group;this._scene.add(this._particlesAndPolesScene);this._particleSystemMesh=this._particleSystem=null;this._particleMaterial=new THREE.RawShaderMaterial({defines:{COLOR_THEME:1,COLOR_VARIATION:!0,USE_IMAGE:!1,ROTATION_MODE:0},uniforms:{projectionModelViewMatrix:{value:null},
color:{value:null},colorSampler:{type:"t",value:null},sampler:{type:"t",value:null},imageSampler:{type:"t",value:null},particleSize:{value:null},alpha:{value:null}},vertexShader:"\n\t\t\t\tprecision highp float;\n\t\t\t\tprecision highp int;\n\t\t\t\tprecision highp sampler2D;\n\n\t\t\t\tattribute float position;\n\t\t\t\tattribute vec2 uv;\n\n\t\t\t\tuniform mat4 projectionModelViewMatrix;\n\n\t\t\t\tuniform vec3 color;\n\t\t\t\tuniform sampler2D sampler;\n\t\t\t\t#if COLOR_THEME == 3\n\t\t\t\t\tuniform sampler2D colorSampler;\n\t\t\t\t#endif\n\t\t\t\t#ifdef USE_IMAGE\n\t\t\t\t\tuniform float particleSize;\n\t\t\t\t#endif\n\n\t\t\t\tvarying vec3 fColor;\n\n\t\t\t\t#if ROTATION_MODE != 0\n\t\t\t\t\tvarying float rotation;\n\t\t\t\t#endif\n\n\t\t\t\tvec3 hsv2rgb(vec3 c)\n\t\t\t\t{\n\t\t\t\t\tvec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n\t\t\t\t\tvec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n\t\t\t\t\treturn c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\t\t\t\t\tvec4 data = texture2D(sampler, uv);\n\n\t\t\t\t\t#if COLOR_THEME == 0\n\t\t\t\t\t\tfColor = color;\n\t\t\t\t\t#elif COLOR_THEME == 1\n\t\t\t\t\t\tfloat velocity = length(data.zw);\n\t\t\t\t\t\tfColor = hsv2rgb(vec3(min(0.9, velocity / 800.0), 1.0, 1.0));\n\t\t\t\t\t#elif COLOR_THEME == 2\n\t\t\t\t\t\tfloat velocityDirection = atan(data.z, data.w);\n\t\t\t\t\t\tfColor = hsv2rgb(vec3(velocityDirection / 3.1415926538 / 2.0, 1.0, 1.0));\n\t\t\t\t\t#elif COLOR_THEME == 3\n\t\t\t\t\t\tfColor = texture2D(colorSampler, uv).rgb;\n\t\t\t\t\t#elif COLOR_THEME == 4\n\t\t\t\t\t\tfColor = hsv2rgb(vec3(position * 100.0, 1.0, 1.0));\n\t\t\t\t\t#endif\n\n\t\t\t\t\t#ifdef COLOR_VARIATION\n\t\t\t\t\t\tfColor *= position * 0.5 + 0.5;\n\t\t\t\t\t#endif\n\n\t\t\t\t\tgl_Position = projectionModelViewMatrix * vec4(data.xy, 0.0, 1.0);\n\n\t\t\t\t\t#ifdef USE_IMAGE\n\t\t\t\t\t\t#if ROTATION_MODE == 0\n\t\t\t\t\t\t\tgl_PointSize = particleSize;\n\t\t\t\t\t\t#elif ROTATION_MODE == 1 || ROTATION_MODE == 2\n\t\t\t\t\t\t\t#if ROTATION_MODE == 1\n\t\t\t\t\t\t\t\trotation = position * 3.1415926538 * 2.0;\n\t\t\t\t\t\t\t#else\n\t\t\t\t\t\t\t\trotation = atan(data.w, data.z);\n\t\t\t\t\t\t\t#endif\n\t\t\t\t\t\t\tgl_PointSize = ((abs(sin(rotation * 2.0)) * (sqrt(2.0) - 1.0)) + 1.0) * particleSize;\n\t\t\t\t\t\t#endif\n\t\t\t\t\t#else\n\t\t\t\t\t\tgl_PointSize = 1.0;\n\t\t\t\t\t#endif\n\t\t\t\t}\n\t\t\t",
fragmentShader:"\n\t\t\t\tprecision highp float;\n\t\t\t\tprecision highp int;\n\t\t\t\tprecision highp sampler2D;\n\n\t\t\t\tuniform float alpha;\n\t\t\t\t#ifdef USE_IMAGE\n\t\t\t\t\tuniform sampler2D imageSampler;\n\t\t\t\t#endif\n\t\t\t\tvarying vec3 fColor;\n\t\t\t\t#if ROTATION_MODE != 0\n\t\t\t\t\tvarying float rotation;\n\t\t\t\t#endif\n\n\t\t\t\tvoid main() {\n\t\t\t\t\t#ifdef USE_IMAGE\n\t\t\t\t\t\tvec2 uv;\n\t\t\t\t\t\t#if ROTATION_MODE != 0\n\t\t\t\t\t\t\tfloat c = cos(rotation);\n\t\t\t\t\t\t\tfloat s = sin(rotation);\n\t\t\t\t\t\t\tvec2 pos = vec2((gl_PointCoord.x - 0.5) * 2.0, ((1.0 - gl_PointCoord.y) - 0.5) * 2.0);\n\t\t\t\t\t\t\tvec2 rot = vec2(c * pos.x + s * pos.y, -c * pos.y + s * pos.x);\n\t\t\t\t\t\t\tuv = (rot / 2.0 * (1.0 + abs(sin(rotation * 2.0)) * (sqrt(2.0) - 1.0)) + vec2(0.5));\n\t\t\t\t\t\t#else\n\t\t\t\t\t\t\tuv = vec2(gl_PointCoord.x, 1.0 - gl_PointCoord.y);\n\t\t\t\t\t\t#endif\n\t\t\t\t\t\tuv = uv * 0.5 + vec2(0.25);\n\t\t\t\t\t\tgl_FragColor = texture2D(imageSampler, uv) * vec4(fColor.x, fColor.y, fColor.z, alpha);\n\t\t\t\t\t#else\n\t\t\t\t\t\tgl_FragColor = vec4(fColor, alpha);\n\t\t\t\t\t#endif\n\t\t\t\t}\n\t\t\t"});
this._particleMaterial.transparent=!0;this._particleMaterial.depthTest=!1;this._particleMaterial.depthWrite=!1;this._particleMaterial.stencilWrite=!1;this._particleMaterial.toneMapped=!1;this._holeGeometry=new THREE.CircleGeometry(1,96);this._holeMeshes=[];this._poleSizeDependOnZoom=!0;this._poleSizeFactor=1;this._positivePoleColor=new THREE.Color(.88,0,0);this._negativePoleColor=new THREE.Color(.0432,.88768,.9168);this._negativePoleOpacity=this._positivePoleOpacity=1;this._particleTexture=null;this._particleTextureSetID=
0;this.particleSize=15;this._particleRotationMode=0;this._particleColor=new THREE.Color(1,1,1);this._colorVariationEnabled=!0;this.alpha=this._colorTheme=1;this._backgroundColor=new THREE.Color(0,0,0);this._useAntialiasing=!0;this._colorThemeEventCallbacks=[];this._createRenderer();this._refreshSize()}_createClass(n,[{key:"_dispose",value:function(){null!=this.renderer&&(this.renderer.forceContextLoss(),this.renderer.resetState(),this.renderer.dispose(),this.renderer=null);null!=this._canvas&&(this._canvas.width=
1,this._canvas.height=1,this._screenDiv.removeChild(this._canvas),this._canvas=null)}},{key:"_createRenderer",value:function(){this._dispose();this._canvas=document.createElement("canvas");this._screenDiv.appendChild(this._canvas);this.renderer=new THREE.WebGLRenderer({canvas:this._canvas,antialias:this._useAntialiasing,powerPreference:"high-performance",stencil:!1,depth:!1,preserveDrawingBuffer:!0});this.renderer.setClearColor(this._backgroundColor)}},{key:"setAntialiasing",value:function(d){this._useAntialiasing=
d;this._createRenderer()}},{key:"getMaxTextureSize",value:function(){return this.renderer.capabilities.maxTextureSize}},{key:"getMaxVertexTextureImageUnits",value:function(){return this.renderer.capabilities.maxVertexTextures}},{key:"getFloat32Support",value:function(){return this.renderer.extensions.has("OES_texture_float")||this.renderer.capabilities.isWebGL2?!0:!1}},{key:"getRenderFloat32Support",value:function(){return this.renderer.extensions.has("WEBGL_color_buffer_float")||this.renderer.extensions.has("EXT_color_buffer_float")?
!0:!1}},{key:"getMaxFragmentUniformVectors",value:function(){return this.renderer.capabilities.maxFragmentUniforms}},{key:"showParticlesAndPoles",value:function(){this._particlesAndPolesScene.visible=!0}},{key:"hideParticlesAndPoles",value:function(){this._particlesAndPolesScene.visible=!1}},{key:"_createHoleMesh",value:function(){var d=new THREE.MeshBasicMaterial({transparent:!0,opacity:1});d=new THREE.Mesh(this._holeGeometry,d);d.renderOrder=1;d.visible=!1;this._particlesAndPolesScene.add(d);this._holeMeshes.push(d)}},
{key:"_createParticleSystemMesh",value:function(){null!=this._particleSystemMesh&&(this._particlesAndPolesScene.remove(this._particleSystemMesh),this._particleSystemMesh.geometry.dispose(),this._particleSystemMesh.material.dispose());for(var d=new Float32Array(1*this._particleSystem.maxAmount),e=new Float32Array(2*this._particleSystem.maxAmount),a=0;a<this._particleSystem.maxAmount;++a)d[a]=Math.random(),e[2*a]=(a-Math.floor(a/this._particleSystem.textureSize)*this._particleSystem.textureSize+.5)/
this._particleSystem.textureSize,e[2*a+1]=(Math.floor(a/this._particleSystem.textureSize)+.5)/this._particleSystem.textureSize;a=new THREE.BufferGeometry;a.setAttribute("position",new THREE.BufferAttribute(d,1));a.setAttribute("uv",new THREE.BufferAttribute(e,2));d=new THREE.Points(a,this._particleMaterial);d.maxAmount=this._particleSystem.maxAmount;d.frustumCulled=!1;d.depthTest=!1;d.depthWrite=!1;d.matrixAutoUpdate=!1;d.updateMatrix();this._particlesAndPolesScene.add(d);this._particleSystemMesh=
d}},{key:"addToolSystem",value:function(d){this._scene.add(d.toolLineMesh);this._scene.add(d.toolMesh)}},{key:"particleSystem",set:function(d){this._particleSystem=d;d=d.maxHoles-this._holeMeshes.length;for(var e=0;e<d;++e)this._createHoleMesh();this._createParticleSystemMesh()}},{key:"setParticleTexture",value:function(d){var e=this;if(null==d)this._particleTexture=null;else{var a=++this._particleTextureSetID;(new THREE.TextureLoader).load(d,function(b){a==e._particleTextureSetID&&(b.wrapS=THREE.ClampToEdgeWrapping,
b.wrapT=THREE.ClampToEdgeWrapping,e._particleTexture=b)})}}},{key:"setParticleRotationMode",value:function(d){if("None"==d)this._particleRotationMode=0;else if("Random"==d)this._particleRotationMode=1;else if("Velocity"==d)this._particleRotationMode=2;else throw"Invalid rotation mode";}},{key:"setColorTheme",value:function(d){if(0<=d&&4>=d)this._colorTheme=d;else throw"Theme id "+d+" is not a color theme";for(var e=0;e<this._colorThemeEventCallbacks.length;++e)this._colorThemeEventCallbacks[e](d)}},
{key:"addColorThemeEventListener",value:function(d){this._colorThemeEventCallbacks.push(d)}},{key:"setColorVariationEnabled",value:function(d){this._colorVariationEnabled=d}},{key:"setColor",value:function(d){this._particleColor=new THREE.Color(d)}},{key:"setBackgroundColor",value:function(d){this._backgroundColor=new THREE.Color(d);this.renderer.setClearColor(this._backgroundColor)}},{key:"getBackgroundColor",value:function(){return this._backgroundColor.clone()}},{key:"setPoleSizeFactor",value:function(d){this._poleSizeFactor=
d}},{key:"getPoleSizeFactor",value:function(){return this._poleSizeFactor}},{key:"setPoleSizeDependOnZoom",value:function(d){this._poleSizeDependOnZoom=d}},{key:"getPoleSizeDependOnZoom",value:function(){return this._poleSizeDependOnZoom}},{key:"setPositvePoleColor",value:function(d){this._positivePoleColor=new THREE.Color(d)}},{key:"setNegativePoleColor",value:function(d){this._negativePoleColor=new THREE.Color(d)}},{key:"setPositivePoleOpacity",value:function(d){this._positivePoleOpacity=d}},{key:"setNegativePoleOpacity",
value:function(d){this._negativePoleOpacity=d}},{key:"captureScreen",value:function(d,e,a,b,c){var f=this._camera.camera.position.x,l=this._camera.camera.position.y,m=this._camera.zoom;this._camera.camera.position.x=a;this._camera.camera.position.y=b;this._camera.setZoom(c);this._refreshSize(d,e);this._draw();this._camera.camera.position.x=f;this._camera.camera.position.y=l;this._camera.setZoom(m);a=document.createElement("canvas");a.width=d;a.height=e;a.getContext("2d").drawImage(this._canvas,0,
0);return a}},{key:"_refreshSize",value:function(d,e){this._canvas.width=d;this._canvas.height=e;this._camera.setSize(this._canvas.width,this._canvas.height);this.renderer.setSize(this._canvas.width,this._canvas.height)}},{key:"_draw",value:function(){for(var d=0;d<this._holeMeshes.length;++d)this._holeMeshes[d].visible=!1;if(null!=this._particleSystem)for(this._particleSystemMesh.maxAmount!=this._particleSystem.maxAmount&&this._createParticleSystemMesh(),this._particleMaterial.defines.COLOR_THEME!=
this._colorTheme&&(this._particleMaterial.defines.COLOR_THEME=this._colorTheme,this._particleMaterial.needsUpdate=!0),this._particleMaterial.defines.COLOR_VARIATION!=this._colorVariationEnabled&&(this._particleMaterial.defines.COLOR_VARIATION=this._colorVariationEnabled,this._particleMaterial.needsUpdate=!0),d=null!=this._particleTexture,this._particleMaterial.defines.USE_IMAGE!=d&&(this._particleMaterial.defines.USE_IMAGE=d,this._particleMaterial.needsUpdate=!0),this._particleMaterial.defines.ROTATION_MODE!=
this._particleRotationMode&&(this._particleMaterial.defines.ROTATION_MODE=this._particleRotationMode,this._particleMaterial.needsUpdate=!0),this._camera.camera.updateMatrix(),this._camera.camera.updateMatrixWorld(),d=this._camera.camera.projectionMatrix.clone().multiply(this._camera.camera.matrixWorldInverse).multiply(this._particleSystemMesh.matrixWorld),this._particleMaterial.uniforms.projectionModelViewMatrix.value=d,this._particleMaterial.uniforms.color.value=this._particleColor,this._particleMaterial.uniforms.colorSampler.value=
this._particleSystem.colorTexture,this._particleMaterial.uniforms.sampler.value=this._particleSystem.texture,this._particleMaterial.uniforms.imageSampler.value=this._particleTexture,this._particleMaterial.uniforms.particleSize.value=null!=this._particleTexture?this.particleSize:1,this._particleMaterial.uniforms.alpha.value=this.alpha,d=0;d<this._particleSystem.holes.length;++d){var e=this._particleSystem.holes[d],a=this._holeMeshes[d];a.visible=!0;0<=e.mass?(a.material.color.set(this._positivePoleColor),
a.material.opacity=this._positivePoleOpacity):(a.material.color.set(this._negativePoleColor),a.material.opacity=this._negativePoleOpacity);a.position.set(e.posX,e.posY,0);e=e.getDisplayRadius(this._camera,this._poleSizeFactor,this._poleSizeDependOnZoom);a.scale.set(e,e,e)}this.renderer.render(this._scene,this._camera.camera)}},{key:"_updateSize",value:function(){"full"==this._screenDiv.className?this._canvas.width==window.innerWidth&&this._canvas.height==window.innerHeight||this._refreshSize(window.innerWidth,
window.innerHeight):this._canvas.width==window.innerWidth-300&&this._canvas.height==window.innerHeight||this._refreshSize(window.innerWidth-300,window.innerHeight)}},{key:"update",value:function(){this._updateSize();this._draw()}},{key:"scene",get:function(){return this._scene}}]);return n}(),Hole=function(){function n(d,e,a,b,c,f,l){_classCallCheck(this,n);this.posX=d;this.posY=e;this.velX=a;this.velY=b;this.mass=c;this.isAffectedByGravity=f;this.hasGravitationalPull=l}_createClass(n,[{key:"getDisplayRadius",
value:function(d,e,a){e*=Math.pow(Math.abs(this.mass),1/3)/30;a||(e/=d.zoom);return Math.max(e,1/d.zoom)}},{key:"getInteractionRadius",value:function(d,e,a){e*=Math.pow(Math.abs(this.mass),1/3)/30;a||(e/=d.zoom);return Math.max(e,10/d.zoom)}}]);return n}(),InfoManager=function(){function n(d,e,a){_classCallCheck(this,n);this._element=d;this._camera=e;this._particleSystem=a;this._leftContainer=document.createElement("span");this._leftContainer.className="left";this._element.appendChild(this._leftContainer);
this._frameCounter=document.createElement("p");this._frameCounter.textContent="- fps";this._leftContainer.appendChild(this._frameCounter);this._time=this._frames=0;this._timeElapsed=document.createElement("p");this._stepsElapsed=document.createElement("p");this._showTime=!1;this._rightContainer=document.createElement("span");this._rightContainer.className="right";this._element.appendChild(this._rightContainer);this._zoomAmount=document.createElement("p");this._zoomAmount.textContent="100%";this._rightContainer.appendChild(this._zoomAmount)}
_createClass(n,[{key:"showTimeInfo",value:function(){this._updateTime();this._leftContainer.appendChild(this._timeElapsed);this._leftContainer.appendChild(this._stepsElapsed);this._showTime=!0}},{key:"hideTimeInfo",value:function(){this._leftContainer.removeChild(this._timeElapsed);this._leftContainer.removeChild(this._stepsElapsed);this._showTime=!1}},{key:"_updateTime",value:function(){this._timeElapsed.textContent=Math.floor(1E3*this._particleSystem.time)/1E3+" s";this._stepsElapsed.textContent=
this._particleSystem.steps+" steps"}},{key:"update",value:function(d){++this._frames;for(this._time+=d;1<=this._time;)this._frameCounter.className=30>=this._frames?"red":"",this._frameCounter.textContent=this._frames+" fps",this._frames=0,--this._time;this._showTime&&this._updateTime();d=Math.floor(1E3*this._camera.zoom)/10+"%";this._zoomAmount.textContent!=d&&(this._zoomAmount.textContent=d)}}]);return n}(),Loading=function(){function n(){_classCallCheck(this,n);this._isLoading=!1;this._hasLeftUIMargin=
!0;this._element=document.getElementById("loading");this._bar=this._element.getElementsByClassName("bar")[0].children[0]}_createClass(n,[{key:"update",value:function(){this._isLoading||"hidden"!=this._element.className&&this._refreshClassName()}},{key:"_refreshClassName",value:function(){this._element.className=this._isLoading?this._hasLeftUIMargin?"":"full":"hidden"}},{key:"isLoading",value:function(){return this._isLoading}},{key:"start",value:function(){this._isLoading=!0;this._refreshClassName()}},
{key:"end",value:function(){this._isLoading=!1}},{key:"setBar",value:function(d){this._bar.style.width=100*d+"%"}},{key:"disableUIMargin",value:function(){this._hasLeftUIMargin=!1;this._refreshClassName()}},{key:"enableUIMargin",value:function(){this._hasLeftUIMargin=!0;this._refreshClassName()}}]);return n}(),ParticleSystem=function(){function n(d,e){_classCallCheck(this,n);this._graphics=e;this._delta=this._maxAmount=this._particleWritePosition=this._amount=this._time=this._steps=0;this.step=.01;
this.speed=1;this.gravity=0;this.particleInfluence=1;this.holesGravity=1E6;this.holes=[];this._maxPoles=50;this._currentScenarioLoading=null;this._colorCanvas=document.createElement("canvas");this._colorContext=this._colorCanvas.getContext("2d");this._colorTexture=new THREE.CanvasTexture(this._colorCanvas,THREE.UVMapping,THREE.ClampToEdgeWrapping,THREE.ClampToEdgeWrapping,THREE.NearestFilter,THREE.NearestFilter);this._colorTexture.flipY=!1;this._textureSize=0;this._renderTargetA=new THREE.WebGLRenderTarget(this.textureSize,
this.textureSize,{type:THREE.FloatType,wrapS:THREE.ClampToEdgeWrapping,wrapT:THREE.ClampToEdgeWrapping,magFilter:THREE.NearestFilter,minFilter:THREE.NearestFilter,depthBuffer:!1,stencilBuffer:!1});this._renderTargetB=new THREE.WebGLRenderTarget(this.textureSize,this.textureSize,{type:THREE.FloatType,wrapS:THREE.ClampToEdgeWrapping,wrapT:THREE.ClampToEdgeWrapping,magFilter:THREE.NearestFilter,minFilter:THREE.NearestFilter,depthBuffer:!1,stencilBuffer:!1});this._scene=new THREE.Scene;this._plane=new THREE.Mesh(new THREE.PlaneBufferGeometry(2,
2),new THREE.RawShaderMaterial({defines:{NUMBER_OF_POLES:0,GRAVITY_ENABLED:!1},uniforms:{sampler:{type:"t",value:null},delta:{value:0},particleInfluence:{value:0},gravity:{value:0},holes:{type:"v3v",value:null}},vertexShader:"\n\t\t\t\tprecision highp float;\n\t\t\t\tprecision highp int;\n\t\t\t\tuniform mat4 modelViewMatrix;\n\t\t\t\tuniform mat4 projectionMatrix;\n\t\t\t\tattribute vec2 position;\n\t\t\t\tvarying vec2 fPos;\n\t\t\t\tvoid main() {\n\t\t\t\t\tvec4 modelViewPosition = modelViewMatrix * vec4(position, 0.0, 1.0);\n\t\t\t\t\tgl_Position = projectionMatrix * modelViewPosition;\n\t\t\t\t\tfPos = position;\n\t\t\t\t}\n\t\t\t",
fragmentShader:"\n\t\t\t\tprecision highp float;\n\t\t\t\tprecision highp int;\n\t\t\t\tprecision highp sampler2D;\n\t\t\t\tuniform sampler2D sampler;\n\t\t\t\tuniform float delta;\n\t\t\t\tuniform float particleInfluence;\n\t\t\t\tuniform float gravity;\n\t\t\t\t#if NUMBER_OF_POLES > 0\n\t\t\t\tuniform vec3 holes[NUMBER_OF_POLES];\n\t\t\t\t#endif\n\t\t\t\tvarying vec2 fPos;\n\n\t\t\t\tvoid main() {\n\t\t\t\t\tvec4 color = texture2D(sampler, fPos);\n\t\t\t\t\tvec2 pos = color.rg;\n\t\t\t\t\tvec2 vel = color.ba;\n\n\t\t\t\t\t#ifdef GRAVITY_ENABLED\n\t\t\t\t\tvel.y -= gravity * delta;\n\t\t\t\t\t#endif\n\n\t\t\t\t\t#if NUMBER_OF_POLES > 0\n\t\t\t\t\t#pragma unroll_loop_start\n\t\t\t\t\tfor(int i = 0; i < NUMBER_OF_POLES; ++i) {\n\t\t\t\t\t\tvec2 dPos = holes[i].xy - pos;\n\t\t\t\t\t\tfloat distanceSquared = dot(dPos, dPos);\n\t\t\t\t\t\tfloat force = holes[i].z / distanceSquared * particleInfluence;\n\n\t\t\t\t\t\tvel += normalize(dPos) * force * delta;\n\t\t\t\t\t}\n\t\t\t\t\t#pragma unroll_loop_end\n\t\t\t\t\t#endif\n\n\t\t\t\t\tpos += vel * delta;\n\n\t\t\t\t\tgl_FragColor = vec4(pos.xy, vel.xy);\n\t\t\t\t}\n\t\t\t"}));
this._plane.frustumCulled=!1;this._scene.add(this._plane);this._overlayPlane=new THREE.Mesh(new THREE.PlaneBufferGeometry(2,2),new THREE.RawShaderMaterial({uniforms:{sampler:{type:"t",value:null},samplerSize:{value:0},textureSize:{value:0},start:{value:0},end:{value:0}},vertexShader:"\n\t\t\t\tprecision highp float;\n\t\t\t\tprecision highp int;\n\t\t\t\tuniform mat4 modelViewMatrix;\n\t\t\t\tuniform mat4 projectionMatrix;\n\t\t\t\tattribute vec3 position;\n\t\t\t\tvarying vec2 fPos;\n\t\t\t\tvoid main() {\n\t\t\t\t\tvec4 modelViewPosition = modelViewMatrix * vec4(position, 1.0);\n\t\t\t\t\tgl_Position = projectionMatrix * modelViewPosition;\n\t\t\t\t\tfPos = position.xy;\n\t\t\t\t}\n\t\t\t",
fragmentShader:"\n\t\t\t\tprecision highp float;\n\t\t\t\tprecision highp int;\n\t\t\t\tuniform sampler2D sampler;\n\t\t\t\tuniform int samplerSize;\n\t\t\t\tuniform int textureSize;\n\t\t\t\tuniform int start;\n\t\t\t\tuniform int end;\n\t\t\t\tvarying vec2 fPos;\n\n\t\t\t\tvoid main() {\n\t\t\t\t\tivec2 pixel = ivec2(fPos * float(textureSize) + 0.5 / float(textureSize));\n\t\t\t\t\tint pixelIndex = pixel.y * textureSize + pixel.x;\n\t\t\t\t\tif((start <= end && pixelIndex >= start && pixelIndex < end) || (start >= end && (pixelIndex >= start || pixelIndex < end))) {\n\t\t\t\t\t\tint samplerPixelIndex = pixelIndex - start;\n\t\t\t\t\t\tint samplerY = samplerPixelIndex / samplerSize;\n\t\t\t\t\t\tint samplerX = samplerPixelIndex - samplerY * samplerSize;\n\t\t\t\t\t\tvec2 samplerUV = (vec2(samplerX, samplerY) + 0.5) / float(samplerSize);\n\t\t\t\t\t\tgl_FragColor = texture2D(sampler, samplerUV);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tdiscard;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t"}));
this._overlayPlane.renderOrder=1;this._overlayPlane.frustumCulled=!1;this._overlayPlane.visible=!1;this._scene.add(this._overlayPlane);this._camera=new THREE.OrthographicCamera(0,1,1,0,1,2);this._camera.position.z=1;this._scene.add(this._camera);this.setMaxAmount(d)}_createClass(n,[{key:"steps",get:function(){return this._steps}},{key:"time",get:function(){return this._time}},{key:"amount",get:function(){return this._amount}},{key:"maxAmount",get:function(){return this._maxAmount}},{key:"maxHoles",
get:function(){return this._maxPoles}},{key:"colorTexture",get:function(){return this._colorTexture}},{key:"texture",get:function(){return this._useRenderTargetA?this._renderTargetA.texture:this._renderTargetB.texture}},{key:"textureSize",get:function(){return this._textureSize}},{key:"clear",value:function(){var d=new Float32Array(4);d[0]=NaN;d[1]=NaN;d[2]=NaN;d[3]=NaN;d=new THREE.DataTexture(d,1,1,THREE.RGBAFormat,THREE.FloatType);this._overlayPlane.material.uniforms.sampler.value=d;this._overlayPlane.material.uniforms.samplerSize.value=
1;this._overlayPlane.material.uniforms.textureSize.value=this._textureSize;this._overlayPlane.material.uniforms.start.value=0;this._overlayPlane.material.uniforms.end.value=this._textureSize*this._textureSize;this._overlayPlane.visible=!0;this._setUniforms(0);this._graphics.renderer.setRenderTarget(this._getWriteTexture());this._graphics.renderer.render(this._scene,this._camera);this._graphics.renderer.setRenderTarget(null);this._useRenderTargetA=!this._useRenderTargetA;this._overlayPlane.visible=
!1;d.dispose();this._particleWritePosition=this._amount=0}},{key:"setMaxAmount",value:function(d){this._particleWritePosition=this._amount=0;this._maxAmount=d;this._textureSize=Math.sqrt(d);this._textureSize!=Math.floor(this._textureSize)&&console.warn("Illegal maximum number of particles: "+d);this._colorCanvas.width=this.textureSize;this._colorCanvas.height=this.textureSize;this._colorTexture.needsUpdate=!0;this._renderTargetA.setSize(this.textureSize,this.textureSize);this._renderTargetB.setSize(this.textureSize,
this.textureSize);this.clear();this.updateStep(0)}},{key:"createParticles",value:function(d,e,a){if(d>e.length/4)throw"Particles list is too short";var b=Math.ceil(Math.sqrt(d));if(e instanceof Float32Array&&e.length==4*b*b)var c=e;else{c=new Float32Array(4*b*b);for(var f=0;f<e.length;++f)c[f]=e[f]}e=new THREE.DataTexture(c,b,b,THREE.RGBAFormat,THREE.FloatType);this._overlayPlane.material.uniforms.sampler.value=e;this._overlayPlane.material.uniforms.samplerSize.value=b;this._overlayPlane.material.uniforms.textureSize.value=
this._textureSize;this._overlayPlane.material.uniforms.start.value=this._particleWritePosition;this._overlayPlane.material.uniforms.end.value=(this._particleWritePosition+d)%(this._textureSize*this._textureSize);this._overlayPlane.visible=!0;this._setUniforms(0);this._graphics.renderer.setRenderTarget(this._getWriteTexture());this._graphics.renderer.render(this._scene,this._camera);this._graphics.renderer.setRenderTarget(null);this._useRenderTargetA=!this._useRenderTargetA;this._overlayPlane.visible=
!1;e.dispose();b=Array.isArray(a)||a instanceof Float32Array?!0:!1;e=0;c=!0;do{f=Math.floor(this._particleWritePosition/this.textureSize);var l=this._particleWritePosition-f*this.textureSize,m=this.textureSize-l;m>=d-e&&(m=d-e,c=!1);if(b){for(var g=this._colorContext.createImageData(m,1),k=0;k<m;++k)g.data[4*k]=255*a[3*(e+k)],g.data[4*k+1]=255*a[3*(e+k)+1],g.data[4*k+2]=255*a[3*(e+k)+2],g.data[4*k+3]=255;this._colorContext.putImageData(g,l,f)}else this._colorContext.fillStyle=a,this._colorContext.fillRect(l,
f,m,1);e+=m;this._particleWritePosition+=m;this._particleWritePosition>=this.maxAmount&&(this._particleWritePosition=0)}while(c);this._colorTexture.needsUpdate=!0;this._amount=Math.min(this._maxAmount,this._amount+d)}},{key:"_loadScenario",value:function(d,e,a,b,c){var f=this;b.start();this._time=this._steps=0;this.particleInfluence=d.particleInfluence;this.gravity=d.gravity;this.holesGravity=d.holesGravity;this.holes.length=0;a.resetSettings();for(e=0;e<d.elements.length;++e)a=d.elements[e],a instanceof
ScenarioHole&&this.holes.push(new Hole(a.posX,a.posY,a.velX,a.velY,a.mass,a.isAffectedByGravity,a.hasGravitationalPull));var l=[];for(e=0;e<d.elements.length;++e)a=d.elements[e],a instanceof ScenarioParticlesElement&&l.push(a);null!=this._currentScenarioLoading&&(clearTimeout(this._currentScenarioLoading.timeout),this._currentScenarioLoading.resolve(!1),this._currentScenarioLoading=null);return new Promise(function(m,g){if(0==l.length)f.clear(),b.end(),f._currentScenarioLoading=null,m(!0);else{f.clear();
var k=null,h=null;(function r(){var u=f.maxAmount-f.amount;if(0==u)b.end(),f._currentScenarioLoading=null,m(!0);else{var x=Date.now(),v=1E3/60;do{var q=Math.min(u,Math.ceil((c?Infinity:1E5)/l.length)*l.length),t=Math.ceil(Math.sqrt(q));if(null==k||null==h)k=new Float32Array(4*t*t),h=new Float32Array(3*q);else if(k.length!=4*t*t||h.length!=3*q)k=new Float32Array(4*t*t),h=new Float32Array(3*q);t=Math.floor(q/l.length);for(var w=0;w<l.length;++w)l[w].createParticles(k,h,w*t,w==l.length-1?q-1:(w+1)*t-
1);f.createParticles(q,k,h)}while(Math.abs(Date.now()-x)<v&&0!=f.maxAmount-f.amount);f._currentScenarioLoading={resolve:m,timeout:setTimeout(r,0)}}b.setBar(f.amount/f.maxAmount)})()}})}},{key:"loadScenario",value:function(d,e,a,b){return this._loadScenario(d,e,a,b,!1)}},{key:"loadScenarioSync",value:function(d,e,a,b){return this._loadScenario(d,e,a,b,!0)}},{key:"_getReadTexture",value:function(){return this._useRenderTargetA?this._renderTargetA.texture:this._renderTargetB.texture}},{key:"_getWriteTexture",
value:function(){return this._useRenderTargetA?this._renderTargetB:this._renderTargetA}},{key:"_setUniforms",value:function(d){this._plane.material.defines.NUMBER_OF_POLES!=this.holes.length&&(this._plane.material.defines.NUMBER_OF_POLES=this.holes.length,this._plane.material.needsUpdate=!0);this._plane.material.defines.GRAVITY_ENABLED!=0<this.gravity&&(this._plane.material.defines.GRAVITY_ENABLED=0<this.gravity,this._plane.material.needsUpdate=!0);this._plane.material.uniforms.sampler.value=this._getReadTexture();
this._plane.material.uniforms.delta.value=d;this._plane.material.uniforms.particleInfluence.value=this.particleInfluence;this._plane.material.uniforms.gravity.value=this.gravity;d=[];for(var e=0;e<this.holes.length;++e){var a=this.holes[e];d.push(new THREE.Vector3(a.posX,a.posY,a.mass))}this._plane.material.uniforms.holes.value=d}},{key:"_updateStepHoles",value:function(d){for(var e=0;e<this.holes.length;++e){var a=this.holes[e];if(a.isAffectedByGravity)for(var b=0;b<this.holes.length;++b){var c=
this.holes[b];if(c!=a&&c.hasGravitationalPull){var f=this.holesGravity*(Math.abs(a.mass)+Math.abs(c.mass))/((a.posX-c.posX)*(a.posX-c.posX)+(a.posY-c.posY)*(a.posY-c.posY));c=Math.atan2(c.posY-a.posY,c.posX-a.posX);var l=Math.sin(c);a.velX+=Math.cos(c)*f/Math.abs(a.mass)*d;a.velY+=l*f/Math.abs(a.mass)*d}}}for(e=0;e<this.holes.length;++e)a=this.holes[e],a.posX+=a.velX*d,a.posY+=a.velY*d}},{key:"update",value:function(d,e){if(0>=this.speed)this._delta=0;else{var a=(new Date).getTime();for(this._delta+=
d*this.speed;this._delta>this.step&&!(this.updateStep(this.step),this._delta-=this.step,Math.abs((new Date).getTime()-a)/1E3>e););}}},{key:"updateStep",value:function(d){this._setUniforms(d);this._graphics.renderer.setRenderTarget(this._getWriteTexture());this._graphics.renderer.render(this._scene,this._camera);this._graphics.renderer.setRenderTarget(null);this._useRenderTargetA=!this._useRenderTargetA;this._updateStepHoles(d);++this._steps;this._time+=d}}]);return n}(),Scenario=function(){function n(){_classCallCheck(this,
n);this.elements=[];this.previewY=this.previewX=this.previewTime=0;this.previewOpacity=.5;this.previewSize=1024;this.particleInfluence=1;this.gravity=0;this.holesGravity=1E6}_createClass(n,[{key:"addElement",value:function(d){this.elements.push(d)}},{key:"addHole",value:function(d,e,a,b,c,f){this.elements.push(new ScenarioHole(d,e,a,b,c,f,6<arguments.length&&void 0!==arguments[6]?arguments[6]:!0))}},{key:"deleteElement",value:function(d){for(var e=0;e<this.elements.length;++e)if(this.elements[e]==
d){this.elements[e].disposeMesh();this.elements[e].disposeSelectionMesh();this.elements.splice(e,1);break}}},{key:"clearElements",value:function(){for(var d=0;d<this.elements.length;++d)this.elements[d].disposeMesh(),this.elements[d].disposeSelectionMesh();this.elements.length=0}},{key:"updateElementMeshes",value:function(d){for(var e=0;e<this.elements.length;++e)this.elements[e].updateMesh(d),this.elements[e].updateSelectionMesh(d)}},{key:"disposeElementMeshes",value:function(){for(var d=0;d<this.elements.length;++d)this.elements[d].disposeMesh(),
this.elements[d].disposeSelectionMesh()}},{key:"getSaveString",value:function(){var d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:!1;var e="s"+this.particleInfluence;e+="s"+this.gravity;e+="s"+this.holesGravity;for(var a=0;a<this.elements.length;++a){e+="o"+n.getElementIDByType(this.elements[a].constructor);for(var b=this.elements[a].getSaveProperties(),c=0;c<b.length;++c)e+="p"+b[c]}if(d){d=new Uint8Array(e.length);for(a=0;a<e.length;++a){b=e.charCodeAt(a);if(255<b)throw"Save string has non-ASCII characters";
d[a]=b}e=pako.deflateRaw(d,{level:pako.constants.Z_BEST_COMPRESSION,strategy:pako.constants.Z_FILTERED});e=String.fromCharCode.apply(null,e);e=btoa(e);e=e.replace(/\+/g,"-");e=e.replace(/\//g,"_");e=e.replace(/=/g,"");return"ds0c1"+e}return"ds0c0"+e}},{key:"setSaveString",value:function(d){if(!d.startsWith("ds"))return!1;d=d.substr(2);var e=d.indexOf("c");if(-1==e||"0"!=d.substr(0,e))return!1;d=d.substr(e+1);if(1>d.length)return!1;e="1"==d.substr(0,1);d=d.substr(1);if(e){d=d.replace(/-/g,"+");d=d.replace(/_/g,
"/");try{d=atob(d)}catch(c){return!1}e=new Uint8Array(d.length);for(var a=0;a<d.length;++a){var b=d.charCodeAt(a);if(255<b)throw"Save string has non-ASCII characters";e[a]=b}try{if(d=pako.inflateRaw(e,{to:"string"}),!d)return!1}catch(c){return!1}}if(1<=d.length)d=d.substr(1);else return!1;d=d.split(/[s,o]/);if(3>d.length)return!1;e=parseFloat(d[0]);a=parseFloat(d[1]);b=parseFloat(d[2]);if(isNaN(e)||0>e||10<e||isNaN(a)||0>a||500<a||isNaN(b)||0>b||1E8<b)return!1;this.particleInfluence=e;this.gravity=
a;this.holesGravity=b;d.splice(0,3);this.clearElements();if(128<d.length)return!1;for(e=0;e<d.length;++e){a=d[e].split("p");if(1>a.length)return!1;b=parseInt(a[0],10);if(!Number.isFinite(b))return!1;b=n.getElementTypeByID(b);if(null==b)return!1;a.splice(0,1);b=new b;if(!b.setSaveProperties(a))return!1;this.elements.push(b)}return!0}},{key:"setAsWindowQueryString",value:function(){var d=this.getSaveString(!0);try{var e=2E3>=d.length?"?load="+d:"?";window.history.replaceState(null,"",e);0==document.referrer.search("https://www.kodub.com")?
window.top.postMessage({replaceState:e},"https://www.kodub.com"):0==document.referrer.search("https://www.localhost")&&window.top.postMessage({replaceState:e},"https://www.localhost")}catch(a){}}}],[{key:"addElementType",value:function(d,e){if(n._elementIDToType.has(d)||n._elementTypeToID.has(e))throw"Scenario element ID conflict";n._elementIDToType.set(d,e);n._elementTypeToID.set(e,d);n._elementTypes.push(e)}},{key:"getElementTypeByID",value:function(d){return n._elementIDToType.get(d)}},{key:"getElementIDByType",
value:function(d){return n._elementTypeToID.get(d)}},{key:"getElementTypesList",value:function(){return n._elementTypes.slice()}}]);return n}();_defineProperty(Scenario,"_elementIDToType",new Map);_defineProperty(Scenario,"_elementTypeToID",new Map);_defineProperty(Scenario,"_elementTypes",[]);
var ScenarioElement=function(){function n(){var d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:0,e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,a=2<arguments.length&&void 0!==arguments[2]?arguments[2]:0,b=3<arguments.length&&void 0!==arguments[3]?arguments[3]:0;_classCallCheck(this,n);this.posX=d;this.posY=e;this.velX=a;this.velY=b;this._meshSelection=this._mesh=null;this._showSelectionMesh=!1;if(this.constructor==n)throw"Can't instantiate abstract class";}_createClass(n,[{key:"updateMesh",
value:function(d){throw"Pure virtual function called";}},{key:"disposeMesh",value:function(){null!=this._mesh&&(this._mesh.parent.remove(this._mesh),this._mesh.geometry.dispose(),this._mesh.material.dispose(),this._mesh=null)}},{key:"hideSelectionMesh",value:function(){this._showSelectionMesh=!1;null!=this._meshSelection&&(this._meshSelection.visible=!1)}},{key:"showSelectionMesh",value:function(){this._showSelectionMesh=!0;null!=this._meshSelection&&(this._meshSelection.visible=!0)}},{key:"updateSelectionMesh",
value:function(d){this.disposeSelectionMesh();var e=this.getSelectionBounds();e.width=Math.min(1E35,e.width);e.height=Math.min(1E35,e.height);e.width+=.01*Math.max(e.width,e.height);e.height+=.01*Math.max(e.width,e.height);var a=(new THREE.BufferGeometry).setFromPoints([new THREE.Vector3(-e.width/2,-e.height/2,0),new THREE.Vector3(e.width/2,-e.height/2,0),new THREE.Vector3(e.width/2,e.height/2,0),new THREE.Vector3(-e.width/2,e.height/2,0),new THREE.Vector3(-e.width/2,-e.height/2,0)]),b=new THREE.LineDashedMaterial({color:16777215,
scale:60/Math.max(e.width,e.height)});this._meshSelection=new THREE.Line(a,b);this._meshSelection.computeLineDistances();this._meshSelection.renderOrder=2;this._meshSelection.rotation.z=-e.rotation;this._meshSelection.position.set(this.posX,this.posY,0);this._meshSelection.visible=this._showSelectionMesh;d.add(this._meshSelection)}},{key:"disposeSelectionMesh",value:function(){null!=this._meshSelection&&(this._meshSelection.parent.remove(this._meshSelection),this._meshSelection.geometry.dispose(),
this._meshSelection.material.dispose(),this._meshSelection=null)}},{key:"refreshPosition",value:function(){null!=this._mesh&&this._mesh.position.set(this.posX,this.posY,0);null!=this._meshSelection&&this._meshSelection.position.set(this.posX,this.posY,0)}},{key:"getSelectionBounds",value:function(){throw"Pure virtual function called";}},{key:"isWithin",value:function(d,e){throw"Pure virtual function called";}},{key:"getEditorName",value:function(){return this.constructor.getEditorName()}},{key:"clone",
value:function(){var d=new this.constructor;d.setSaveProperties(this.getSaveProperties());return d}},{key:"setSaveProperties",value:function(d){throw"Pure virtual function called";}},{key:"getSaveProperties",value:function(){throw"Pure virtual function called";}},{key:"_createEditorPropertyTextbox",value:function(d,e,a,b,c){var f=document.createElement("p");f.textContent=a;d.appendChild(f);var l=document.createElement("input");l.type="text";l.value=c();l.addEventListener("keydown",function(m){m.stopPropagation();
"Escape"!=m.key&&27!=m.keyCode&&"Enter"!=m.key&&13!=m.keyCode||l.blur()});l.addEventListener("input",function(){b(l.value)});l.addEventListener("blur",function(){b(l.value);l.value=c();e()});d.appendChild(l)}},{key:"_createEditorPropertyCheckbox",value:function(d,e,a,b,c){var f=document.createElement("h2");f.textContent=a;a=document.createElement("label");a.className="checkbox";a.tabIndex=0;a.addEventListener("keydown",function(g){if(13==g.keyCode||"Enter"==g.code||"NumpadEnter"==g.code)l.checked=
!l.checked,b(l.checked),e()});var l=document.createElement("input");l.type="checkbox";l.checked=c();l.onchange=function(){b(this.checked);e()};c=document.createElement("span");var m=document.createElement("span");a.appendChild(l);c.appendChild(m);a.appendChild(c);a.appendChild(f);d.appendChild(a)}},{key:"createEditorPropertiesUI",value:function(d,e){var a=this;this._createEditorPropertyTextbox(d,e,"Position X",function(b){b=parseFloat(b);return Number.isFinite(b)?(a.posX=b,a.refreshPosition(),!0):
!1},function(){return a.posX});this._createEditorPropertyTextbox(d,e,"Position Y",function(b){b=parseFloat(b);return Number.isFinite(b)?(a.posY=b,a.refreshPosition(),!0):!1},function(){return a.posY});this._createEditorPropertyTextbox(d,e,"Velocity X",function(b){b=parseFloat(b);return Number.isFinite(b)?(a.velX=b,!0):!1},function(){return a.velX});this._createEditorPropertyTextbox(d,e,"Velocity Y",function(b){b=parseFloat(b);return Number.isFinite(b)?(a.velY=b,!0):!1},function(){return a.velY})}}],
[{key:"getEditorName",value:function(){throw"Pure virtual function called";}}]);return n}(),ScenarioHole=function(n){function d(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:0;var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:0,f=3<arguments.length&&void 0!==arguments[3]?arguments[3]:0,l=4<arguments.length&&void 0!==arguments[4]?arguments[4]:1E6,m=5<arguments.length&&void 0!==arguments[5]?arguments[5]:!1,g=6<arguments.length&&
void 0!==arguments[6]?arguments[6]:!0;_classCallCheck(this,d);a=e.call(this,a,b,c,f);a.mass=l;a.isAffectedByGravity=m;a.hasGravitationalPull=g;return a}_inherits(d,n);var e=_createSuper(d);_createClass(d,[{key:"_getRadius",value:function(){return Math.pow(Math.abs(this.mass),1/3)/30}},{key:"getSelectionBounds",value:function(){return{width:2*this._getRadius(),height:2*this._getRadius(),rotation:0}}},{key:"isWithin",value:function(a,b){var c=a-this.posX,f=b-this.posY;c=c*c+f*f;f=this._getRadius();
return c<=f*f?!0:!1}},{key:"setSaveProperties",value:function(a){if(7!=a.length)return!1;var b=parseFloat(a[0]),c=parseFloat(a[1]),f=parseFloat(a[2]),l=parseFloat(a[3]),m=parseFloat(a[4]),g=parseInt(a[5],10);a=parseInt(a[6],10);if(!(Number.isFinite(b)&&Number.isFinite(c)&&Number.isFinite(f)&&Number.isFinite(l)&&Number.isFinite(m)&&Number.isFinite(g))||0!=g&&1!=g||!Number.isFinite(a)||0!=a&&1!=a)return!1;this.posX=b;this.posY=c;this.velX=f;this.velY=l;this.mass=m;this.isAffectedByGravity=1==g;this.hasGravitationalPull=
1==a;return!0}},{key:"getSaveProperties",value:function(){return[this.posX,this.posY,this.velX,this.velY,this.mass,this.isAffectedByGravity?1:0,this.hasGravitationalPull?1:0]}},{key:"updateMesh",value:function(a){this.disposeMesh();var b=this._getRadius(),c=new THREE.CircleGeometry(1,128);c.scale(b,b,1);b=new THREE.MeshBasicMaterial({transparent:!0,opacity:.75,color:16777215});this._mesh=new THREE.Mesh(c,b);this._mesh.renderOrder=1;this._mesh.position.set(this.posX,this.posY,0);a.add(this._mesh)}},
{key:"createEditorPropertiesUI",value:function(a,b){var c=this;_get(_getPrototypeOf(d.prototype),"createEditorPropertiesUI",this).call(this,a,b);this._createEditorPropertyTextbox(a,b,"Mass",function(f){f=parseFloat(f);return Number.isFinite(f)?(c.mass=f,null!=c._mesh&&c.updateMesh(c._mesh.parent),null!=c._meshSelection&&c.updateSelectionMesh(c._meshSelection.parent),!0):!1},function(){return c.mass});this._createEditorPropertyCheckbox(a,b,"Affected by other poles",function(f){c.isAffectedByGravity=
f},function(){return c.isAffectedByGravity});this._createEditorPropertyCheckbox(a,b,"Pulls other poles",function(f){c.hasGravitationalPull=f},function(){return c.hasGravitationalPull})}}],[{key:"getEditorName",value:function(){return"Pole"}}]);return d}(ScenarioElement);Scenario.addElementType(0,ScenarioHole);
var ScenarioParticlesElement=function(n){function d(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:0;var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:0,f=3<arguments.length&&void 0!==arguments[3]?arguments[3]:0;_classCallCheck(this,d);a=e.call(this,a,b,c,f);if(a.constructor==d)throw"Can't instantiate abstract class";return a}_inherits(d,n);var e=_createSuper(d);_createClass(d,[{key:"createParticles",value:function(a,
b,c,f){throw"Pure virtual function called";}}]);return d}(ScenarioElement),ScenarioOval=function(n){function d(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:0;var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:100,f=3<arguments.length&&void 0!==arguments[3]?arguments[3]:100,l=4<arguments.length&&void 0!==arguments[4]?arguments[4]:0,m=5<arguments.length&&void 0!==arguments[5]?arguments[5]:0,g=6<arguments.length&&
void 0!==arguments[6]?arguments[6]:0,k=7<arguments.length&&void 0!==arguments[7]?arguments[7]:!1;_classCallCheck(this,d);a=e.call(this,a,b,m,g);a.width=c;a.height=f;a.rotation=l;a.hasHardColors=k;return a}_inherits(d,n);var e=_createSuper(d);_createClass(d,[{key:"getSelectionBounds",value:function(){return{width:this.width,height:this.height,rotation:this.rotation}}},{key:"isWithin",value:function(a,b){a-=this.posX;b-=this.posY;var c=Math.cos(this.rotation),f=Math.sin(this.rotation),l=a*c-b*f;c=b*
c+a*f;return l>=-this.width/2&&l<=this.width/2&&c>=-this.height/2&&c<=this.height/2?(l=l/this.width*2,c=c/this.height*2,1>=l*l+c*c?!0:!1):!1}},{key:"setSaveProperties",value:function(a){if(8!=a.length)return!1;var b=parseFloat(a[0]),c=parseFloat(a[1]),f=parseFloat(a[2]),l=parseFloat(a[3]),m=parseFloat(a[4]),g=parseFloat(a[5]),k=parseFloat(a[6]);a=parseInt(a[7],10);if(!(Number.isFinite(b)&&Number.isFinite(c)&&Number.isFinite(f)&&Number.isFinite(l)&&Number.isFinite(m)&&Number.isFinite(g)&&Number.isFinite(k))||
k<2*-Math.PI||k>2*Math.PI||!Number.isFinite(a)||0!=a&&1!=a)return!1;this.posX=b;this.posY=c;this.velX=f;this.velY=l;this.width=m;this.height=g;this.rotation=k;this.hasHardColors=1==a;return!0}},{key:"getSaveProperties",value:function(){return[this.posX,this.posY,this.velX,this.velY,this.width,this.height,this.rotation,this.hasHardColors?1:0]}},{key:"createParticles",value:function(a,b,c,f){this.hasHardColors?this._createParticlesHard(a,b,c,f):this._createParticlesSoft(a,b,c,f)}},{key:"_createParticlesSoft",
value:function(a,b,c,f){for(var l=Math.cos(this.rotation),m=Math.sin(this.rotation);c<=f;++c){do{var g=-this.width/2+Math.random()*this.width;var k=-this.height/2+Math.random()*this.height}while(.25<g/this.width*(g/this.width)+k/this.height*(k/this.height));a[4*c]=this.posX+g*l+k*m;a[4*c+1]=this.posY+k*l-g*m;a[4*c+2]=this.velX;a[4*c+3]=this.velY;var h=5*Math.sqrt(g/this.width*(g/this.width)+k/this.height*(k/this.height))/.5,p=k=g=void 0;1>h?(k=h,g=1,p=0):2>h?(g=1-(h-1),k=1,p=0):3>h?(h-=2,g=0,k=1,
p=h):4>h?(k=h-3,g=0,k=1-k,p=1):5>h&&(g=h-4,k=0,p=1);b[3*c]=g;b[3*c+1]=k;b[3*c+2]=p}}},{key:"_createParticlesHard",value:function(a,b,c,f){for(var l=Math.cos(this.rotation),m=Math.sin(this.rotation);c<=f;++c){do{var g=-this.width/2+Math.random()*this.width;var k=-this.height/2+Math.random()*this.height}while(.25<g/this.width*(g/this.width)+k/this.height*(k/this.height));a[4*c]=this.posX+g*l+k*m;a[4*c+1]=this.posY+k*l-g*m;a[4*c+2]=this.velX;a[4*c+3]=this.velY;g=6*Math.sqrt(g/this.width*(g/this.width)+
k/this.height*(k/this.height))/.5;if(1>g){g=1;var h=k=0}else 2>g?(k=g=1,h=0):3>g?(g=0,k=1,h=0):(4>g?(g=0,k=1):(g=5>g?0:1,k=0),h=1);b[3*c]=g;b[3*c+1]=k;b[3*c+2]=h}}},{key:"updateMesh",value:function(a){this.disposeMesh();var b=new THREE.CircleGeometry(1,128);b.scale(this.width/2,this.height/2,1);var c=new THREE.MeshBasicMaterial({transparent:!0,opacity:.75,color:16777215});this._mesh=new THREE.Mesh(b,c);this._mesh.renderOrder=1;this._mesh.position.set(this.posX,this.posY,0);this._mesh.rotation.z=-this.rotation;
a.add(this._mesh)}},{key:"createEditorPropertiesUI",value:function(a,b){var c=this;_get(_getPrototypeOf(d.prototype),"createEditorPropertiesUI",this).call(this,a,b);this._createEditorPropertyTextbox(a,b,"Width",function(f){f=parseFloat(f);return Number.isFinite(f)&&0<f?(c.width=f,null!=c._mesh&&c.updateMesh(c._mesh.parent),null!=c._meshSelection&&c.updateSelectionMesh(c._meshSelection.parent),!0):!1},function(){return c.width});this._createEditorPropertyTextbox(a,b,"Height",function(f){f=parseFloat(f);
return Number.isFinite(f)&&0<f?(c.height=f,null!=c._mesh&&c.updateMesh(c._mesh.parent),null!=c._meshSelection&&c.updateSelectionMesh(c._meshSelection.parent),!0):!1},function(){return c.height});this._createEditorPropertyTextbox(a,b,"Rotation",function(f){f=parseFloat(f);return Number.isFinite(f)?(c.rotation=f*Math.PI/180,null!=c._mesh&&c.updateMesh(c._mesh.parent),null!=c._meshSelection&&c.updateSelectionMesh(c._meshSelection.parent),!0):!1},function(){return c.rotation/(Math.PI/180)%360});this._createEditorPropertyCheckbox(a,
b,"Multicolor smooth lines",function(f){c.hasHardColors=!f},function(){return!c.hasHardColors})}}],[{key:"getEditorName",value:function(){return"Oval"}}]);return d}(ScenarioParticlesElement);Scenario.addElementType(1,ScenarioOval);
var ScenarioRingBase=function(n){function d(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:0;var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:100,f=3<arguments.length&&void 0!==arguments[3]?arguments[3]:300,l=4<arguments.length&&void 0!==arguments[4]?arguments[4]:0,m=5<arguments.length&&void 0!==arguments[5]?arguments[5]:0,g=6<arguments.length&&void 0!==arguments[6]?arguments[6]:0,k=7<arguments.length&&void 0!==
arguments[7]?arguments[7]:!1;_classCallCheck(this,d);a=e.call(this,a,b,l,m);a.innerDiameter=c;a.diameter=f;a.orbitMass=g;a.isClockwise=k;if(a.constructor==d)throw"Can't instantiate abstract class";return a}_inherits(d,n);var e=_createSuper(d);_createClass(d,[{key:"createParticles",value:function(a,b,c,f){throw"Pure virtual function called";}},{key:"isWithin",value:function(a,b){var c=a-this.posX,f=b-this.posY;c=Math.sqrt(c*c+f*f);return c>=this.innerDiameter/2&&c<=this.diameter/2?!0:!1}},{key:"getSelectionBounds",
value:function(){return{width:this.diameter,height:this.diameter,rotation:0}}},{key:"updateMesh",value:function(a){this.disposeMesh();var b=new THREE.RingGeometry(Math.min(this.innerDiameter/2,this.diameter/2-.5),this.diameter/2,128),c=new THREE.MeshBasicMaterial({transparent:!0,opacity:.75,color:16777215});this._mesh=new THREE.Mesh(b,c);this._mesh.renderOrder=1;this._mesh.position.set(this.posX,this.posY,0);a.add(this._mesh)}},{key:"createEditorPropertiesUI",value:function(a,b){var c=this;_get(_getPrototypeOf(d.prototype),
"createEditorPropertiesUI",this).call(this,a,b);this._createEditorPropertyTextbox(a,b,"Inner Diameter",function(f){f=parseFloat(f);return Number.isFinite(f)&&0<=f&&f<c.diameter?(c.innerDiameter=f,null!=c._mesh&&c.updateMesh(c._mesh.parent),!0):!1},function(){return c.innerDiameter});this._createEditorPropertyTextbox(a,b,"Outer Diameter",function(f){f=parseFloat(f);return Number.isFinite(f)&&f>c.innerDiameter?(c.diameter=f,null!=c._mesh&&c.updateMesh(c._mesh.parent),null!=c._meshSelection&&c.updateSelectionMesh(c._meshSelection.parent),
!0):!1},function(){return c.diameter});this._createEditorPropertyTextbox(a,b,"Orbit mass",function(f){f=parseFloat(f);return Number.isFinite(f)&&0<=f?(c.orbitMass=f,!0):!1},function(){return c.orbitMass});this._createEditorPropertyCheckbox(a,b,"Clockwise orbit",function(f){c.isClockwise=f},function(){return c.isClockwise})}}]);return d}(ScenarioParticlesElement),ScenarioRing=function(n){function d(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:0;var b=1<arguments.length&&void 0!==
arguments[1]?arguments[1]:0,c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:100,f=3<arguments.length&&void 0!==arguments[3]?arguments[3]:300,l=4<arguments.length&&void 0!==arguments[4]?arguments[4]:0,m=5<arguments.length&&void 0!==arguments[5]?arguments[5]:0,g=6<arguments.length&&void 0!==arguments[6]?arguments[6]:0,k=7<arguments.length&&void 0!==arguments[7]?arguments[7]:!1,h=8<arguments.length&&void 0!==arguments[8]?arguments[8]:!1;_classCallCheck(this,d);a=e.call(this,a,b,c,f,l,m,g,k);
a.hasHardColors=h;return a}_inherits(d,n);var e=_createSuper(d);_createClass(d,[{key:"setSaveProperties",value:function(a){if(9!=a.length)return!1;var b=parseFloat(a[0]),c=parseFloat(a[1]),f=parseFloat(a[2]),l=parseFloat(a[3]),m=parseFloat(a[4]),g=parseFloat(a[5]),k=parseFloat(a[6]),h=parseInt(a[7],10);a=parseInt(a[8],10);if(!(Number.isFinite(b)&&Number.isFinite(c)&&Number.isFinite(f)&&Number.isFinite(l)&&Number.isFinite(m))||0>m&&m>=g||!Number.isFinite(g)||g<=m||!Number.isFinite(k)||0>k||!Number.isFinite(h)||
0!=h&&1!=h||!Number.isFinite(a)||0!=a&&1!=a)return!1;this.posX=b;this.posY=c;this.velX=f;this.velY=l;this.innerDiameter=m;this.diameter=g;this.orbitMass=k;this.isClockwise=1==h;this.hasHardColors=1==a;return!0}},{key:"getSaveProperties",value:function(){return[this.posX,this.posY,this.velX,this.velY,this.innerDiameter,this.diameter,this.orbitMass,this.isClockwise?1:0,this.hasHardColors?1:0]}},{key:"createParticles",value:function(a,b,c,f){this.hasHardColors?this._createParticlesHard(a,b,c,f):this._createParticlesSoft(a,
b,c,f)}},{key:"_createParticlesSoft",value:function(a,b,c,f){var l;for(l=this.isClockwise?-1:1;c<=f;++c){var m=this.innerDiameter/this.diameter*(this.innerDiameter/this.diameter);m=Math.sqrt(m+Math.random()*(1-m))*this.diameter/2;var g=2*Math.PI*Math.random(),k=Math.cos(g);g=Math.sin(g);var h=g*m,p=Math.sqrt(this.orbitMass/m);a[4*c]=this.posX+k*m;a[4*c+1]=this.posY+h;a[4*c+2]=this.velX-g*p*l;a[4*c+3]=this.velY+k*p*l;m=(m-.5*this.innerDiameter)/(this.diameter-this.innerDiameter)*5/.5;1>m?(k=m,m=1,
g=0):2>m?(m=1-(m-1),k=1,g=0):3>m?(g=m-2,m=0,k=1):(4>m?(k=m-3,m=0,k=1-k):(m-=4,k=0),g=1);b[3*c]=m;b[3*c+1]=k;b[3*c+2]=g}}},{key:"_createParticlesHard",value:function(a,b,c,f){var l;for(l=this.isClockwise?-1:1;c<=f;++c){var m=this.innerDiameter/this.diameter*(this.innerDiameter/this.diameter);m=Math.sqrt(m+Math.random()*(1-m))*this.diameter/2;var g=2*Math.PI*Math.random(),k=Math.cos(g);g=Math.sin(g);var h=g*m,p=Math.sqrt(this.orbitMass/m);a[4*c]=this.posX+k*m;a[4*c+1]=this.posY+h;a[4*c+2]=this.velX-
g*p*l;a[4*c+3]=this.velY+k*p*l;m=(m-.5*this.innerDiameter)/(this.diameter-this.innerDiameter)*6/.5;1>m?(m=1,g=k=0):2>m?(k=m=1,g=0):3>m?(m=0,k=1,g=0):(4>m?(m=0,k=1):(m=5>m?0:1,k=0),g=1);b[3*c]=m;b[3*c+1]=k;b[3*c+2]=g}}},{key:"createEditorPropertiesUI",value:function(a,b){var c=this;_get(_getPrototypeOf(d.prototype),"createEditorPropertiesUI",this).call(this,a,b);this._createEditorPropertyCheckbox(a,b,"Multicolor smooth lines",function(f){c.hasHardColors=!f},function(){return!c.hasHardColors})}}],[{key:"getEditorName",
value:function(){return"Ring"}}]);return d}(ScenarioRingBase);Scenario.addElementType(2,ScenarioRing);
var ScenarioRingRainbowSegments=function(n){function d(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:0;var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:100,f=3<arguments.length&&void 0!==arguments[3]?arguments[3]:300,l=4<arguments.length&&void 0!==arguments[4]?arguments[4]:20,m=5<arguments.length&&void 0!==arguments[5]?arguments[5]:0,g=6<arguments.length&&void 0!==arguments[6]?arguments[6]:0,k=7<arguments.length&&
void 0!==arguments[7]?arguments[7]:0,h=8<arguments.length&&void 0!==arguments[8]?arguments[8]:!1;_classCallCheck(this,d);a=e.call(this,a,b,c,f,m,g,k,h);a.numberOfSegments=l;return a}_inherits(d,n);var e=_createSuper(d);_createClass(d,[{key:"setSaveProperties",value:function(a){if(9!=a.length)return!1;var b=parseFloat(a[0]),c=parseFloat(a[1]),f=parseFloat(a[2]),l=parseFloat(a[3]),m=parseFloat(a[4]),g=parseFloat(a[5]),k=parseFloat(a[6]),h=parseInt(a[7],10);a=parseInt(a[8],10);if(!(Number.isFinite(b)&&
Number.isFinite(c)&&Number.isFinite(f)&&Number.isFinite(l)&&Number.isFinite(m))||0>m&&m>=g||!Number.isFinite(g)||g<=m||!Number.isFinite(k)||0>k||!Number.isFinite(h)||0!=h&&1!=h||!Number.isFinite(a)||2>a)return!1;this.posX=b;this.posY=c;this.velX=f;this.velY=l;this.innerDiameter=m;this.diameter=g;this.orbitMass=k;this.isClockwise=1==h;this.numberOfSegments=a;return!0}},{key:"getSaveProperties",value:function(){return[this.posX,this.posY,this.velX,this.velY,this.innerDiameter,this.diameter,this.orbitMass,
this.isClockwise?1:0,this.numberOfSegments]}},{key:"createParticles",value:function(a,b,c,f){var l;for(l=this.isClockwise?-1:1;c<=f;++c){var m=Math.floor(Math.random()*this.numberOfSegments),g=Math.random()*Math.PI*2,k=this.innerDiameter/2+m/(this.numberOfSegments-1)*(this.diameter-this.innerDiameter)/2,h=Math.cos(g);g=Math.sin(g);var p=g*k,r=Math.sqrt(this.orbitMass/k);a[4*c]=this.posX+h*k;a[4*c+1]=this.posY+p;a[4*c+2]=this.velX-g*r*l;a[4*c+3]=this.velY+h*r*l;m=m%6*6/6;1>m?(m=1,h=k=0):2>m?(k=m=1,
h=0):3>m?(m=0,k=1,h=0):(4>m?(m=0,k=1):(m=5>m?0:1,k=0),h=1);b[3*c]=m;b[3*c+1]=k;b[3*c+2]=h}}},{key:"createEditorPropertiesUI",value:function(a,b){var c=this;_get(_getPrototypeOf(d.prototype),"createEditorPropertiesUI",this).call(this,a,b);this._createEditorPropertyTextbox(a,b,"Segments",function(f){f=parseInt(f,10);return Number.isFinite(f)&&2<=f?(c.numberOfSegments=f,null!=c._mesh&&c.updateMesh(c._mesh.parent),null!=c._meshSelection&&c.updateSelectionMesh(c._meshSelection.parent),!0):!1},function(){return c.numberOfSegments})}}],
[{key:"getEditorName",value:function(){return"Ring segments"}}]);return d}(ScenarioRingBase);Scenario.addElementType(3,ScenarioRingRainbowSegments);
var ScenarioRectangleBase=function(n){function d(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:0;var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:100,f=3<arguments.length&&void 0!==arguments[3]?arguments[3]:100,l=4<arguments.length&&void 0!==arguments[4]?arguments[4]:0,m=5<arguments.length&&void 0!==arguments[5]?arguments[5]:0,g=6<arguments.length&&void 0!==arguments[6]?arguments[6]:0,k=7<arguments.length&&void 0!==
arguments[7]?arguments[7]:!1;_classCallCheck(this,d);a=e.call(this,a,b,m,g);a.width=c;a.height=f;a.rotation=l;a.hasHardColors=k;if(a.constructor==d)throw"Can't instantiate abstract class";return a}_inherits(d,n);var e=_createSuper(d);_createClass(d,[{key:"createParticles",value:function(a,b,c,f){throw"Pure virtual function called";}},{key:"getSelectionBounds",value:function(){return{width:this.width,height:this.height,rotation:this.rotation}}},{key:"isWithin",value:function(a,b){a-=this.posX;b-=this.posY;
var c=Math.cos(this.rotation),f=Math.sin(this.rotation),l=a*c-b*f;c=b*c+a*f;return l>=-this.width/2&&l<=this.width/2&&c>=-this.height/2&&c<=this.height/2?!0:!1}},{key:"setSaveProperties",value:function(a){if(8!=a.length)return!1;var b=parseFloat(a[0]),c=parseFloat(a[1]),f=parseFloat(a[2]),l=parseFloat(a[3]),m=parseFloat(a[4]),g=parseFloat(a[5]),k=parseFloat(a[6]);a=parseInt(a[7],10);if(!(Number.isFinite(b)&&Number.isFinite(c)&&Number.isFinite(f)&&Number.isFinite(l)&&Number.isFinite(m)&&Number.isFinite(g)&&
Number.isFinite(k))||k<2*-Math.PI||k>2*Math.PI||!Number.isFinite(a)||0!=a&&1!=a)return!1;this.posX=b;this.posY=c;this.velX=f;this.velY=l;this.width=m;this.height=g;this.rotation=k;this.hasHardColors=1==a;return!0}},{key:"getSaveProperties",value:function(){return[this.posX,this.posY,this.velX,this.velY,this.width,this.height,this.rotation,this.hasHardColors?1:0]}},{key:"updateMesh",value:function(a){this.disposeMesh();var b=new THREE.PlaneGeometry(1,1);b.scale(this.width,this.height,1);var c=new THREE.MeshBasicMaterial({transparent:!0,
opacity:.75,color:16777215});this._mesh=new THREE.Mesh(b,c);this._mesh.renderOrder=1;this._mesh.position.set(this.posX,this.posY,0);this._mesh.rotation.z=-this.rotation;a.add(this._mesh)}},{key:"createEditorPropertiesUI",value:function(a,b){var c=this;_get(_getPrototypeOf(d.prototype),"createEditorPropertiesUI",this).call(this,a,b);this._createEditorPropertyTextbox(a,b,"Width",function(f){f=parseFloat(f);return Number.isFinite(f)&&0<f?(c.width=f,null!=c._mesh&&c.updateMesh(c._mesh.parent),null!=c._meshSelection&&
c.updateSelectionMesh(c._meshSelection.parent),!0):!1},function(){return c.width});this._createEditorPropertyTextbox(a,b,"Height",function(f){f=parseFloat(f);return Number.isFinite(f)&&0<f?(c.height=f,null!=c._mesh&&c.updateMesh(c._mesh.parent),null!=c._meshSelection&&c.updateSelectionMesh(c._meshSelection.parent),!0):!1},function(){return c.height});this._createEditorPropertyTextbox(a,b,"Rotation",function(f){f=parseFloat(f);return Number.isFinite(f)?(c.rotation=f*Math.PI/180,null!=c._mesh&&c.updateMesh(c._mesh.parent),
null!=c._meshSelection&&c.updateSelectionMesh(c._meshSelection.parent),!0):!1},function(){return c.rotation/(Math.PI/180)%360});this._createEditorPropertyCheckbox(a,b,"Multicolor smooth lines",function(f){c.hasHardColors=!f},function(){return!c.hasHardColors})}}]);return d}(ScenarioParticlesElement),ScenarioRectangle=function(n){function d(){_classCallCheck(this,d);return e.apply(this,arguments)}_inherits(d,n);var e=_createSuper(d);_createClass(d,[{key:"createParticles",value:function(a,b,c,f){this.hasHardColors?
this._createParticlesHard(a,b,c,f):this._createParticlesSoft(a,b,c,f)}},{key:"_createParticlesSoft",value:function(a,b,c,f){for(var l=Math.cos(this.rotation),m=Math.sin(this.rotation);c<=f;++c){var g=-this.width/2+Math.random()*this.width,k=-this.height/2+Math.random()*this.height;a[4*c]=this.posX+g*l+k*m;a[4*c+1]=this.posY+k*l-g*m;a[4*c+2]=this.velX;a[4*c+3]=this.velY;g=10*Math.max(Math.abs(g/this.width),Math.abs(k/this.height));if(1>g){k=g;g=1;var h=0}else 2>g?(g=1-(g-1),k=1,h=0):3>g?(h=g-2,g=0,
k=1):(4>g?(k=g-3,g=0,k=1-k):(g-=4,k=0),h=1);b[3*c]=g;b[3*c+1]=k;b[3*c+2]=h}}},{key:"_createParticlesHard",value:function(a,b,c,f){for(var l=Math.cos(this.rotation),m=Math.sin(this.rotation);c<=f;++c){var g=-this.width/2+Math.random()*this.width,k=-this.height/2+Math.random()*this.height;a[4*c]=this.posX+g*l+k*m;a[4*c+1]=this.posY+k*l-g*m;a[4*c+2]=this.velX;a[4*c+3]=this.velY;g=12*Math.max(Math.abs(g/this.width),Math.abs(k/this.height));if(1>g){g=1;var h=k=0}else 2>g?(k=g=1,h=0):3>g?(g=0,k=1,h=0):
(4>g?(g=0,k=1):(g=5>g?0:1,k=0),h=1);b[3*c]=g;b[3*c+1]=k;b[3*c+2]=h}}}],[{key:"getEditorName",value:function(){return"Rectangle"}}]);return d}(ScenarioRectangleBase);Scenario.addElementType(4,ScenarioRectangle);
var ScenarioRectangleLines=function(n){function d(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:0;var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:100,f=3<arguments.length&&void 0!==arguments[3]?arguments[3]:100,l=4<arguments.length&&void 0!==arguments[4]?arguments[4]:100,m=5<arguments.length&&void 0!==arguments[5]?arguments[5]:0,g=6<arguments.length&&void 0!==arguments[6]?arguments[6]:0,k=7<arguments.length&&
void 0!==arguments[7]?arguments[7]:0,h=8<arguments.length&&void 0!==arguments[8]?arguments[8]:!1;_classCallCheck(this,d);a=e.call(this,a,b,c,f,m,g,k,h);a.repeat=l;return a}_inherits(d,n);var e=_createSuper(d);_createClass(d,[{key:"setSaveProperties",value:function(a){if(9!=a.length)return!1;var b=parseFloat(a[0]),c=parseFloat(a[1]),f=parseFloat(a[2]),l=parseFloat(a[3]),m=parseFloat(a[4]),g=parseFloat(a[5]),k=parseFloat(a[6]),h=parseInt(a[7],10);a=parseFloat(a[8]);if(!(Number.isFinite(b)&&Number.isFinite(c)&&
Number.isFinite(f)&&Number.isFinite(l)&&Number.isFinite(m)&&Number.isFinite(g)&&Number.isFinite(k))||k<2*-Math.PI||k>2*Math.PI||!Number.isFinite(h)||0!=h&&1!=h||!Number.isFinite(a)||0>=a)return!1;this.posX=b;this.posY=c;this.velX=f;this.velY=l;this.width=m;this.height=g;this.rotation=k;this.hasHardColors=1==h;this.repeat=a;return!0}},{key:"getSaveProperties",value:function(){return[this.posX,this.posY,this.velX,this.velY,this.width,this.height,this.rotation,this.hasHardColors?1:0,this.repeat]}},{key:"createParticles",
value:function(a,b,c,f){this.hasHardColors?this._createParticlesHard(a,b,c,f):this._createParticlesSoft(a,b,c,f)}},{key:"_createParticlesSoft",value:function(a,b,c,f){for(var l=Math.cos(this.rotation),m=Math.sin(this.rotation);c<=f;++c){var g=-this.width/2+Math.random()*this.width,k=-this.height/2+Math.random()*this.height;a[4*c]=this.posX+g*l+k*m;a[4*c+1]=this.posY+k*l-g*m;a[4*c+2]=this.velX;a[4*c+3]=this.velY;g=(g+this.width)%this.repeat*6/this.repeat;if(1>g){k=g;g=1;var h=0}else 2>g?(g=1-(g-1),
k=1,h=0):3>g?(h=g-2,g=0,k=1):4>g?(k=g-3,g=0,k=1-k,h=1):5>g?(g-=4,k=0,h=1):(h=g-5,g=1,k=0,h=1-h);b[3*c]=g;b[3*c+1]=k;b[3*c+2]=h}}},{key:"_createParticlesHard",value:function(a,b,c,f){for(var l=Math.cos(this.rotation),m=Math.sin(this.rotation);c<=f;++c){var g=-this.width/2+Math.random()*this.width,k=-this.height/2+Math.random()*this.height;a[4*c]=this.posX+g*l+k*m;a[4*c+1]=this.posY+k*l-g*m;a[4*c+2]=this.velX;a[4*c+3]=this.velY;g=(g+this.width)%this.repeat*6/this.repeat;if(1>g){g=1;var h=k=0}else 2>
g?(k=g=1,h=0):3>g?(g=0,k=1,h=0):(4>g?(g=0,k=1):(g=5>g?0:1,k=0),h=1);b[3*c]=g;b[3*c+1]=k;b[3*c+2]=h}}},{key:"createEditorPropertiesUI",value:function(a,b){var c=this;_get(_getPrototypeOf(d.prototype),"createEditorPropertiesUI",this).call(this,a,b);this._createEditorPropertyTextbox(a,b,"Multicolor repeat distance",function(f){f=parseFloat(f);return Number.isFinite(f)&&0<f?(c.repeat=f,null!=c._mesh&&c.updateMesh(c._mesh.parent),null!=c._meshSelection&&c.updateSelectionMesh(c._meshSelection.parent),!0):
!1},function(){return c.repeat})}}],[{key:"getEditorName",value:function(){return"Rectangle lines"}}]);return d}(ScenarioRectangleBase);Scenario.addElementType(5,ScenarioRectangleLines);
function digitSeparated(n,d){var e=n.toString(),a=Math.abs(parseInt(n)).toString();if(-1!==e.indexOf("e+"))return e;e="";for(var b=a.length-1;0<=b;--b)e=0==(a.length-1-b)%3&&b!=a.length-1?a[b]+"&thinsp;"+e:a[b]+e;0>n&&(e="-"+e);0<d&&(a=Math.trunc(n),n!=a&&(b=Math.pow(10,d),e=e+"."+Math.abs(Math.trunc((n-a)*b)/b).toString().substring(2)));return e}
var Tool=function(){function n(){_classCallCheck(this,n)}_createClass(n,[{key:"mouseDown",value:function(d,e,a,b){}},{key:"mouseMove",value:function(d,e,a){}},{key:"mouseUp",value:function(d,e,a){}},{key:"modifierDown",value:function(d,e,a){}},{key:"modifierUp",value:function(d,e,a){}},{key:"update",value:function(d,e,a){}},{key:"getToolPosition",value:function(d,e){return null}},{key:"getToolLine",value:function(d,e){return null}},{key:"getToolRadius",value:function(d,e,a){return 0}},{key:"getToolColor",
value:function(d,e){return 16777215}}]);return n}(),ToolSystem=function(){function n(d,e,a,b){_classCallCheck(this,n);this._camera=e;this._particleSystem=a;this._graphics=b;this._tool=null;this._mouseY=this._mouseX=0;var c=this;d.addEventListener("pointerdown",function(f){c._mouseX=f.clientX;c._mouseY=f.clientY;c._mouseDown(f)});window.addEventListener("pointermove",function(f){c._mouseX=f.clientX;c._mouseY=f.clientY;c._mouseMove(f)});window.addEventListener("pointerup",function(f){c._mouseX=f.clientX;
c._mouseY=f.clientY;c._mouseUp(f)});window.addEventListener("keydown",function(f){c._modifierDown(f)});window.addEventListener("keyup",function(f){c._modifierUp(f)});d=new THREE.BufferGeometry;e=[];for(a=0;64>=a;++a)b=2*Math.PI/64*a,e.push(Math.cos(b),Math.sin(b),0);d.setAttribute("position",new THREE.BufferAttribute(new Float32Array(e),3));e=new THREE.LineBasicMaterial({transparent:!0,opacity:.8});d=new THREE.Line(d,e);d.renderOrder=2;this.toolMesh=d;d=new THREE.BufferGeometry;d.setAttribute("position",
new THREE.BufferAttribute(new Float32Array([0,0,0,1,0,0]),3));d=new THREE.Line(d,e);d.renderOrder=2;this.toolLineMesh=d}_createClass(n,[{key:"setTool",value:function(d){this._tool=d;null==d?this._camera.enableLeftButton():this._camera.disableLeftButton()}},{key:"_mouseDown",value:function(d){null!=this._tool&&this._tool.mouseDown(d,this._camera,this._particleSystem,this._graphics)}},{key:"_mouseMove",value:function(d){null!=this._tool&&this._tool.mouseMove(d,this._camera,this._particleSystem)}},{key:"_mouseUp",
value:function(d){null!=this._tool&&this._tool.mouseUp(d,this._camera,this._particleSystem)}},{key:"_modifierUp",value:function(d){null!=this._tool&&16==d.which&&this._tool.modifierUp(d,this._camera,this._particleSystem)}},{key:"_modifierDown",value:function(d){null!=this._tool&&16==d.which&&this._tool.modifierDown(d,this._camera,this._particleSystem)}},{key:"update",value:function(d){if(null!=this._tool)if(this._tool.update(d,this._camera,this._particleSystem),d=this._tool.getToolRadius(this._camera,
this._particleSystem,this._graphics),0>=d?this.toolMesh.visible=!1:(this.toolMesh.visible=!0,this.toolMesh.scale.set(d,d,1),d=this._tool.getToolPosition(this._camera,this._particleSystem),null==d&&(d=this._camera.screenToWorld(this._mouseX,this._mouseY)),this.toolMesh.position.set(d.x,d.y,0),this.toolMesh.material.color.set(this._tool.getToolColor(this._camera,this._particleSystem))),d=this._tool.getToolLine(this._camera,this._particleSystem),null==d)this.toolLineMesh.visible=!1;else if(d.y1==d.y0&&
d.x1==d.x0||0>=d.width)this.toolLineMesh.visible=!1;else{this.toolLineMesh.visible=!0;var e=Math.atan2(d.y1-d.y0,d.x1-d.x0),a=d.x1-d.x0,b=d.y1-d.y0;this.toolLineMesh.scale.set(Math.sqrt(a*a+b*b),d.width,1);this.toolLineMesh.position.set(d.x0,d.y0,0);this.toolLineMesh.rotation.z=e;this.toolLineMesh.material.color.set(this._tool.getToolColor(this._camera,this._particleSystem))}else this.toolMesh.visible=!1,this.toolLineMesh.visible=!1}}]);return n}(),ErrorUI=_createClass(function ErrorUI(n,d){_classCallCheck(this,
ErrorUI);this._element=n;var a=document.createElement("div");a.className="error_ui";n.appendChild(a);var b=document.createElement("h1");b.textContent="Error";a.appendChild(b);for(b=0;b<d.length;++b)if(""==d[b])a.appendChild(document.createElement("br"));else{var c=document.createElement("p");c.textContent=d[b];a.appendChild(c)}}),Navigation=function(){function n(d,e){_classCallCheck(this,n);this._ui=d;this._div=document.createElement("div");this._div.className="navigation";e.appendChild(this._div);
this._shortcutKeys=[];var a=this;window.addEventListener("keydown",function(b){if((49==b.keyCode||"Digit1"==b.code)&&1<=a._shortcutKeys.length)a._shortcutKeys[0]();else if((50==b.keyCode||"Digit2"==b.code)&&2<=a._shortcutKeys.length)a._shortcutKeys[1]();else if((51==b.keyCode||"Digit3"==b.code)&&3<=a._shortcutKeys.length)a._shortcutKeys[2]();else if((52==b.keyCode||"Digit4"==b.code)&&4<=a._shortcutKeys.length)a._shortcutKeys[3]();else if((53==b.keyCode||"Digit5"==b.code)&&5<=a._shortcutKeys.length)a._shortcutKeys[4]();
else if((54==b.keyCode||"Digit6"==b.code)&&6<=a._shortcutKeys.length)a._shortcutKeys[5]();else if((55==b.keyCode||"Digit7"==b.code)&&7<=a._shortcutKeys.length)a._shortcutKeys[6]();else if((56==b.keyCode||"Digit8"==b.code)&&8<=a._shortcutKeys.length)a._shortcutKeys[7]();else if((57==b.keyCode||"Digit9"==b.code)&&9<=a._shortcutKeys.length)a._shortcutKeys[8]()})}_createClass(n,[{key:"addTab",value:function(d,e){function a(){for(var m=0;m<f.children.length;++m)f.children[m]!=this&&(f.children[m].className=
"");b.className="selected";l.setTab(d)}var b=document.createElement("button");0==this._div.children.length&&(b.className="selected");var c=document.createElement("img");c.src=e;b.appendChild(c);this._div.appendChild(b);for(c=0;c<this._div.children.length;++c)this._div.children[c].style.width=100/this._div.children.length+"%";var f=this._div,l=this._ui;b.onclick=a;this._shortcutKeys.push(a)}}]);return n}(),TabUI=function(){function n(d){_classCallCheck(this,n);this._div=document.createElement("div");
this._div.className="tab";this._div.style.display="none";d.appendChild(this._div);this._content=document.createElement("div");this._content.className="content";this._div.appendChild(this._content);this._scrollbar=document.createElement("div");this._scrollbar.className="scrollbar";this._div.appendChild(this._scrollbar);this._scrollbarBox=document.createElement("div");this._scrollbar.appendChild(this._scrollbarBox);this._scrollGrabPos=null;this._isOpen=!1;var e=this;window.addEventListener("resize",
function(){e._isOpen&&e.refreshScrollbar()});this._content.addEventListener("scroll",function(){e._isOpen&&e.refreshScrollbarPosition()});this._scrollbarBox.addEventListener("pointerdown",function(a){if(0==a.button){var b=e._scrollbarBox.getBoundingClientRect();e._scrollGrabPos=-a.clientY+b.top}});window.addEventListener("pointermove",function(a){if(null!=e._scrollGrabPos){var b=e._content.getBoundingClientRect();e._content.scrollTop=(a.clientY-b.top+e._scrollGrabPos)/b.height*e._content.scrollHeight}});
window.addEventListener("pointerup",function(a){0==a.button&&(e._scrollGrabPos=null)})}_createClass(n,[{key:"_createDiv",value:function(){var d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:this._content,e=document.createElement("div");d.appendChild(e);return e}},{key:"_createText",value:function(d){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:this._content,a=document.createElement("p");a.innerHTML=d;e.appendChild(a);return a}},{key:"_createCenteredText",value:function(d){var e=
1<arguments.length&&void 0!==arguments[1]?arguments[1]:this._content,a=document.createElement("p");a.className="centered";a.innerHTML=d;e.appendChild(a);return a}},{key:"_createTitle",value:function(d){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:this._content,a=document.createElement("h1");a.textContent=d;e.appendChild(a);return a}},{key:"_createHorizontalLine",value:function(){var d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:this._content,e=document.createElement("div");
e.className="line";d.appendChild(e);return e}},{key:"_createEmptyLine",value:function(){var d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:this._content,e=document.createElement("br");d.appendChild(e);return e}},{key:"_createThreeButtons",value:function(d,e,a,b,c,f){var l=6<arguments.length&&void 0!==arguments[6]?arguments[6]:this._content,m=document.createElement("div");m.className="three";var g=document.createElement("button");g.innerHTML=d;g.onclick=function(){e()};m.appendChild(g);g=
document.createElement("button");g.innerHTML=a;g.onclick=function(){b()};m.appendChild(g);g=document.createElement("button");g.innerHTML=c;g.onclick=function(){f()};m.appendChild(g);l.appendChild(m);return m}},{key:"_createButton",value:function(d,e){var a=2<arguments.length&&void 0!==arguments[2]?arguments[2]:this._content,b=document.createElement("div"),c=document.createElement("button");c.textContent=d;c.onclick=function(){e()};b.appendChild(c);a.appendChild(b);return b}},{key:"_createCheckBox",
value:function(d,e,a){var b=3<arguments.length&&void 0!==arguments[3]?arguments[3]:this._content,c=document.createElement("div"),f=document.createElement("h2");f.textContent=d;var l=document.createElement("label");l.className="checkbox";l.tabIndex=0;l.addEventListener("keydown",function(h){if(13==h.keyCode||"Enter"==h.code||"NumpadEnter"==h.code)m.checked=!m.checked,a(m.checked)});var m=document.createElement("input");m.type="checkbox";m.checked=e;m.onchange=function(){a(this.checked)};var g=document.createElement("span"),
k=document.createElement("span");l.appendChild(m);g.appendChild(k);l.appendChild(g);l.appendChild(f);c.appendChild(l);b.appendChild(c);return c}},{key:"_createRadioButton",value:function(d,e,a,b){var c=4<arguments.length&&void 0!==arguments[4]?arguments[4]:this._content,f=document.createElement("div"),l=document.createElement("h2");l.textContent=d;var m=document.createElement("label");m.className="radio";m.tabIndex=0;m.addEventListener("keydown",function(p){if(13==p.keyCode||"Enter"==p.code||"NumpadEnter"==
p.code)g.checked=!g.checked,b(g.checked)});var g=document.createElement("input");g.type="radio";g.name=e;g.checked=a;g.onchange=function(){b(this.checked)};var k=document.createElement("span"),h=document.createElement("span");m.appendChild(g);k.appendChild(h);m.appendChild(k);m.appendChild(l);f.appendChild(m);c.appendChild(f);return f}},{key:"_createSliderWithButton",value:function(d,e,a,b,c,f,l,m){var g=this._createSlider(d,e,a,b,c,l,m,8<arguments.length&&void 0!==arguments[8]?arguments[8]:this._content);
g.className="slider_button";var k=document.createElement("button");k.textContent="Apply";k.onclick=function(){f()};g.appendChild(k);return g}},{key:"_createSlider",value:function(d,e,a,b,c,f,l){var m=7<arguments.length&&void 0!==arguments[7]?arguments[7]:this._content;l||(l=function(p,r){p.textContent=d+": "+r});var g=document.createElement("div"),k=document.createElement("h2"),h=document.createElement("input");h.type="range";h.min=e;h.max=a;h.step=b;h.value=c;h.oninput=h.onchange=function(){f(this.value);
l(k,this.value)};h.addEventListener("keydown",function(){if(37==event.keyCode||"ArrowLeft"==event.code||38==event.keyCode||"ArrowUp"==event.code||39==event.keyCode||"ArrowRight"==event.code||40==event.keyCode||"ArrowDown"==event.code)document.body.className="show-focus",event.stopPropagation()});l(k,c);g.appendChild(k);g.appendChild(h);m.appendChild(g);return g}},{key:"_createColorPicker",value:function(d){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:Infinity,a=2<arguments.length&&
void 0!==arguments[2]?arguments[2]:null,b=3<arguments.length&&void 0!==arguments[3]?arguments[3]:this._content,c=document.createElement("div");c.className="color_picker";if(null==a){a=[];for(var f=0;7>=f;++f)for(var l=0;16>=l;++l){var m=l/16;a.push("hsl("+Math.floor(f/7*320)+","+Math.floor(30+70*(1-2*Math.abs(m-.5)))+"%,"+Math.floor(6+76*m)+"%)")}for(f=0;16>=f;++f)a.push("hsl(0,0%,"+Math.floor(f/16*100)+"%)")}var g=[];f=function(k){var h=a[k],p=document.createElement("button");p.style.backgroundColor=
a[k];k==e||Infinity==e&&k==a.length-1?(p.className="selected",p.tabIndex=0):p.tabIndex=-1;p.addEventListener("click",function(){for(var r=0;r<g.length;++r)g[r].className="",g[r].tabIndex=-1;this.className="selected";p.tabIndex=0;d(h)});p.addEventListener("keydown",function(r){if(37==r.keyCode||"ArrowLeft"==r.code)0<k&&(g[k-1].focus(),g[k-1].click()),r.stopPropagation(),r.preventDefault();if(38==r.keyCode||"ArrowUp"==r.code)16<k&&(g[k-16-1].focus(),g[k-16-1].click()),r.stopPropagation(),r.preventDefault();
if(39==r.keyCode||"ArrowRight"==r.code)k<g.length-1&&(g[k+1].focus(),g[k+1].click()),r.stopPropagation(),r.preventDefault();if(40==r.keyCode||"ArrowDown"==r.code)k<g.length-16-1&&(g[k+16+1].focus(),g[k+16+1].click()),r.stopPropagation(),r.preventDefault()});c.appendChild(p);g.push(p)};for(l=0;l<a.length;++l)f(l);b.appendChild(c);return c}},{key:"_createImageSelection",value:function(d,e,a){var b=3<arguments.length&&void 0!==arguments[3]?arguments[3]:this._content,c=document.createElement("div");c.className=
"image_selection";for(var f=[],l=function(g){var k=document.createElement("button");k.addEventListener("click",function(){for(var p=0;p<f.length;++p)f[p].className="";k.className="selected";e(g)});g==a&&(k.className="selected");var h=document.createElement("img");h.src=d[g];k.appendChild(h);c.appendChild(k);f.push(k)},m=0;m<d.length;++m)l(m);b.appendChild(c);return c}},{key:"_hideScrollbar",value:function(){var d=this._content.offsetWidth-this._content.clientWidth;this._scrollbar.style.display="none";
this._content.style.paddingRight=d+"px";this._content.style.width=300+d+"px"}},{key:"_showScrollbar",value:function(){var d=this._content.offsetWidth-this._content.clientWidth;this._scrollbar.style.display="inline-block";this._content.style.paddingRight=d+"px";this._content.style.width=290+d+"px"}},{key:"refreshScrollbar",value:function(){var d=this._content.scrollHeight,e=this._content.clientHeight;4>d-e?this._hideScrollbar():(this._showScrollbar(),this._scrollbarBox.style.height=100*Math.min(1,
e/d)+"%",this.refreshScrollbarPosition())}},{key:"refreshScrollbarPosition",value:function(){var d=this._content.clientHeight,e=this._content.scrollHeight,a=this._content.scrollTop,b=e-d;this._scrollbarBox.style.top=0==b?"0px":a/b*(1-Math.min(1,d/e))*100+"%"}},{key:"hide",value:function(){this._isOpen=!1;this._div.style.display="none"}},{key:"show",value:function(){this._isOpen=!0;this._div.style.display="block";this.refreshScrollbar()}},{key:"isOpen",get:function(){return this._isOpen}},{key:"update",
value:function(d){}}]);return n}(),UI=function(){function n(d,e,a,b,c,f){var l=this;_classCallCheck(this,n);this._element=d;this._tabs=[];this._navigation=new Navigation(this,d);this._infoElement=e;this._versionElement=a;this._screenDiv=b;this._camera=c;this._loading=f;this._isHidden=!1;window.addEventListener("keydown",function(m){72!=m.keyCode&&"KeyH"!=m.code||l.toggle()})}_createClass(n,[{key:"addTab",value:function(d,e){this._navigation.addTab(d,e);this._tabs.push(d);1==this._tabs.length&&this.setTab(d)}},
{key:"setTab",value:function(d){for(var e=0;e<this._tabs.length;++e)this._tabs[e]!=d&&this._tabs[e].hide();d.show()}},{key:"toggle",value:function(){(this._isHidden=!this._isHidden)?(this._element.className="hidden",this._infoElement.className="hidden",this._versionElement.className="hidden",this._screenDiv.className="full",this._loading.disableUIMargin(),this._camera.moveScreen(-150,0)):(this._element.className="",this._infoElement.className="",this._versionElement.className="",this._screenDiv.className=
"",this._loading.enableUIMargin(),this._camera.moveScreen(150,0))}},{key:"update",value:function(d){for(var e=0;e<this._tabs.length;++e)this._tabs[e].update(d)}}]);return n}(),HoleTool=function(n){function d(){_classCallCheck(this,d);var a=e.call(this);a.type="add";a.mass=1E6;a.isAffectedByGravity=!1;a.hasGravitationalPull=!0;a._grabbed=null;a._grabbedPos=null;a._toolPos=null;a._mouseX=0;a._mouseY=0;return a}_inherits(d,n);var e=_createSuper(d);_createClass(d,[{key:"modifierDown",value:function(a){this._modifier=
!0}},{key:"modifierUp",value:function(a){this._modifier=!1}},{key:"mouseDown",value:function(a,b,c,f){this._mouseX=a.clientX;this._mouseY=a.clientY;this._updateMousePos(b);if(0==a.button)if("add"==this.type)c.holes.length<c.maxHoles&&(a=f=0,this._modifier&&(a=b.screenToWorld(this._mouseX,this._mouseY),b=Math.atan2(a.y-this._toolPos.y,a.x-this._toolPos.x),f=a.x-this._toolPos.x,a=a.y-this._toolPos.y,a=Math.sqrt(f*f+a*a),f=Math.cos(b)*a,a*=Math.sin(b)),b=new Hole(this._toolPos.x,this._toolPos.y,0,0,
this.mass,this.isAffectedByGravity,this.hasGravitationalPull),b.velX=f,b.velY=a,c.holes.push(b));else if("delete"==this.type){a=b.screenToWorld(a.clientX,a.clientY);for(var l=null,m=Infinity,g=0;g<c.holes.length;++g){var k=c.holes[g],h=k.getInteractionRadius(b,f.getPoleSizeFactor(),f.getPoleSizeDependOnZoom()),p=a.x-k.posX;k=a.y-k.posY;p=p*p+k*k;p<=h*h&&p<m&&(m=p,l=g)}null!=l&&c.holes.splice(l,1)}else if("move"==this.type){a=b.screenToWorld(a.clientX,a.clientY);l=null;m=Infinity;for(g=0;g<c.holes.length;++g){h=
c.holes[g];p=h.getInteractionRadius(b,f.getPoleSizeFactor(),f.getPoleSizeDependOnZoom());k=a.x-h.posX;var r=a.y-h.posY;k=k*k+r*r;k<=p*p&&k<m&&(m=k,l=h)}null!=l&&(this._grabbed=l,this._grabbedPos={x:a.x-l.posX,y:a.y-l.posY})}}},{key:"mouseMove",value:function(a,b,c){this._mouseX=a.clientX;this._mouseY=a.clientY;this._updateMousePos(b)}},{key:"mouseUp",value:function(a,b,c){this._mouseX=a.clientX;this._mouseY=a.clientY;this._updateMousePos(b);0==a.button&&(this._grabbedPos=this._grabbed=null)}},{key:"update",
value:function(a,b,c){this._updateMousePos(b);"move"==this.type&&null!=this._grabbed&&null!=this._grabbedPos&&(c=a=0,this._modifier&&(c=b.screenToWorld(this._mouseX,this._mouseY),b=Math.atan2(c.y-this._grabbed.posY,c.x-this._grabbed.posX),a=c.x-this._grabbed.posX,c=c.y-this._grabbed.posY,c=Math.sqrt(a*a+c*c),a=Math.cos(b)*c,c*=Math.sin(b)),this._grabbed.posX=this._toolPos.x-this._grabbedPos.x,this._grabbed.posY=this._toolPos.y-this._grabbedPos.y,this._grabbed.velX=a,this._grabbed.velY=c)}},{key:"_updateMousePos",
value:function(a){("add"==this.type||"move"==this.type&&null!=this._grabbed)&&null!=this._toolPos&&this._modifier||(this._toolPos=a.screenToWorld(this._mouseX,this._mouseY))}},{key:"getToolRadius",value:function(a,b,c){return"add"==this.type?(new Hole(0,0,0,0,this.mass,!0,!0)).getDisplayRadius(a,c.getPoleSizeFactor(),c.getPoleSizeDependOnZoom()):0}},{key:"getToolPosition",value:function(a,b){return"move"==this.type&&null!=this._grabbed?{x:this._grabbed.posX,y:this._grabbed.posY}:this._toolPos}},{key:"getToolLine",
value:function(a,b){if(("add"==this.type||"move"==this.type&&null!=this._grabbed)&&this._modifier){var c=this.getToolPosition(a,b),f=a.screenToWorld(this._mouseX,this._mouseY);return{x0:c.x,y0:c.y,x1:f.x,y1:f.y,width:10/a.zoom}}return null}},{key:"getToolColor",value:function(a,b){return"move"==this.type&&null!=this._grabbed?0<=this._grabbed.mass?16711680:65535:0<=this.mass?16711680:65535}}]);return d}(Tool),ParticleTool=function(n){function d(){_classCallCheck(this,d);var a=e.call(this);a.radius=
20;a.amount=9E4;a.randomVelocity=5;a.color="#fff";a._modifier=!1;a._draw=!1;a._drawPos=null;a._drawAmount=0;a._mouseX=0;a._mouseY=0;a._mouseWorldPos=null;return a}_inherits(d,n);var e=_createSuper(d);_createClass(d,[{key:"mouseDown",value:function(a,b,c,f){this._mouseX=a.clientX;this._mouseY=a.clientY;0==a.button&&(this._draw=!0)}},{key:"mouseMove",value:function(a,b,c){this._mouseX=a.clientX;this._mouseY=a.clientY}},{key:"mouseUp",value:function(a,b,c){this._mouseX=a.clientX;this._mouseY=a.clientY;
0==a.button&&(this._draw=!1)}},{key:"modifierDown",value:function(a){this._modifier=!0}},{key:"modifierUp",value:function(a){this._modifier=!1}},{key:"_spawnParticles",value:function(a,b,c,f,l,m,g,k,h,p,r,u,x){for(var v=[],q=0;q<p;++q){var t=Math.random(),w=Math.random()*Math.PI*2,y=Math.random()*r,z=Math.random()*Math.PI*2,A=Math.random()*u;v.push(b+(f-b)*t+Math.cos(w)*y,c+(l-c)*t+Math.sin(w)*y,m+(k-m)*t+Math.cos(z)*A,g+(h-g)*t+Math.sin(z)*A)}a.createParticles(p,v,x)}},{key:"update",value:function(a,
b,c){var f=this._drawPos,l=this._mouseWorldPos;this._mouseWorldPos=b.screenToWorld(this._mouseX,this._mouseY);null!=this._drawPos&&this._modifier||(this._drawPos=this._mouseWorldPos);if(this._draw&&null!=f&&null!=l){var m=0,g=0;this._modifier&&(m=l.x-f.x,g=l.y-f.y);var k=l=0;this._modifier&&(l=this._mouseWorldPos.x-this._drawPos.x,k=this._mouseWorldPos.y-this._drawPos.y);this._drawAmount+=this.amount*a;a=Math.floor(this._drawAmount);this._drawAmount-=a;this._spawnParticles(c,f.x,f.y,this._drawPos.x,
this._drawPos.y,m,g,l,k,a,this.radius/b.zoom,this.randomVelocity/b.zoom,this.color)}else this._drawAmount=0}},{key:"getToolPosition",value:function(a,b){return this._drawPos}},{key:"getToolLine",value:function(a,b){if(this._modifier){var c=a.screenToWorld(this._mouseX,this._mouseY);return{x0:this._drawPos.x,y0:this._drawPos.y,x1:c.x,y1:c.y,width:10/a.zoom}}return null}},{key:"getToolRadius",value:function(a,b,c){return this.radius/a.zoom}}]);return d}(Tool),EditorTab=function(n){function d(a,b,c,
f,l,m,g,k){_classCallCheck(this,d);var h=e.call(this,a);h._graphics=b;h._camera=f;h._scene=new THREE.Group;h._scene.visible=!1;h._graphics.scene.add(h._scene);h._createButtons=[];h._currentScenario=null;h._elementListButtons=[];h._selectedElement=null;h._isEditing=!1;h._previousBackgroundColor=null;h._mouseX=0;h._mouseY=0;h._isDragging=!1;h._grabbed=null;h._createdElement=null;h._createTitle("Scenario editor");h._editRunButton=h._createButton("Edit",function(){h._isEditing?h._beginRun(m,f,l,g):h._beginEdit()});
h._editRunButton.children[0].style.margin="16px 16px 4px 16px";h._createButton("Recenter camera",function(){f.reset()}).children[0].style.margin="4px 16px";h._createButton("Export / Import",function(){k.showImportExportDialog(_assertThisInitialized(h),m,f,l,g)}).children[0].style.margin="4px 16px 16px 16px";h._editingDiv=h._createDiv();h._editingDiv.style.display="none";h._createHorizontalLine(h._editingDiv);h._createTitle("Scenario settings",h._editingDiv);h._globalGravitySlider=h._createSlider("Global gravity",
0,500,1,0,function(p){h._currentScenario.gravity=parseFloat(p)},null,h._editingDiv);h._globalGravitySlider.children[1].addEventListener("change",function(){h._onScenarioModified()});h._particleInfluenceSlider=h._createSlider("Particle influence",0,10,.05,1,function(p){h._currentScenario.particleInfluence=parseFloat(p)},function(p,r){p.textContent="Particle influence: "+Math.round(100*r)+"%"},h._editingDiv);h._particleInfluenceSlider.children[1].addEventListener("change",function(){h._onScenarioModified()});
h._poleInfluenceSlider=h._createSlider("Pole influence",0,1E4,10,1E3,function(p){h._currentScenario.holesGravity=parseFloat(p)*parseFloat(p)},function(p,r){p.textContent="Pole influence: "+r*r/1E4+"%"},h._editingDiv);h._poleInfluenceSlider.children[1].addEventListener("change",function(){h._onScenarioModified()});h._createHorizontalLine(h._editingDiv);h._createTitle("Create",h._editingDiv);h._initCreateButtons(h._editingDiv);h._createHorizontalLine(h._editingDiv);h._elementProperties=h._createDiv(h._editingDiv);
h._createTitle("Elements",h._editingDiv);h._scenarioElementsDiv=h._createDiv(h._editingDiv);h._createEmptyLine(h._editingDiv);c.addEventListener("pointerdown",function(p){if(h._isOpen&&0==p.button){if(null==h._createdElement){p=f.screenToWorld(p.clientX,p.clientY);for(var r=0;r<h._currentScenario.elements.length;++r){var u=h._currentScenario.elements[r];if(u.isWithin(p.x,p.y)){f.disableMouseMovement();h._grabbed={element:u,x:p.x-u.posX,y:p.y-u.posY};h._showElementProperties(u);break}}}h._isDragging=
!1}});window.addEventListener("pointermove",function(p){h._mouseX=p.clientX;h._mouseY=p.clientY;h._isDragging=!0});window.addEventListener("pointerup",function(p){0==p.button&&(null!=h._grabbed?h._releaseGrabbedElement():null!=h._createdElement?(p=h._createdElement,h._createdElement=null,h._currentScenario.addElement(p),h._showElementProperties(p),h._refreshElementsList(),h._refreshCreateButtons(),h._onScenarioModified()):h._isDragging||h._hideElementProperties())});window.addEventListener("keydown",
function(p){if(27==p.keyCode||"Escape"==p.code)null!=h._grabbed?h._releaseGrabbedElement():null!=h._createdElement?h._cancelCreatingElement():h._hideElementProperties();46!=p.keyCode&&"Delete"!=p.code||h._deleteSelectedElement()});return h}_inherits(d,n);var e=_createSuper(d);_createClass(d,[{key:"_beginRun",value:function(a,b,c,f){null!=this._grabbed&&this._releaseGrabbedElement();null!=this._createdElement&&this._cancelCreatingElement();this._editRunButton.children[0].textContent="Edit";this._editingDiv.style.display=
"none";this.refreshScrollbar();a.loadScenario(this._currentScenario,b,c,f);this._graphics.showParticlesAndPoles();null!=this._previousBackgroundColor&&(this._graphics.setBackgroundColor(this._previousBackgroundColor),this._previousBackgroundColor=null);this._isEditing=this._scene.visible=!1}},{key:"_beginEdit",value:function(){this._editRunButton.children[0].textContent="Run";this._editingDiv.style.display="block";this.refreshScrollbar();this._graphics.hideParticlesAndPoles();null==this._previousBackgroundColor&&
(this._previousBackgroundColor=this._graphics.getBackgroundColor(),this._graphics.setBackgroundColor(0));this._isEditing=this._scene.visible=!0}},{key:"isEditing",get:function(){return this._isEditing}},{key:"_onScenarioModified",value:function(){this._currentScenario.setAsWindowQueryString()}},{key:"_initCreateButtons",value:function(a){for(var b=this,c=Scenario.getElementTypesList(),f=function(m){var g=c[m];m=b._createButton(g.getEditorName()+" +",function(){b._startCreatingElement(new g)},a);m.children[0].style.margin=
"4px 16px";b._createButtons.push({elementType:g,button:m.children[0]})},l=0;l<c.length;++l)f(l);this._refreshCreateButtons()}},{key:"_refreshCreateButtons",value:function(){for(var a=0;a<this._createButtons.length;++a){var b=this._createButtons[a].elementType,c=this._createButtons[a].button;if(null==this._currentScenario)c.disabled=!1;else if(128<=this._currentScenario.elements.length)c.disabled=!0;else if(b==ScenarioHole){for(var f=b=0;f<this._currentScenario.elements.length;++f)this._currentScenario.elements[f]instanceof
ScenarioHole&&++b;c.disabled=50<=b?!0:!1}else c.disabled=!1}}},{key:"_getElementName",value:function(a){for(var b=1,c=a.getEditorName(),f=0;f<this._currentScenario.elements.length;++f){var l=this._currentScenario.elements[f];if(l.getEditorName()==c)if(l==a)break;else++b}return c+" #"+b}},{key:"_startCreatingElement",value:function(a){this._cancelCreatingElement();this._createdElement=a;this._createdElement.updateMesh(this._scene);this._createdElement.updateSelectionMesh(this._scene);this._showElementProperties(this._createdElement)}},
{key:"_cancelCreatingElement",value:function(){null!=this._createdElement&&(this._selectedElement==this._createdElement&&this._hideElementProperties(),this._createdElement.disposeMesh(),this._createdElement.disposeSelectionMesh(),this._createdElement=null)}},{key:"_releaseGrabbedElement",value:function(){null!=this._grabbed&&(this._showElementProperties(this._grabbed.element),this._camera.enableMouseMovement(),this._onScenarioModified(),this._grabbed=null)}},{key:"_deleteSelectedElement",value:function(){if(null!=
this._selectedElement){var a=this._selectedElement;this._hideElementProperties();this._currentScenario.deleteElement(a);a.disposeMesh();a.disposeSelectionMesh();this._refreshElementsList();this._refreshCreateButtons();this._onScenarioModified();null!=this._grabbed&&a==this._grabbed.element&&(this._camera.enableMouseMovement(),this._grabbed=null)}}},{key:"update",value:function(a){this._isOpen?(null!=this._grabbed&&(a=this._camera.screenToWorld(this._mouseX,this._mouseY),this._grabbed.element.posX=
Math.round(a.x-this._grabbed.x),this._grabbed.element.posY=Math.round(a.y-this._grabbed.y),this._grabbed.element.refreshPosition()),null!=this._createdElement&&(a=this._camera.screenToWorld(this._mouseX,this._mouseY),this._createdElement.posX=Math.round(a.x),this._createdElement.posY=Math.round(a.y),this._createdElement.refreshPosition())):(this._camera.enableMouseMovement(),this._grabbed=null)}},{key:"setScenario",value:function(a){if(a.constructor!=Scenario)throw"Scenario is not a Scenario object";
null!=this._currentScenario&&(this._currentScenario.disposeElementMeshes(),this._currentScenario=null);this._selectedElement=null;this._currentScenario=a;this._currentScenario.updateElementMeshes(this._scene);this._refreshElementsList();this._hideElementProperties();this._refreshCreateButtons();this._onScenarioModified();this._globalGravitySlider.children[1].value=this._currentScenario.gravity;this._globalGravitySlider.children[1].onchange();this._particleInfluenceSlider.children[1].value=this._currentScenario.particleInfluence;
this._particleInfluenceSlider.children[1].onchange();this._poleInfluenceSlider.children[1].value=Math.sqrt(this._currentScenario.holesGravity);this._poleInfluenceSlider.children[1].onchange()}},{key:"_refreshElementsList",value:function(){var a=this;this._scenarioElementsDiv.innerHTML="";var b=new Map;this._elementListButtons.length=0;for(var c=function(l){var m=a._currentScenario.elements[l];l=m.getEditorName();if(b.has(l)){var g=b.get(l);b.set(l,g+1);l+=" #"+(g+1)}else b.set(l,1),l+=" #1";g=document.createElement("button");
m==a._selectedElement&&(g.className="selected");g.element=m;g.style.margin="4px 16px";g.textContent=l;g.onclick=function(){m==a._selectedElement?a._camera.setPosition(m.posX,m.posY):a._showElementProperties(m)};a._scenarioElementsDiv.appendChild(g);a._elementListButtons.push(g)},f=0;f<this._currentScenario.elements.length;++f)c(f);this.refreshScrollbar()}},{key:"_showElementProperties",value:function(a){var b=this;a!=this._createdElement&&this._cancelCreatingElement();null!=this._selectedElement&&
this._selectedElement.hideSelectionMesh();this._selectedElement=a;a.showSelectionMesh();for(var c=0;c<this._elementListButtons.length;++c)this._elementListButtons[c].className=this._elementListButtons[c].element==a?"selected":"";this._elementProperties.className="";this._elementProperties.innerHTML="";c=document.createElement("h1");c.textContent=this._getElementName(a);this._elementProperties.appendChild(c);a.createEditorPropertiesUI(this._elementProperties,function(){b._onScenarioModified()});c=
document.createElement("button");c.style.margin="16px 16px 4px 16px";c.textContent="Center view";this._createdElement==a&&(c.disabled=!0);c.addEventListener("click",function(){b._camera.setPosition(a.posX,a.posY)});this._elementProperties.appendChild(c);c=document.createElement("button");c.style.margin="4px 16px 4px 16px";c.textContent="Duplicate";this._createdElement==a&&(c.disabled=!0);c.addEventListener("click",function(){b._startCreatingElement(a.clone())});this._elementProperties.appendChild(c);
c=document.createElement("button");c.style.margin="4px 16px 16px 16px";c.textContent="Delete";c.addEventListener("click",function(){b._createdElement==a?b._cancelCreatingElement():b._deleteSelectedElement()});this._elementProperties.appendChild(c);c=document.createElement("div");c.className="line";this._elementProperties.appendChild(c);this.refreshScrollbar();this._elementProperties.scrollIntoView&&this._elementProperties.scrollIntoView({behavior:"smooth"})}},{key:"_hideElementProperties",value:function(){null!=
this._selectedElement&&this._selectedElement.hideSelectionMesh();this._selectedElement=null;for(var a=0;a<this._elementListButtons.length;++a)this._elementListButtons[a].className="";this._elementProperties.className="hidden";this._elementProperties.innerHTML="";this.refreshScrollbar()}},{key:"hide",value:function(){this._scene.visible=!1;this._graphics.showParticlesAndPoles();null!=this._previousBackgroundColor&&(this._graphics.setBackgroundColor(this._previousBackgroundColor),this._previousBackgroundColor=
null);_get(_getPrototypeOf(d.prototype),"hide",this).call(this)}},{key:"show",value:function(){if(this._scene.visible=this._isEditing)this._graphics.hideParticlesAndPoles(),null==this._previousBackgroundColor&&(this._previousBackgroundColor=this._graphics.getBackgroundColor(),this._graphics.setBackgroundColor(0));this._refreshElementsList();_get(_getPrototypeOf(d.prototype),"show",this).call(this)}},{key:"currentScenario",get:function(){return this._currentScenario}}]);return d}(TabUI),HolesTab=function(n){function d(a,
b,c,f){_classCallCheck(this,d);a=e.call(this,a);a._particleSystem=c;a._toolSystem=f;a._negativeMass=!1;var l=_assertThisInitialized(a),m=new HoleTool;a._tool=m;a._createTitle("Poles");var g=a._createThreeButtons('<img src="images/add.svg"><small>Add</small>',function(){m.type="add";g.children[0].className="selected";g.children[1].className="";g.children[2].className=""},'<img src="images/move.svg"><small>Move</small>',function(){m.type="move";g.children[0].className="";g.children[1].className="selected";
g.children[2].className=""},'<img src="images/delete.svg"><small>Delete</small>',function(){m.type="delete";g.children[0].className="";g.children[1].className="";g.children[2].className="selected"});g.children[0].className="selected";a._createSlider("Strength",0,1E3,10,100,function(k){m.mass=l._negativeMass?-(k*k*k):k*k*k},function(k,h){k.innerHTML="Strength: "+digitSeparated(h*h*h,0)});a._createCheckBox("Negative pole",!1,function(k){l._negativeMass=k;m.mass=l._negativeMass?-Math.abs(m.mass):Math.abs(m.mass)});
a._createCheckBox("Affected by other poles",!1,function(k){m.isAffectedByGravity=k});a._createCheckBox("Pulls other poles",!0,function(k){m.hasGravitationalPull=k});a._createText("Use the Shift key to spawn poles with an initial velocity<br><br>");a._createHorizontalLine();a._createButton("Clear poles",function(){c.holes.length=0});a._holesAmountText=a._createText("");a._lastAmount=null;a._createEmptyLine();return a}_inherits(d,n);var e=_createSuper(d);_createClass(d,[{key:"update",value:function(a){this._particleSystem.holes.length!=
this._lastAmount&&(this._holesAmountText.innerHTML="Poles: "+this._particleSystem.holes.length+" / "+this._particleSystem.maxHoles,this._lastAmount=this._particleSystem.holes.length)}},{key:"hide",value:function(){this._toolSystem.setTool(null);_get(_getPrototypeOf(d.prototype),"hide",this).call(this)}},{key:"show",value:function(){this._toolSystem.setTool(this._tool);_get(_getPrototypeOf(d.prototype),"show",this).call(this)}}]);return d}(TabUI),ParticleTab=function(n){function d(a,b,c,f){_classCallCheck(this,
d);a=e.call(this,a);a._graphics=b;a._particleSystem=c;a._toolSystem=f;var l=_assertThisInitialized(a),m=new ParticleTool;a._tool=m;a._createTitle("Particles");a._createSlider("Radius",5,200,5,20,function(h){m.radius=h});a._createSlider("Amount",10,1E3,10,300,function(h){m.amount=h*h},function(h,p){h.innerHTML="Amount: "+digitSeparated(p*p,0)});a._createSlider("Random velocity",0,100,1,5,function(h){m.randomVelocity=h},function(h,p){h.innerHTML="Random velocity: "+digitSeparated(p,0)});a._createText("Use the Shift key to spawn particles with an initial velocity<br>");
var g=a._createTitle("Color"),k=a._createColorPicker(function(h){m.color=h;b.setColorTheme(3)});g.style.opacity=.5;k.style.opacity=.5;b.addColorThemeEventListener(function(h){3==h?(g.style.opacity=1,k.style.opacity=1):(g.style.opacity=.5,k.style.opacity=.5)});a._createText("Reminder: Select multicolor in the particle color section in the options tab to see the colors<br><br>");a._createHorizontalLine();a._createButton("Clear particles",function(){l._particleSystem.clear()});a._particleAmountText=
a._createText("");a._lastAmount=null;a._lastMaxAmount=null;a._createEmptyLine();return a}_inherits(d,n);var e=_createSuper(d);_createClass(d,[{key:"update",value:function(a){if(this._particleSystem.amount!=this._lastAmount||this._particleSystem.maxAmount!=this._lastMaxAmount)this._particleAmountText.innerHTML="Particles: "+digitSeparated(this._particleSystem.amount)+" / "+digitSeparated(this._particleSystem.maxAmount),this._lastAmount=this._particleSystem.amount,this._lastMaxAmount=this._particleSystem.maxAmount}},
{key:"hide",value:function(){this._toolSystem.setTool(null);_get(_getPrototypeOf(d.prototype),"hide",this).call(this)}},{key:"show",value:function(){this._toolSystem.setTool(this._tool);_get(_getPrototypeOf(d.prototype),"show",this).call(this)}}]);return d}(TabUI),ScenarioTab=function(n){function d(a,b,c,f,l,m,g){_classCallCheck(this,d);a=e.call(this,a);a._editorTab=b;a._settingsTab=c;a._graphics=f;a._camera=l;a._particleSystem=m;a._loading=g;a._scenarios=[];a._defaultScenario=null;a._createTitle("Scenarios");
a._createHorizontalLine();a._scenarioImages=new Image;a._createScenarios();a._scenarioImages.src="images/scenarios.png";try{var k=window.location.search}catch(h){k=""}0==k.indexOf("?")&&(k="&"+k.substr(1));-1!=k.indexOf("&load=")?(k=k.substr(k.indexOf("&load=")+6),f=-1!=k.indexOf("&")?k.substr(0,k.indexOf("&")):k,k=new Scenario,k.setSaveString(f)?(m.loadScenario(k,l,c,g),b.setScenario(k),f=!1):f=!0):f=!0;f&&(m.loadScenario(a._defaultScenario(),l,c,g),b.setScenario(a._defaultScenario()));return a}
_inherits(d,n);var e=_createSuper(d);_createClass(d,[{key:"_createScenarios",value:function(){this._addScenario("Empty",function(){return new Scenario});this._addScenario("Stable orbits",function(){var a=new Scenario;a.previewOpacity=.02;a.previewSize=475;a.addHole(0,0,0,0,1E6,!1);a.addElement(new ScenarioRing(0,0,100,400,0,0,1E6));return a});this._addScenario("Encounter",this._defaultScenario=function(){var a=new Scenario;a.previewTime=7;a.previewOpacity=.02;a.previewSize=1600;a.addHole(-500,-100,
100,0,1E6,!0);a.addElement(new ScenarioRing(-500,-100,100,300,100,0,1E6));a.addHole(500,100,-100,0,1E6,!0);a.addElement(new ScenarioRing(500,100,100,300,-100,0,1E6));return a});this._addScenario("Encounter 2",function(){var a=new Scenario;a.previewTime=5;a.previewOpacity=.02;a.previewSize=1400;a.addHole(-500,-100,100,0,1E6,!0);a.addElement(new ScenarioRing(-500,-100,100,300,100,0,1E6));a.addHole(500,100,-100,0,1E6,!0);a.addElement(new ScenarioRing(500,100,100,300,-100,0,1E6));a.addHole(100,-500,0,
100,1E6,!0);a.addElement(new ScenarioRing(100,-500,100,300,0,100,1E6));a.addHole(-100,500,0,-100,1E6,!0);a.addElement(new ScenarioRing(-100,500,100,300,0,-100,1E6));return a});this._addScenario("Encounter negative",function(){var a=new Scenario;a.previewTime=8;a.previewX=400;a.previewY=0;a.previewOpacity=.02;a.previewSize=1E3;a.addHole(-500,-100,100,0,1E6,!0);a.addElement(new ScenarioRing(-500,-100,100,300,100,0,1E6));a.addHole(500,100,-100,0,-1E5,!0);return a});this._addScenario("Encounter negative 2",
function(){var a=new Scenario;a.previewTime=7;a.previewOpacity=.02;a.previewSize=1900;a.addHole(-500,-100,100,0,-1E5,!0);a.addHole(500,100,-100,0,-1E5,!0);a.addHole(100,-500,0,100,1E6,!0);a.addElement(new ScenarioRing(100,-500,100,300,0,100,1E6));a.addHole(-100,500,0,-100,1E6,!0);a.addElement(new ScenarioRing(-100,500,100,300,0,-100,1E6));return a});this._addScenario("Grid",function(){var a=new Scenario;a.previewTime=8;a.previewOpacity=.01;a.previewSize=800;for(var b=-1;1>=b;++b)for(var c=-1;1>=c;++c)0!=
b&&0!=c?a.addHole(100*b,100*c,0,0,-1E6,!1):a.addHole(100*b,100*c,0,0,1E6,!1);a.addElement(new ScenarioRing(0,0,600,700,0,0,0,!0));return a});this._addScenario("Spinning around grid",function(){var a=new Scenario;a.previewTime=10.5;a.previewOpacity=.06;a.previewSize=1E3;for(var b=-1;1>=b;++b)for(var c=-1;1>=c;++c)0!=b&&0!=c?a.addHole(100*b,100*c,0,0,-1E6,!1):a.addHole(100*b,100*c,0,0,1E6,!1);a.addElement(new ScenarioRing(0,0,600,700,0,0,5E5,!1));return a});this._addScenario("Tidal force",function(){var a=
new Scenario;a.previewTime=15.5;a.previewX=-300;a.previewY=-110;a.previewOpacity=.02;a.previewSize=1E3;a.addHole(0,0,0,0,2E6,!1);a.addElement(new ScenarioOval(-300,-250,100,100,0,25,0,!0));return a});this._addScenario("Tidal force 2",function(){var a=new Scenario;a.previewTime=20;a.previewOpacity=.01;a.previewSize=1100;a.addHole(0,0,0,0,1E6,!1);a.addElement(new ScenarioOval(250,0,100,100,0,0,Math.sqrt(4E3)));a.addElement(new ScenarioOval(-250,0,100,100,0,0,-Math.sqrt(4E3)));a.addElement(new ScenarioOval(0,
250,100,100,0,-Math.sqrt(4E3),0));a.addElement(new ScenarioOval(0,-250,100,100,0,Math.sqrt(4E3),0));return a});this._addScenario("Collision",function(){var a=new Scenario;a.previewTime=4;a.previewX=350;a.previewY=0;a.previewOpacity=.02;a.previewSize=450;a.addHole(-200,0,100,0,1E6,!1);a.addElement(new ScenarioOval(0,0,100,100,0,0,0,!0));return a});this._addScenario("Cut",function(){var a=new Scenario;a.previewTime=2.25;a.previewX=50;a.previewY=0;a.previewOpacity=.02;a.previewSize=800;a.addHole(-1200,
0,1E3,0,-5E5,!1);a.addElement(new ScenarioOval(0,0,100,100,0,0,0,!0));return a});this._addScenario("Two orbiting rings",function(){var a=new Scenario;a.previewTime=20;a.previewOpacity=.01;a.previewSize=2700;a.addHole(0,-200,-Math.sqrt(2500),0,1E6,!0);a.addHole(0,200,Math.sqrt(2500),0,1E6,!0);a.addElement(new ScenarioRing(0,-200,100,350,-Math.sqrt(2500),0,1E6));a.addElement(new ScenarioRing(0,200,100,350,Math.sqrt(2500),0,1E6));return a});this._addScenario("Three orbiting rings",function(){var a=new Scenario;
a.previewTime=8;a.previewOpacity=.015;a.previewSize=1400;for(var b=0;3>b;++b){var c=2*Math.PI/3*b,f=200*Math.cos(c),l=200*Math.sin(c),m=Math.cos(c-Math.PI/2)*Math.sqrt(5E3);c=Math.sin(c-Math.PI/2)*Math.sqrt(5E3);a.addHole(f,l,m,c,1E6,!0);a.addElement(new ScenarioRing(f,l,100,350,m,c,1E6))}return a});this._addScenario("Two orbiting poles",function(){var a=new Scenario;a.previewTime=11.25;a.previewOpacity=.015;a.previewSize=900;a.addHole(0,-100,-Math.sqrt(5E3),0,1E6,!0);a.addHole(0,100,Math.sqrt(5E3),
0,1E6,!0);a.addElement(new ScenarioOval(0,0,4,4));return a});this._addScenario("Three orbiting poles",function(){var a=new Scenario;a.previewTime=6.5;a.previewOpacity=.03;a.previewSize=1600;for(var b=0;3>b;++b){var c=2*Math.PI/3*b;a.addHole(100*Math.cos(c),100*Math.sin(c),Math.cos(c-Math.PI/2)*Math.sqrt(1E4),Math.sin(c-Math.PI/2)*Math.sqrt(1E4),1E6,!0)}a.addElement(new ScenarioOval(0,0,4,4));return a});this._addScenario("Moon",function(){var a=new Scenario;a.previewTime=58.5;a.previewX=200;a.previewY=
1E3;a.previewOpacity=.015;a.previewSize=3500;a.addHole(0,500,Math.sqrt(4E3),0,1E6,!0);a.addHole(0,0,0,0,1E6,!1);a.addElement(new ScenarioRing(0,0,100,500,0,0,1E6));return a});this._addScenario("Moon with ring",function(){var a=new Scenario;a.previewTime=30;a.previewX=100;a.previewY=-100;a.previewOpacity=.01;a.previewSize=1400;a.addHole(0,500,Math.sqrt(4E3),0,1E6,!0);a.addElement(new ScenarioRing(0,500,100,500,Math.sqrt(4E3),0,1E6));a.addHole(0,0,0,0,1E6,!1);return a});this._addScenario("Moon inside ring",
function(){var a=new Scenario;a.previewTime=10;a.previewX=-50;a.previewY=0;a.previewOpacity=.01;a.previewSize=1E3;a.addHole(0,200,-Math.sqrt(1E4),0,1E6,!0);a.addHole(0,0,0,0,1E6,!1);a.addElement(new ScenarioRing(0,0,700,1E3,0,0,1E6));return a});this._addScenario("Two moons",function(){var a=new Scenario;a.previewTime=38;a.previewSize=3E3;a.previewOpacity=.02;a.addHole(0,500,Math.sqrt(4E3),0,1E6,!0);a.addHole(0,-500,-Math.sqrt(4E3),0,1E6,!0);a.addHole(0,0,0,0,1E6,!1);a.addElement(new ScenarioRing(0,
0,100,500,0,0,1E6));return a});this._addScenario("Two negative moons",function(){var a=new Scenario;a.previewTime=20;a.previewSize=3500;a.previewOpacity=.02;a.addHole(0,500,Math.sqrt(4E3),0,-1E6,!0);a.addHole(0,-500,-Math.sqrt(4E3),0,-1E6,!0);a.addHole(0,0,0,0,1E6,!1);a.addElement(new ScenarioRing(0,0,100,500,0,0,1E6));return a});this._addScenario("Orbiters in ring",function(){var a=new Scenario;a.previewTime=5;a.previewOpacity=.015;a.previewSize=900;a.addHole(0,-100,-Math.sqrt(5E3),0,1E6,!0);a.addHole(0,
100,Math.sqrt(5E3),0,1E6,!0);a.addElement(new ScenarioRing(0,0,400,800,0,0,2E6));return a});this._addScenario("Eccentric orbits",function(){var a=new Scenario;a.previewTime=10;a.previewOpacity=.01;a.previewSize=2800;a.addHole(0,-200,20,0,1E6,!0);a.addHole(0,200,-20,0,1E6,!0);a.addElement(new ScenarioRing(0,-200,100,350,20,0,1E6));a.addElement(new ScenarioRing(0,200,100,350,-20,0,1E6));return a});this._addScenario("Symmetry",function(){var a=new Scenario;a.previewTime=10;a.previewY=-25;a.previewOpacity=
.02;a.previewSize=500;a.addHole(-100,0,0,0,1E6,!1);a.addHole(100,0,0,0,1E6,!1);a.addElement(new ScenarioOval(0,200,100,100,0,0,0));return a});this._addScenario("Symmetry 2",function(){var a=new Scenario;a.previewTime=10;a.previewOpacity=.015;a.previewSize=650;a.addHole(-150,-200,0,0,1E6,!1);a.addHole(150,-200,0,0,1E6,!1);a.addHole(-150,200,0,0,1E6,!1);a.addHole(150,200,0,0,1E6,!1);a.addElement(new ScenarioOval(0,0,100,100,0,0,0));return a});this._addScenario("Symmetry 3",function(){var a=new Scenario;
a.previewTime=5;a.previewOpacity=.015;a.previewSize=650;a.addHole(0,-200,0,0,1E6,!1);a.addHole(0,200,0,0,1E6,!1);a.addHole(-200,0,0,0,-2E6,!1);a.addHole(200,0,0,0,-2E6,!1);a.addElement(new ScenarioOval(0,0,100,100,0,0,0));return a});this._addScenario("Drop two",function(){var a=new Scenario;a.previewTime=9;a.previewOpacity=.01;a.previewSize=650;for(var b=0;2>b;++b){var c=b/2*Math.PI*2-Math.PI/2;a.addHole(150*Math.cos(c),150*Math.sin(c),0,0,1E6,!1)}for(b=0;2>b;++b)c=b/2*Math.PI*2+Math.PI/2-Math.PI/
2,a.addElement(new ScenarioOval(200*Math.cos(c),200*Math.sin(c),50,50,0,0,0));return a});this._addScenario("Drop three",function(){var a=new Scenario;a.previewTime=5;a.previewOpacity=.01;a.previewSize=650;for(var b=0;3>b;++b){var c=b/3*Math.PI*2-Math.PI/2;a.addHole(150*Math.cos(c),150*Math.sin(c),0,0,1E6,!1)}for(b=0;3>b;++b)c=b/3*Math.PI*2+Math.PI/3-Math.PI/2,a.addElement(new ScenarioOval(200*Math.cos(c),200*Math.sin(c),50,50,0,0,0));return a});this._addScenario("Drop six",function(){var a=new Scenario;
a.previewTime=1.5;a.previewOpacity=.01;a.previewSize=500;for(var b=0;6>b;++b){var c=b/6*Math.PI*2-Math.PI/2;a.addHole(150*Math.cos(c),150*Math.sin(c),0,0,1E6,!1)}for(b=0;6>b;++b)c=b/6*Math.PI*2+Math.PI/6-Math.PI/2,a.addElement(new ScenarioOval(200*Math.cos(c),200*Math.sin(c),50,50,0,0,0));return a});this._addScenario("Birds",function(){var a=new Scenario;a.previewTime=15;a.previewOpacity=.01;a.previewSize=700;for(var b=0;6>b;++b){var c=b/6*Math.PI*2-Math.PI/2,f=100*Math.cos(c);c=100*Math.sin(c);0==
b%2?a.addHole(f,c,0,0,1E6,!1):a.addHole(f,c,0,0,-1E6,!1)}for(b=0;6>b;++b)f=b/6*Math.PI*2+Math.PI/6-Math.PI/2,a.addElement(new ScenarioOval(300*Math.cos(f),300*Math.sin(f),50,50,0,0,0));return a});this._addScenario("Flower six",function(){var a=new Scenario;a.previewTime=7;a.previewOpacity=.02;a.previewSize=650;for(var b=0;6>b;++b){var c=b/6*Math.PI*2;a.addHole(250*Math.cos(c),250*Math.sin(c),0,0,1E6,!1)}a.addElement(new ScenarioOval(0,0,100,100,0,0,0));return a});this._addScenario("Flower twelve",
function(){var a=new Scenario;a.previewTime=4;a.previewOpacity=.015;a.previewSize=700;for(var b=0;12>b;++b){var c=b/12*Math.PI*2;a.addHole(250*Math.cos(c),250*Math.sin(c),0,0,1E6,!1)}a.addElement(new ScenarioOval(0,0,100,100,0,0,0));return a});this._addScenario("Exploding flower",function(){var a=new Scenario;a.previewTime=4.25;a.previewOpacity=.02;a.previewSize=900;for(var b=0;6>b;++b){var c=b/6*Math.PI*2;a.addHole(250*Math.cos(c),250*Math.sin(c),0,0,1E6,!1)}a.addHole(0,0,0,0,-2E5,!1);a.addElement(new ScenarioOval(0,
0,100,100,0,0,0));return a});this._addScenario("Bowl",function(){var a=new Scenario;a.previewTime=48;a.previewOpacity=.02;a.previewSize=900;a.gravity=125;for(var b=0;8>b;++b){var c=Math.PI+b/7*Math.PI;a.addHole(300*Math.cos(c),300*Math.sin(c),0,0,-25E5,!1)}a.addHole(-320,200,0,0,-2E6,!1);a.addHole(320,200,0,0,-2E6,!1);a.addElement(new ScenarioOval(0,200,400,100));return a});this._addScenario("Crushing six",function(){var a=new Scenario;a.previewTime=5.5;a.previewOpacity=.15;a.previewSize=900;a.holesGravity=
1E4;for(var b=0;6>b;++b){var c=b/6*Math.PI*2;a.addHole(100*Math.cos(c),100*Math.sin(c),0,0,-1E6,!0)}a.addElement(new ScenarioRectangle(0,0,100,100,0,0,0,!0));return a});this._addScenario("Crushing eight",function(){var a=new Scenario;a.previewTime=4.5;a.previewOpacity=.15;a.previewSize=900;a.holesGravity=1E4;for(var b=0;8>b;++b){var c=b/8*Math.PI*2;a.addHole(100*Math.cos(c),100*Math.sin(c),0,0,-1E6,!0)}a.addElement(new ScenarioRectangle(0,0,100,100,0,0,0,!0));return a});this._addScenario("Crushing ring",
function(){var a=new Scenario;a.previewTime=6;a.previewOpacity=.015;a.previewSize=1600;a.holesGravity=1E4;a.addHole(0,0,0,0,1E6,!1);for(var b=0;8>b;++b){var c=b/8*Math.PI*2;a.addHole(400*Math.cos(c),400*Math.sin(c),50*Math.cos(c+Math.PI),50*Math.sin(c+Math.PI),-1E6,!0)}a.addElement(new ScenarioRing(0,0,100,600,0,0,1E6));return a});this._addScenario("Crushing spinning",function(){var a=new Scenario;a.previewTime=15;a.previewOpacity=.015;a.previewSize=1600;a.holesGravity=2E4;for(var b=0;6>b;++b){var c=
b/6*Math.PI*2;a.addHole(200*Math.cos(c),200*Math.sin(c),10*Math.cos(c+Math.PI/2),10*Math.sin(c+Math.PI/2),-1E6,!0)}a.addElement(new ScenarioOval(0,0,200,200));return a});this._addScenario("Magnetosphere",function(){var a=new Scenario;a.previewTime=15;a.previewX=25;a.previewSize=600;a.addHole(0,0,0,0,-1E6,!1);a.addElement(new ScenarioRectangleLines(-3E3,0,5E3,3E3,300,0,300,0,!0));return a});this._addScenario("Magnetosphere three",function(){var a=new Scenario;a.previewTime=15;a.previewX=25;a.previewSize=
600;a.addHole(0,0,0,0,-1E6,!1);a.addHole(100,-122,0,0,-1E6,!1);a.addHole(100,122,0,0,-1E6,!1);a.addElement(new ScenarioRectangleLines(-3E3,0,5E3,3E3,300,0,300,0,!0));return a});this._addScenario("Umbrella",function(){var a=new Scenario;a.previewTime=8;a.previewY=-200;a.previewOpacity=.1;a.previewSize=1E3;a.gravity=50;a.addHole(0,50,0,0,-1E6,!1);a.addHole(-50,35,0,0,-1E6,!1);a.addHole(-100,0,0,0,-1E6,!1);a.addHole(50,35,0,0,-1E6,!1);a.addHole(100,0,0,0,-1E6,!1);a.addHole(0,-300,0,0,1E7,!1);a.addElement(new ScenarioRectangleLines(0,
3E3,5E3,3E3,300,Math.PI/2,0,0,!0));return a});this._addScenario("Rings",function(){var a=new Scenario;a.previewSize=475;a.addHole(0,0,0,0,1E6,!1);a.addElement(new ScenarioRingRainbowSegments(0,0,100,400,12,0,0,1E6));return a});this._addScenario("Contained",function(){var a=new Scenario;a.previewTime=50;a.previewOpacity=.01;a.previewSize=800;a.addHole(0,0,0,0,1E6,!1);a.addHole(-400,0,0,0,-1E6,!1);a.addHole(-400/Math.SQRT2,-400/Math.SQRT2,0,0,-1E6,!1);a.addHole(0,-400,0,0,-1E6,!1);a.addHole(400/Math.SQRT2,
-400/Math.SQRT2,0,0,-1E6,!1);a.addHole(400,0,0,0,-1E6,!1);a.addHole(400/Math.SQRT2,400/Math.SQRT2,0,0,-1E6,!1);a.addHole(0,400,0,0,-1E6,!1);a.addHole(-400/Math.SQRT2,400/Math.SQRT2,0,0,-1E6,!1);a.addElement(new ScenarioRing(0,0,100,400,0,0,1E6));return a});this._addScenario("Contained rings",function(){var a=new Scenario;a.previewTime=130;a.previewSize=800;a.addHole(0,0,0,0,1E6,!1);a.addHole(-400,0,0,0,-1E6,!1);a.addHole(-400/Math.SQRT2,-400/Math.SQRT2,0,0,-1E6,!1);a.addHole(0,-400,0,0,-1E6,!1);a.addHole(400/
Math.SQRT2,-400/Math.SQRT2,0,0,-1E6,!1);a.addHole(400,0,0,0,-1E6,!1);a.addHole(400/Math.SQRT2,400/Math.SQRT2,0,0,-1E6,!1);a.addHole(0,400,0,0,-1E6,!1);a.addHole(-400/Math.SQRT2,400/Math.SQRT2,0,0,-1E6,!1);a.addElement(new ScenarioRingRainbowSegments(0,0,100,400,12,0,0,1E6));return a});this._addScenario("Swing",function(){var a=new Scenario;a.previewTime=6.9;a.previewOpacity=.01;a.previewSize=1600;a.addHole(0,0,0,0,1E6,!1,!0);a.addHole(-200,-500,0,50,1E6,!0,!1);a.addElement(new ScenarioRing(-200,-500,
50,200,0,50,1E6,!1));a.addHole(200,-500,0,50,1E6,!0,!1);a.addElement(new ScenarioRing(200,-500,50,200,0,50,1E6,!0));return a});this._addScenario("Swing negative",function(){var a=new Scenario;a.previewTime=4.5;a.previewOpacity=.01;a.previewSize=1600;a.addHole(0,0,0,0,-1E6,!1,!0);a.addHole(-200,-300,0,50,1E6,!0,!1);a.addElement(new ScenarioRing(-200,-300,50,200,0,50,1E6,!1));a.addHole(200,-300,0,50,1E6,!0,!1);a.addElement(new ScenarioRing(200,-300,50,200,0,50,1E6,!0));return a});this._addScenario("Blender two",
function(){var a=new Scenario;a.previewTime=5;a.previewOpacity=.01;a.previewSize=2900;a.addHole(0,0,0,0,1E6,!1,!0);for(var b=0;b<2*Math.PI;b+=Math.PI){var c=Math.cos(b),f=Math.sin(b);a.addHole(100*c,100*f,f*Math.sqrt(2E4),-c*Math.sqrt(2E4),1E6,!0,!1)}a.addElement(new ScenarioOval(250,0,200,50,0,0,Math.sqrt(4E3),!0));a.addElement(new ScenarioOval(-250,0,200,50,0,0,-Math.sqrt(4E3),!0));a.addElement(new ScenarioOval(0,250,50,200,0,-Math.sqrt(4E3),0,!0));a.addElement(new ScenarioOval(0,-250,50,200,0,
Math.sqrt(4E3),0,!0));return a});this._addScenario("Blender four",function(){var a=new Scenario;a.previewTime=5;a.previewOpacity=.01;a.previewSize=3E3;a.addHole(0,0,0,0,1E6,!1,!0);for(var b=0;b<2*Math.PI;b+=Math.PI/2){var c=Math.cos(b),f=Math.sin(b);a.addHole(100*c,100*f,f*Math.sqrt(2E4),-c*Math.sqrt(2E4),1E6,!0,!1)}a.addElement(new ScenarioOval(250,0,200,50,0,0,Math.sqrt(4E3),!0));a.addElement(new ScenarioOval(-250,0,200,50,0,0,-Math.sqrt(4E3),!0));a.addElement(new ScenarioOval(0,250,50,200,0,-Math.sqrt(4E3),
0,!0));a.addElement(new ScenarioOval(0,-250,50,200,0,Math.sqrt(4E3),0,!0));return a});this._addScenario("Blender eight",function(){var a=new Scenario;a.previewTime=5;a.previewOpacity=.01;a.previewSize=2700;a.addHole(0,0,0,0,1E6,!1,!0);for(var b=0;b<2*Math.PI;b+=Math.PI/4){var c=Math.cos(b),f=Math.sin(b);a.addHole(100*c,100*f,f*Math.sqrt(2E4),-c*Math.sqrt(2E4),1E6,!0,!1)}a.addElement(new ScenarioOval(350,0,200,50,0,0,Math.sqrt(1E6/350),!0));a.addElement(new ScenarioOval(-350,0,200,50,0,0,-Math.sqrt(1E6/
350),!0));a.addElement(new ScenarioOval(0,350,50,200,0,-Math.sqrt(1E6/350),0,!0));a.addElement(new ScenarioOval(0,-350,50,200,0,Math.sqrt(1E6/350),0,!0));return a});this._addScenario("Carousel",function(){var a=new Scenario;a.previewTime=4;a.previewOpacity=.01;a.previewSize=2700;a.addHole(0,0,0,0,1E6,!1,!0);for(var b=0;b<2*Math.PI;b+=Math.PI/4){var c=Math.cos(b),f=Math.sin(b);a.addHole(100*c,100*f,f*Math.sqrt(2E4),-c*Math.sqrt(2E4),-1E6,!0,!1)}for(b=0;b<2*Math.PI;b+=Math.PI/8)c=Math.cos(b),f=Math.sin(b),
a.addHole(300*c,300*f,-f*Math.sqrt(1E6/300*2),c*Math.sqrt(1E6/300*2),-1E6,!0,!1);a.addElement(new ScenarioRing(0,0,390,410,0,0,1E6,!1));return a})}},{key:"_addScenario",value:function(a,b){var c=this,f=this._scenarios.length,l=this._editorTab,m=this._settingsTab,g=this._camera,k=this._particleSystem,h=this._loading,p=document.createElement("button");p.className=0==this._scenarios.length%2?"scenario left":"scenario right";p.onclick=function(){g.reset();var x=b();k.loadScenario(x,g,m,h);l.setScenario(x)};
var r=document.createElement("canvas");r.width=148;r.height=148;var u=r.getContext("2d");this._scenarioImages.addEventListener("load",function(){var x=c._scenarioImages.width/148,v=Math.floor(f/x);u.drawImage(c._scenarioImages,-148*(f-v*x),-148*v)});p.appendChild(r);r=document.createElement("h2");r.textContent=a;p.appendChild(r);this._content.appendChild(p);p=b();this._scenarios.push(p)}},{key:"generatePreviews",value:function(a,b){var c=this._particleSystem;c.setMaxAmount(16777216);for(var f=[],
l=0;l<this._scenarios.length;++l)f.push(this._generatePreview(this._scenarios[l],a,b));c.setMaxAmount(1);return f}},{key:"_generatePreview",value:function(a,b,c){var f=this._graphics,l=this._camera,m=this._particleSystem;m.loadScenarioSync(a,l,this._settingsTab,this._loading);m.update(a.previewTime,Infinity);f.alpha=a.previewOpacity;return f.captureScreen(b,c,a.previewX,a.previewY,l.size/a.previewSize)}}]);return d}(TabUI),SettingsTab=function(n){function d(a,b,c,f){_classCallCheck(this,d);var l=
e.call(this,a);l._graphics=b;l._particleSystem=c;_assertThisInitialized(l);l._createTitle("Simulation");l._speedSlider=l._createSlider("Speed",0,3,.05,1,function(h){c.speed=h*h},function(h,p){h.textContent="Speed: "+Math.floor(p*p*100)+"%"});var m=null;window.addEventListener("keydown",function(h){if(32==h.keyCode||"Space"==h.code||80==h.keyCode||"KeyP"==h.code){null==m?(m=c.speed,c.speed=0):(c.speed=0==m?1:m,m=null);var p=Math.sqrt(c.speed);l._speedSlider.children[1].value=p;l._speedSlider.children[0].textContent=
"Speed: "+Math.floor(p*p*100)+"%";h.preventDefault()}});var g=Math.min(4096,b.getMaxTextureSize()),k=b.getMaxTextureSize();l._maxParticles=262144;l._maxParticlesSlider=l._createSliderWithButton("Particle limit",256,g,256,512,function(){c.setMaxAmount(l._maxParticles)},function(h){l._maxParticles=h*h},function(h,p){h.innerHTML="Particle limit: "+digitSeparated(p*p,0)});l._createText("WARNING: Setting the particle limit to a large value will slown down the simulation and might cause the browser to crash or freeze when using low-end hardware.");
l._globalGravitySlider=l._createSlider("Global gravity",0,500,1,0,function(h){c.gravity=parseFloat(h)});l._particleInfluenceSlider=l._createSlider("Particle influence",0,10,.05,1,function(h){c.particleInfluence=parseFloat(h)},function(h,p){h.textContent="Particle influence: "+Math.round(100*p)+"%"});l._massGravitySlider=l._createSlider("Pole influence",0,1E4,10,1E3,function(h){c.holesGravity=parseFloat(h)*parseFloat(h)},function(h,p){h.textContent="Pole influence: "+p*p/1E4+"%"});l._createHorizontalLine();
l._createTitle("Advanced");l._stepLengthSlider=l._createSlider("Step length",1E-4,.01,1E-4,.01,function(h){c.step=parseFloat(h)},function(h,p){h.textContent="Step length: "+Math.round(1E4*p)/10+"ms"});l._increasedParticleLimitCheckbox=l._createCheckBox("Increased particle limit",!1,function(h){l._maxParticlesSlider.children[1].max=h?k:g});k==g&&(l._increasedParticleLimitCheckbox.children[0].children[0].disabled=!0);l._createCheckBox("Anti-aliasing",!0,function(h){b.setAntialiasing(h);c.clear()});
l._createCheckBox("Time info",!1,function(h){h?f.showTimeInfo():f.hideTimeInfo()});return l}_inherits(d,n);var e=_createSuper(d);_createClass(d,[{key:"hide",value:function(){var a=Math.sqrt(this._particleSystem.maxAmount);this._maxParticlesSlider.children[1].value=a;this._maxParticlesSlider.children[0].innerHTML="Particle limit: "+digitSeparated(a*a,0);_get(_getPrototypeOf(d.prototype),"hide",this).call(this)}},{key:"resetSettings",value:function(){this._speedSlider.children[1].value=Math.sqrt(this._particleSystem.speed);
this._speedSlider.children[1].onchange();this._stepLengthSlider.children[1].value=this._particleSystem.step;this._stepLengthSlider.children[1].onchange();this._particleInfluenceSlider.children[1].value=this._particleSystem.particleInfluence;this._particleInfluenceSlider.children[1].onchange();this._globalGravitySlider.children[1].value=this._particleSystem.gravity;this._globalGravitySlider.children[1].onchange();this._massGravitySlider.children[1].value=Math.sqrt(this._particleSystem.holesGravity);
this._massGravitySlider.children[1].onchange();this._maxParticles=this._particleSystem.maxAmount;this._maxParticlesSlider.children[1].value=Math.sqrt(this._maxParticles);this._maxParticlesSlider.children[1].onchange()}}]);return d}(TabUI),ViewTab=function(n){function d(a,b,c){_classCallCheck(this,d);var f=e.call(this,a);f._graphics=b;f._particleSystem=c;f._createTitle("View");f._particleOpacitySlider=f._createSlider("Particle opacity",.05,1,.005,1,function(q){b.alpha=q*q});f._particleBrightnessVariation=
f._createCheckBox("Particle brightness variation",!0,function(q){b.setColorVariationEnabled(q)});f._createHorizontalLine();f._createTitle("Particle color");var l=f._createRadioButton("Velocity","ColorTheme",!0,function(){b.setColorTheme(1)}),m=f._createRadioButton("Velocity direction","ColorTheme",!1,function(){b.setColorTheme(2)});f._createRadioButton("Random","ColorTheme",!1,function(){b.setColorTheme(4)});var g=f._createRadioButton("Multicolor","ColorTheme",!1,function(){b.setColorTheme(3)}),k=
f._createRadioButton("Single color","ColorTheme",!1,function(){b.setColorTheme(0)});b.addColorThemeEventListener(function(q){0==q?k.children[0].children[0].checked=!0:1==q?l.children[0].children[0].checked=!0:2==q?m.children[0].children[0].checked=!0:3==q&&(g.children[0].children[0].checked=!0)});var h=f._createColorPicker(function(q){b.setColor(q);b.setColorTheme(0)});h.style.opacity=.5;b.addColorThemeEventListener(function(q){h.style.opacity=0==q?1:.5});f._createEmptyLine();f._createHorizontalLine();
f._createTitle("Particle texture");f._particleTexture=f._createImageSelection(["images/particle_preview0.png","images/particle_preview1.png","images/particle_preview2.png","images/particle_preview3.png","images/particle_preview4.png"],function(q){0==q?(b.setParticleTexture(null),b.setParticleRotationMode("None")):(b.setParticleTexture("images/particle"+q+".png"),4==q?b.setParticleRotationMode("Velocity"):3==q?b.setParticleRotationMode("Random"):b.setParticleRotationMode("None"))},0);f._particleTextureSize=
f._createSlider("Texture size",0,64,.25,15,function(q){b.particleSize=q});f._createEmptyLine();f._createHorizontalLine();f._createTitle("Background color");var p=f._createColorPicker(function(q){b.setBackgroundColor(q)},136);f._createEmptyLine();f._createHorizontalLine();f._createTitle("Poles");f._polesSizeFactor=f._createSlider("Pole size factor",5,30,1,10,function(q){b.setPoleSizeFactor(q*q/100)},function(q,t){q.textContent="Pole size factor: "+t*t+"%"});f._poleSizeDependOnZoom=f._createCheckBox("Pole size depend on zoom",
!0,function(q){b.setPoleSizeDependOnZoom(q)});f._createTitle("Pole color");var r=f._createColorPicker(function(q){b.setPositvePoleColor(q)},8),u=f._createSlider("Opacity",0,100,1,100,function(q){b.setPositivePoleOpacity(q/100)},function(q,t){q.textContent="Opacity: "+t+"%"});f._createTitle("Negative pole color");var x=f._createColorPicker(function(q){b.setNegativePoleColor(q)},77),v=f._createSlider("Opacity",0,100,1,100,function(q){b.setNegativePoleOpacity(q/100)},function(q,t){q.textContent="Opacity: "+
t+"%"});f._createHorizontalLine();f._createButton("Reset to default",function(){f._particleOpacitySlider.children[1].value=1;f._particleOpacitySlider.children[1].onchange();f._particleBrightnessVariation.children[0].children[0].checked=!0;f._particleBrightnessVariation.children[0].children[0].onchange();h.lastChild.click();l.children[0].children[0].checked=!0;l.children[0].children[0].onchange();f._particleTexture.children[0].click();f._particleTextureSize.children[1].value=15;f._particleTextureSize.children[1].onchange();
p.children[136].click();f._polesSizeFactor.children[1].value=10;f._polesSizeFactor.children[1].onchange();f._poleSizeDependOnZoom.children[0].children[0].checked=!0;f._poleSizeDependOnZoom.children[0].children[0].onchange();r.children[8].click();x.children[77].click();u.children[1].value=100;u.children[1].onchange();v.children[1].value=100;v.children[1].onchange()});return f}_inherits(d,n);var e=_createSuper(d);return _createClass(d)}(TabUI);
window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(n){window.setTimeout(n,1E3/60)}}();
(function(){var n=document.getElementById("ui"),d=document.getElementById("screen"),e=new Camera(d,document.getElementById("zoom_amount")),a=new Graphics(d,e),b=null,c=null,f=null,l=null,m=null,g=null,k=null,h=null,p=null,r=null;if(1>a.getMaxVertexTextureImageUnits())new ErrorUI(n,["MAX_VERTEX_TEXTURE_IMAGE_UNITS is too low","","Try another browser or a device with a more powerful graphics card"]);else if(a.getFloat32Support())if(a.getRenderFloat32Support())if(64>a.getMaxFragmentUniformVectors())new ErrorUI(n,
["MAX_FRAGMENT_UNIFORM_VECTORS is less than 64","","Try another browser or a device with a more powerful graphics card"]);else{var u=function(){requestAnimFrame(u);var t=(new Date).getTime(),w=v=(t-q)/1E3;q=t;0>v&&(v=0);.1<v&&(v=.1);0<v&&(f.update(),f.isLoading()||r.isOpen&&r.isEditing||b.update(v,1/30),e.update(v),l.update(v),c.update(v),a.update());x.update(w)};b=new ParticleSystem(262144,a);a.particleSystem=b;c=new ToolSystem(d,e,b,a);a.addToolSystem(c);f=new Loading;g=new DialogManager(document.body);
var x=new InfoManager(document.getElementById("info"),e,b);l=new UI(n,document.getElementById("info"),document.getElementById("version"),d,e,f);m=new SettingsTab(n,a,b,x);k=new ViewTab(n,a,b);r=new EditorTab(n,a,d,e,m,b,f,g);g=new ScenarioTab(n,r,m,a,e,b,f);h=new HolesTab(n,a,b,c);p=new ParticleTab(n,a,b,c);l.addTab(g,"images/scenario.svg");l.addTab(r,"images/editor.svg");l.addTab(m,"images/settings.svg");l.addTab(k,"images/view.svg");l.addTab(h,"images/holes.svg");l.addTab(p,"images/particles.svg");
var v=0,q=(new Date).getTime();u()}else new ErrorUI(n,["WEBGL_color_buffer_float is not supported","","Try another browser or a device with a more powerful graphics card"]);else new ErrorUI(n,["OES_texture_float is not supported","","Try another browser or a device with a more powerful graphics card"]);window.addEventListener("keydown",function(t){if(9==t.keyCode||"Tab"==t.code)document.body.className="show-focus";27!=t.keyCode&&"Escape"!=t.code||document.activeElement.blur()});window.addEventListener("pointerdown",
function(t){document.body.className=""})})();