-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.min.js
More file actions
11 lines (11 loc) · 5.31 KB
/
script.min.js
File metadata and controls
11 lines (11 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
function ia(f){var q=0;return function(){return q<f.length?{done:!1,value:f[q++]}:{done:!0}}}function p(f){var q="undefined"!=typeof Symbol&&Symbol.iterator&&f[Symbol.iterator];if(q)return q.call(f);if("number"==typeof f.length)return{next:ia(f)};throw Error(String(f)+" is not an iterable or ArrayLike");}function I(f){if(!(f instanceof Array)){f=p(f);for(var q,y=[];!(q=f.next()).done;)y.push(q.value);f=y}return f}
(function(f){f.addEventListener("load",function(){function q(a){a=void 0===a?P():a;h.clearRect(0,0,B,C);V++;W=Math.min(a-X,30);X=a;if(F)l(G,r);else{a=u;var b=.001*W,d=y.apply(null,I(a)),c=y.apply(null,I(v(a,w(b/2,d)))),g=y.apply(null,I(v(a,w(b/2,c)))),t=y.apply(null,I(v(a,w(b,g))));a=v(a,v(w(b/6,v(d,t)),w(b/3,v(c,g))));l(u,a);u[0]+e.L0<e.rBob+e.rPivot&&(u[0]=e.rPivot+e.rBob-e.L0,u[2]=-u[2]);l(G,ja.apply(null,I(u)))}h.beginPath();h.scale(e.pxPerM,e.pxPerM);h.arc.apply(h,[].concat(I(x),[e.rPivot,0,2*Math.PI]));h.fillStyle="#333";h.fill();
h.moveTo.apply(h,I(x));h.lineWidth=3/e.pxPerM;h.lineTo.apply(h,I(G));h.strokeStyle="#333";h.stroke();h.beginPath();h.arc.apply(h,[].concat(I(G),[e.rBob,0,2*Math.PI]));h.fillStyle="#ccc";h.fill();h.setTransform(1,0,0,1,0,0);Y=f.requestAnimationFrame(q)}function y(a,b,d,c){var g=e.L0+a||e.rBob+e.rPivot;return[d,c,g*c*c-e.k*a+e.g*Math.cos(b)-e.ldc*d,-(e.g*Math.sin(b)+2*d*c)/g-e.ldc*c]}function ja(a,b){return v(x,w(e.L0+a,[Math.sin(b),Math.cos(b)]))}function ka(a,b,d,c){d=void 0===d?0:d;c=void 0===c?0:c;a=J([a,b],x);b=Math.sqrt(Q(a));
var g=b-e.L0,t=Math.atan2(a[0],a[1]),k=0,H=0;(d||c)&&0<b&&(k=d*d+c*c,16<k&&(k=4*Math.pow(k,-.5),d*=k,c*=k),H=(d*a[1]-c*a[0])/b,k=(a[0]*d+a[1]*c)/b);return[g,t,k,H]}function Z(a){var b={},d;for(d in e)if(b={h:b.h,o:void 0},b.h=d,b.h){var c=void 0,g=n.querySelector('[data-param="'+b.h+'"]'),t=null==(c=g)?void 0:c.nextSibling;g&&t&&g instanceof HTMLInputElement&&t instanceof HTMLInputElement&&(b.o=[g,t],b.o.forEach(function(k){return function(H,la){H.value=e[k.h];a&&a(k.h,H,k.o[1-la])}}(b)))}}function Q(a){return a.reduce(function(b,
d){return b+d*d},0)}function w(a,b){return b.map(function(d){return a*d})}function J(a,b){return a.map(function(d,c){return d-b[c]})}function v(a,b){return a.map(function(d,c){return d+b[c]})}function aa(){B=f.innerWidth;C=f.innerHeight;K.width=B;K.height=C}function ba(){D.checked?f.requestAnimationFrame(q):f.cancelAnimationFrame(Y)}function ca(a,b,d,c){function g(){c&&c();m(z,"touchmove mousemove touchend mouseup",t,!0);m(f,"blur",g,!0)}function t(k){k.preventDefault();d(da(k),k)&&g()}m(a,"touchstart mousedown",
function(k){k.preventDefault();b(da(k),k);m(z,"touchmove mousemove",t);m(z,"touchend mouseup",g);m(f,"blur",g)})}function ea(a,b,d){var c=p(a);a=c.next().value;c=c.next().value;0>a?a=0:a>b&&(a=b);0>c?c=0:c>d&&(c=d);return[a,c]}function da(a){if("touches"in a){var b=a.changedTouches,d;a=null!=(d=a.touches[0])?d:b[0];return[a.clientX,a.clientY]}return[a.clientX,a.clientY]}function l(a,b){a.splice.apply(a,[0,a.length].concat(I(b)))}function L(a,b){b=void 0===b?2:b;return Math.round(a*Math.pow(10,b))/
Math.pow(10,b)}function P(){var a=z.timeline.currentTime;if("number"===typeof a)return a;throw Error("document.timeline.currentTime is not a number");}function m(a,b,d,c){c=void 0===c?!1:c;b=p(b.split(" "));for(var g=b.next();!g.done;g=b.next())g=g.value,c?a.removeEventListener(g,d):a.addEventListener(g,d)}function E(a){var b=z.getElementById(a);if(b)return b;throw Error("Element #"+a+" not found");}var z=f.document,M=z.body,n=E("controls"),R=E("css-output"),N=E("output-coords"),ma=N.innerHTML;m(f,
"blur",function(){});m(f,"focus",function(){});var O=[0,0],A=function(a){return[a.left,a.top]}(n.getBoundingClientRect());ca(n.getElementsByTagName("header")[0],function(a){l(O,a);n.classList.add("currentlyDragging")},function(a){A[0]+=a[0]-O[0];A[1]+=a[1]-O[1];l(O,a);var b=p(ea(A,M.clientWidth-n.clientWidth,M.clientHeight-n.clientHeight));a=b.next().value;b=b.next().value;n.style.transform="translate("+a+"px,"+b+"px)"},function(){n.classList.remove("currentlyDragging");l(A,ea(A,M.clientWidth-n.clientWidth,
M.clientHeight-n.clientHeight))});m(n.getElementsByClassName("toggle-dropdown")[0],"click",function(){n.classList.toggle("closed")});R.innerHTML="#controls>ul{max-height:"+2*n.getElementsByTagName("ul")[0].childElementCount+"em;}";var D=E("toggle-animation");m(D,"change",ba);m(z,"keydown",function(a){"key"in a&&"p"===a.key&&(D.checked=!D.checked,ba())});R=E("reset-canvas");m(R,"click",function(a){V=0;"shiftKey"in a&&a.shiftKey&&Object.assign(e,fa);l(u,[e.g/e.k,0,0,0]);l(x,[B/(2*e.pxPerM),C/(6*e.pxPerM)]);Z(null);
h.clearRect(0,0,B,C)});var K=E("canvas"),h=K.getContext("2d"),r=[0,0],S=[0,0],T,ha=0,Y,B=0,C=0,V=0,X=0,W=0;aa();m(f,"resize",aa);var fa={L0:1,g:9.8,k:3,pxPerM:100,ldc:.1,rBob:.15,rPivot:.15},e=Object.assign({},fa);Z(function(a,b,d){m(b,"input",function(){var c=b.value;e[a]=c;d.value=c})});var x=[B/(2*e.pxPerM),C/(6*e.pxPerM)],G=v(x,[0,100/e.pxPerM]),u=[e.g/e.k,.1,0,0],F=!1,U=!1;ca(K,function(a){l(r,w(1/e.pxPerM,a));T=P();D.checked&&(Q(J(r,G))<=8*Math.pow(e.rBob,2)?F=!0:Q(J(r,x))<=Math.pow(e.rPivot,2)&&(U=!0));N.innerHTML=L(r[0])+", "+L(r[1])},
function(a){if(D.checked){a=w(1/e.pxPerM,a);if(F){var b=P()-T;T+=b;0<b&&l(S,w(1E3/b,J(a,r)));clearTimeout(ha);ha=setTimeout(function(){l(S,[0,0])},50)}else U&&l(x,a);l(r,a)}N.innerHTML=L(r[0])+", "+L(r[1])},function(){F&&l(u,ka.apply(null,[].concat(I(r),I(S))));U=F=!1;N.innerHTML=ma})})})(window);