-
Notifications
You must be signed in to change notification settings - Fork 0
/
min.js
1 lines (1 loc) · 16.3 KB
/
min.js
1
"use strict";function _createForOfIteratorHelper(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,c=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return i=e.done,e},e:function(e){c=!0,a=e},f:function(){try{i||null==n.return||n.return()}finally{if(c)throw a}}}}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}var pBody=document.querySelector("body"),pHtml=document.querySelector("html"),bgChangeFlag=-1;!function(){var e=["#30542c","#232170","#530a80","#870c6d","#873a0b"],t=0;bgChangeFlag=setTimeout(function n(){5==++t&&(t=0),pBody.style.backgroundColor=e[t],pHtml.style.backgroundColor=e[t],bgChangeFlag&&(bgChangeFlag=setTimeout(n,5e3))},5e3)}(),document.querySelector(".cancel-bg-change").addEventListener("click",function e(t){document.querySelector(".cancel-bg-change").removeEventListener("click",e),clearTimeout(bgChangeFlag),bgChangeFlag=null}),document.querySelector(".cancel-bg-change-and-enable-star").addEventListener("click",function e(t){document.querySelector(".cancel-bg-change-and-enable-star").removeEventListener("click",e),clearTimeout(bgChangeFlag),bgChangeFlag=null,pBody.style.backgroundColor="unset",pHtml.style.backgroundColor="unset",pHtml.style.background='url("./assets/bg.jpg")',pHtml.style.backgroundPosition="center center",pHtml.style.backgroundAttachment="fixed",document.querySelector("#container").style.backgroundColor="unset",document.querySelector("#container").style.overflow="unset";var n=["1px 1px 15px 6px rgba(255,144,61,.89)","1px 1px 15px 6px rgba(255,100,61,.93)","1px 1px 15px 6px rgba(255,88,61,.89)","1px 1px 15px 6px rgba(255,88,61,.5)","1px 1px 15px 6px rgba(255,100,61,.89)","1px 1px 15px 6px rgba(255,144,61,.77)"],o=0,r=document.querySelector("#origin");r.style.background="radial-gradient( rgb(255,208,0) 1%, rgb(255,151,0) 39%, rgb(249,183,0) 39%, rgb(223,77,23) 100%)",r.style.width="8px",r.style.height="8px",setTimeout(function e(){6==++o&&(o=0),r.style.boxShadow=n[o],r.style.WebkitBoxShadow=n[o],setTimeout(e,4e3)},0)});var container=document.querySelector("div#container"),containerWidthText=document.querySelector(".container-width"),origin=document.querySelector("div#origin"),containerLength=0;function floatToPx(e){return String(e)+"px"}function parseFloat200(e){var t=parseFloat(e);return isNaN(t)?1/0:t}function wrongInput(e){var t=e.style.backgroundColor;e.style.backgroundColor="#c98d8d",setTimeout(function(){e.style.backgroundColor=t},400)}function onChangeContainerSize(e){var t=floatToPx(containerLength=parseFloat(window.getComputedStyle(container).width));container.style.height=t,containerWidthText.value=t,origin.style.left=floatToPx(parseFloat(window.getComputedStyle(container).width)/2-3.6),origin.style.top=floatToPx(parseFloat(window.getComputedStyle(container).height)/2-3.5)}function degToRadian(e){return Math.PI*e/180}function radianToDeg(e){return 180*e/Math.PI}function rotateX(e,t,n){return Math.cos(n)*e-Math.sin(n)*t}function rotateY(e,t,n){return Math.sin(n)*e+Math.cos(n)*t}function Block(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;this.offset=t,this.initPeriod=n,this.initSemiX=o,this.initSemiY=r,this.initRotate=a,this.period=function(t){return e.initPeriod},this.omega=function(t){return 2*Math.PI/e.period(t)},this.semiX=function(t){return e.initSemiX},this.semiY=function(t){return e.initSemiY},this.rotate=function(t){return e.initRotate},this.yieldX=function(t){return e.semiX(t)*Math.cos(e.omega(t)*t-e.offset)},this.yieldY=function(t){return e.semiY(t)*Math.sin(e.omega(t)*t-e.offset)},this.yieldRotated=function(t){var n=e.yieldX(t),o=e.yieldY(t),r=e.rotate(t),a=degToRadian(r);return{x:rotateX(n,o,a),y:rotateY(n,o,a),rx:e.semiX(t),ry:e.semiY(t),rad:a,deg:r}}}onChangeContainerSize(),window.addEventListener("resize",onChangeContainerSize);var intervals=40;function BlockInMotion(e){var t=new Block,n=document.querySelector("div#moving-obj-".concat(e)),o=document.querySelector("div#moving-obj-trajectory-".concat(e)),r=document.querySelector("div#moving-obj-prj-".concat(e)),a=document.querySelector("#info-container-".concat(e," .box-x")),i=document.querySelector("#info-container-".concat(e," .box-y")),c=document.querySelector("#info-container-".concat(e," .set-color")),l=document.querySelector("#info-container-".concat(e," .set-size")),u=document.querySelector("#info-container-".concat(e," .set-period")),s=document.querySelector("#info-container-".concat(e," .set-angle")),d=document.querySelector("#info-container-".concat(e," .set-semi-X-axis")),v=document.querySelector("#info-container-".concat(e," .set-semi-Y-axis")),y=document.querySelector("#info-container-".concat(e," .set-period-change")),m=document.querySelector("#info-container-".concat(e," .set-semi-X-axis-change")),f=document.querySelector("#info-container-".concat(e," .set-semi-Y-axis-change")),p=document.querySelector("#info-container-".concat(e," .set-angle-change")),g=document.querySelector("#info-container-".concat(e," .set-rotate-around")),h=document.querySelector("#info-container-".concat(e," .set-attr-go")),b=document.querySelector("#info-container-".concat(e," .set-attr-reset")),S=0,C=0,x=null,k=!1,q=!1,w=0,T=0;function j(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];C=0,S=containerLength/2,l.value=15,u.value=5,d.value=S/2,v.value=S/2,s.value=0,y.value=0,m.value=0,f.value=0,p.value=0,g.value="origin",k=!1,n.style.left="49.1%",n.style.top="48.9%",n.style.width="15px",n.style.height="15px",r.style.left="49.1%",o.style.width="0px",o.style.height="0px",o.style.left="0px",o.style.top="0px",o.style.borderColor="rgba(255,255,255,.18) !important",t&&(c.value="yellow",h.style.backgroundColor="yellow",n.style.backgroundColor="yellow",r.style.backgroundColor="yellow"),x=null}function F(){var e=(C+=intervals)/1e3,o=parseFloat(n.style.width),c=S-o/2,l=t.yieldRotated(e),s=l.x+c,d=l.y+c,v=0,y=0;if(k){var p=l.rad;if(Math.abs(l.rx)>=Math.abs(l.ry)){var g=Math.sqrt(l.rx**2-l.ry**2);v=g*Math.cos(p),y=g*Math.sin(p)}else{var h=Math.sqrt(l.ry**2-l.rx**2);v=h*Math.sin(-p),y=h*Math.cos(p)}s+=v,d+=y}if(function(e,t,n){return e<-containerLength||e>2*containerLength||t<-containerLength||t>2*containerLength}(s,d))return t.initSemiX=S,t.SemiX=function(e){return t.initSemiX},t.initSemiY=S,t.SemiY=function(e){return t.initSemiY},t.initPeriod=0,t.period=function(e){return t.initPeriod},t.rotate=function(e){return t.initRotate},m.value=0,f.value=0,u.value=0,a.value="stopped",void(i.value="stopped");n.style.left=floatToPx(s),a.value=floatToPx(s),n.style.top=floatToPx(d),i.value=floatToPx(d),r.style.left=floatToPx(s),L(l.rx,l.ry,l.deg,v,y),x=setTimeout(F,intervals)}function L(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;e=Math.abs(e),t=Math.abs(t),o.style.width=floatToPx(2*e),o.style.height=floatToPx(2*t);var i=parseFloat(window.getComputedStyle(container).width)/2;o.style.left=floatToPx(i-e+r),o.style.top=floatToPx(i-t+a),o.style.transform="rotate(".concat(n,"deg)"),o.style.WebkitTransform="rotate(".concat(n,"deg)")}function M(e){(e=e||window.event).preventDefault(),w=(e.clientX||e.touches[0].clientX)-n.offsetLeft,T=(e.clientY||e.touches[0].clientY)-n.offsetTop,q=!0}function E(e){if(q){(e=e||window.event).preventDefault();var o=parseFloat(n.style.width),c=(e.clientX||e.touches[0].clientX)-w,l=(e.clientY||e.touches[0].clientY)-T;if(function(e,t,n){return e<0||e>containerLength-n||t<0||t>containerLength-1.1*n}(c,l,o))return;n.style.left=floatToPx(c),n.style.top=floatToPx(l),a.value=c,i.value=l,r.style.left=floatToPx(c);var u=c-parseFloat(origin.style.left),s=l-parseFloat(origin.style.top),y=Math.sqrt(u**2+s**2);d.value=y,v.value=y,t.offset=-Math.atan2(s,u),L(y,y,0)}}function B(e){q=!1,w=0,T=0}j(),window.addEventListener("resize",function(e){S=containerLength/2,t.initSemiX>S&&(t.initSemiX=S),t.initSemiY>S&&(t.initSemiY=S),"ontouchstart"in document.documentElement||(d.value=t.initSemiX,v.value=t.initSemiY)}),u.addEventListener("click",function(e){u.value=t.period(C/1e3)}),d.addEventListener("click",function(e){d.value=t.semiX(C/1e3)}),v.addEventListener("click",function(e){v.value=t.semiY(C/1e3)}),s.addEventListener("click",function(e){s.value=t.rotate(C/1e3)}),g.addEventListener("change",function(e){var t=g.value;k="origin"!==t}),h.addEventListener("click",function(e){var o=parseFloat(l.value);if(o<=30&&o>=5){h.style.backgroundColor=c.value,n.style.backgroundColor=c.value,n.style.width=floatToPx(o),n.style.height=floatToPx(o),r.style.backgroundColor=c.value;var a=isNaN(parseFloat(u.value)),i=isNaN(parseFloat(s.value))||Math.abs(parseFloat(s.value))>360,g=Math.abs(parseFloat200(d.value))>S,b=Math.abs(parseFloat200(v.value))>S;if(g||b||a||i)return g&&wrongInput(d),b&&wrongInput(v),a&&wrongInput(u),void(i&&wrongInput(s));t.initPeriod=parseFloat(u.value),t.initSemiX=parseFloat(d.value),t.initSemiY=parseFloat(v.value),t.initRotate=parseFloat(s.value),u.value=parseFloat(u.value),d.value=parseFloat(d.value),v.value=parseFloat(v.value),s.value=parseFloat(s.value),y.value||(y.value=0),m.value||(m.value=0),f.value||(f.value=0),p.value||(p.value=0);var k=isNaN(parseFloat(y.value)),q=isNaN(parseFloat(p.value))||Math.abs(parseFloat(p.value))>360,w=Math.abs(parseFloat200(m.value))>S,T=Math.abs(parseFloat200(f.value))>S;if(w||T||k||q)return w&&wrongInput(m),T&&wrongInput(f),k&&wrongInput(y),void(q&&wrongInput(p));var j=parseFloat(y.value);t.period=function(e){return t.initPeriod+e*j};var L=parseFloat(m.value);t.semiX=function(e){return t.initSemiX+e*L};var M=parseFloat(f.value);t.semiY=function(e){return t.initSemiY+e*M};var E=parseFloat(p.value);t.rotate=function(e){return t.initRotate+e*E},y.value=j,m.value=L,f.value=M,p.value=E;var B=C/1e3;clearTimeout(x),t.offset-=t.omega(B)*B,C=0,x=setTimeout(F,intervals),h.value="Change!"}else wrongInput(l)}),b.addEventListener("click",function(e){clearTimeout(x),t=null,j(null,!1),t=new Block,h.value="Go!",a.value=null,i.value=null}),"onmousedown"in document.documentElement&&(n.addEventListener("mousedown",M),container.addEventListener("mousemove",E),container.addEventListener("mouseup",B)),"ontouchstart"in document.documentElement&&(n.addEventListener("touchstart",M),container.addEventListener("touchmove",E),container.addEventListener("touchend",B)),this.cleanUp=function(){clearTimeout(x),t=null}}var setFpsText=document.querySelector(".shared-info-container-bo > span:nth-child(2)");document.querySelector(".shared-info-container-bo .fps-decrease").addEventListener("click",function(e){var t=parseInt(setFpsText.innerText);t<=5?setFpsText.innerText=5:(intervals=parseInt(1e3/t),setFpsText.innerText=t-(t>=40?10:5))}),document.querySelector(".shared-info-container-bo .fps-increase").addEventListener("click",function(e){var t=parseInt(setFpsText.innerText);t>=150?setFpsText.innerText=150:(intervals=parseInt(1e3/t),setFpsText.innerText=t+(t>=40?10:5))});var grandContainer=document.querySelector(".grand-container"),infoContainer1=document.querySelector("#info-container-1"),movingObj1=document.querySelector("#moving-obj-1"),movingObjTrajectory1=document.querySelector("#moving-obj-trajectory-1"),objManageNode=document.querySelector(".obj-manage"),movingObjProjection1=document.querySelector("#moving-obj-prj-1"),oneClickGoBtn=document.querySelector(".obj-manage .objs-oneclick-go"),oneClickResetBtn=document.querySelector(".obj-manage .objs-oneclick-reset"),oneClickBtnsSeparator=document.querySelector(".obj-manage br");oneClickGoBtn.style.display="none",oneClickResetBtn.style.display="none",oneClickBtnsSeparator.style.display="none";var prevObjSelect=[],nextObjSelect=[],nextBtnHandlers=[],circular1=new BlockInMotion(1),CircularsCount=1,Circulars=[];document.querySelector(".obj-manage .append-objs").addEventListener("click",function(e){if(!(CircularsCount>=6)){++CircularsCount;var t=infoContainer1.cloneNode(!0);t.id="info-container-".concat(CircularsCount),t.children[0].children[1].innerText="Block ".concat(CircularsCount),t.style.display="none",grandContainer.insertBefore(t,container);var n=movingObj1.cloneNode(!0);n.id="moving-obj-".concat(CircularsCount),container.appendChild(n);var o=movingObjTrajectory1.cloneNode(!0);o.id="moving-obj-trajectory-".concat(CircularsCount),container.insertBefore(o,origin);var r=movingObjProjection1.cloneNode();r.id="moving-obj-prj-".concat(CircularsCount);var a=document.createElement("div");a.setAttribute("class","projections"),a.appendChild(r),grandContainer.insertBefore(a,objManageNode);var i=new BlockInMotion(CircularsCount);document.querySelector("#info-container-".concat(CircularsCount," .set-color")).value="rgba(".concat(Math.floor(256*Math.random()),",").concat(Math.floor(256*Math.random()),",").concat(Math.floor(256*Math.random()),",1)"),Circulars.push(i),2===CircularsCount&&(oneClickGoBtn.style.display="",oneClickResetBtn.style.display="",oneClickBtnsSeparator.style.display="");var c=CircularsCount;document.querySelector("#info-container-".concat(c," .switch-obj-prev")).addEventListener("click",function(e){document.querySelector("#info-container-".concat(c)).style.display="none",document.querySelector("#info-container-".concat(c-1)).style.display="grid"}),nextBtnHandlers.push(function(e){document.querySelector("#info-container-".concat(c-1)).style.display="none",document.querySelector("#info-container-".concat(c)).style.display="grid"}),document.querySelector("#info-container-".concat(c-1," .switch-obj-next")).addEventListener("click",nextBtnHandlers[c-2])}}),document.querySelector(".obj-manage .delete-objs").addEventListener("click",function(e){if(!(CircularsCount<=1)){Circulars[Circulars.length-1].cleanUp(),Circulars.pop();var t=document.querySelector("#info-container-".concat(CircularsCount)),n=document.querySelector("#info-container-".concat(CircularsCount-1)),o="none"!=t.style.display;t.remove(),document.querySelector("#moving-obj-".concat(CircularsCount)).remove(),document.querySelector("#moving-obj-trajectory-".concat(CircularsCount)).remove(),document.querySelector("#moving-obj-prj-".concat(CircularsCount)).parentNode.remove(),document.querySelector("#info-container-".concat(CircularsCount-1," .switch-obj-next")).removeEventListener("click",nextBtnHandlers.pop()),o&&(n.style.display="grid"),1==--CircularsCount&&(oneClickGoBtn.style.display="none",oneClickResetBtn.style.display="none",oneClickBtnsSeparator.style.display="none")}}),document.querySelector(".obj-manage .objs-oneclick-go").addEventListener("click",function(e){var t,n=_createForOfIteratorHelper(document.querySelectorAll(".info-container .set-attr-go"));try{for(n.s();!(t=n.n()).done;){t.value.click()}}catch(e){n.e(e)}finally{n.f()}}),document.querySelector(".obj-manage .objs-oneclick-reset").addEventListener("click",function(e){var t,n=_createForOfIteratorHelper(document.querySelectorAll(".info-container .set-attr-reset"));try{for(n.s();!(t=n.n()).done;){t.value.click()}}catch(e){n.e(e)}finally{n.f()}});var samplesClickDisplay=document.querySelector(".samples-display > h5"),samplesShown=!1;samplesClickDisplay.addEventListener("click",function(e){if(samplesShown){var t,n=_createForOfIteratorHelper(document.querySelectorAll(".samples-display img"));try{for(n.s();!(t=n.n()).done;){t.value.remove()}}catch(e){n.e(e)}finally{n.f()}}else for(var o=0,r=["./assets/uniformcircular1.gif","./assets/uniformcircular2.gif","./assets/uniformcircular3.gif","./assets/uniformcircular4.gif"];o<r.length;o++){var a=r[o],i=document.createElement("img");i.src=a,document.querySelector(".samples-display").appendChild(i)}samplesShown=!samplesShown});