-
Notifications
You must be signed in to change notification settings - Fork 1
/
graph_background.min.js
1 lines (1 loc) · 4.26 KB
/
graph_background.min.js
1
function graph_background(n,t){function e(n,t,e){"undefined"==typeof t&&(t=n,n=0),e="undefined"==typeof e?1:e,e=n>t?-e:e;for(var o=[n],r=1;(t-n)/e>r;r++)o.push(o[o.length-1]+e);return o}function o(n,t){t="undefined"==typeof t?1:t;for(var e=[],o=n.length,r=0;t>r;r++){var i=Math.floor(Math.random()*o);e.push(n[i])}return 1==e.length?e[0]:e}function r(n,t){var e=t.filter(function(t){return n.start==t.start&&n.end==t.end||n.start==t.end&&n.end==t.start});return Boolean(e.length)}function i(n,t,e){if("undefined"==typeof e&&(e=Math.max(Math.round(t-n)+1,1)),2>e)return 1===e?[n]:[];var o,r=Array(e);for(e--,o=e;o>=0;o--)r[o]=(o*t+(e-o)*n)/e;return r}function a(n,t,e){for(var o=i(n,t,e),r=[],a=[],d=0;e>d;d++)r.push(1/Math.PI*Math.atan(o[d]-(t+n)/2)+.5),t>n&&a.push(r[d]*(t-n)+n);if(n>t)for(var d=e-1;d>=0;d--)a.push(r[d]*(t-n)+n);return a[0]=n,a[a.length-1]=t,a}function d(n,t,e,o){return Math.sqrt((e-n)*(e-n)+(o-t)*(o-t))}function f(){h.width=window.innerWidth,h.height=window.innerHeight;var n=window.innerWidth/2/u,t=window.innerHeight/2/y;u=window.innerWidth/2,y=window.innerHeight/2;for(var e=0;_>e;e++)b[e].x0=u+b[e].x_shift*n,b[e].y0=y+b[e].y_shift*t,b[e].x_shift*=n,b[e].y_shift*=t}function x(n,t){var e=n.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}}function c(){context=h.getContext("2d"),context.clearRect(0,0,window.innerWidth,window.innerHeight);for(var n=0;_>n;n++){var t=o(w),e=o(v);context.beginPath();var i=u+t,a=y+e;context.arc(i,a,0,0,2*Math.PI,!1),context.fill(),m.push({x0:i,y0:a}),b.push({x0:i,y0:a,x_shift:t,y_shift:e})}for(var n=0;_>n;n++){for(var x=[],c=0;_>c;c++)x.push({index:c,distance:d(m[n].x0,m[n].y0,m[c].x0,m[c].y0)});x=x.sort(function(n,t){return n.distance-t.distance});for(var s=0,g=0;p>g;g++){context.beginPath();for(var k=x[g+1].index;r({start:n,end:k},M)&&g+1+s!=x.length;)s++,k=x[g+1+s].index;context.moveTo(m[n].x0,m[n].y0),context.lineTo(m[k].x0,m[k].y0),M.push({start:n,end:k}),context.stroke()}H[n]={goal:{x:m[n].x0,y:m[n].y0},range_x:[],range_index_x:0,range_y:[],range_index_y:0}}f(),window.requestAnimationFrame(l)}function l(){context=h.getContext("2d"),context.clearRect(0,0,window.innerWidth,window.innerHeight);for(var n=0;_>n;n++){if(H[n].goal.x==m[n].x0){var t=b[n].x0+o([1,-1])*o(e(P[0],P[1]));H[n].goal.x=t,H[n].range_x=a(m[n].x0,t,Math.round(W*F[n])),H[n].range_index_x=0}if(H[n].goal.y==m[n].y0){var t=b[n].y0+o([1,-1])*o(e(P[0],P[1]));H[n].goal.y=t,H[n].range_y=a(m[n].y0,t,Math.round(W*F[n])),H[n].range_index_y=0}context.beginPath(),m[n].x0=H[n].range_x[H[n].range_index_x],H[n].range_index_x++,m[n].y0=H[n].range_y[H[n].range_index_y],H[n].range_index_y++,context.globalAlpha=0;for(var r=0,i=1;i<B.length;i++){var f=d(m[n].x0,m[n].y0,k,A);if(f<B[i]&&f>=B[i-1]){context.globalAlpha=q[i-1],r=R[i-1];break}}context.arc(m[n].x0,m[n].y0,r,0,2*Math.PI,!1),context.fillStyle=S,context.fill(),context=h.getContext("2d"),context.globalAlpha=0;for(var x=0;p>x;x++){for(var c=n*p+x,i=1;i<B.length;i++){var f=d(m[M[c].start].x0,m[M[c].start].y0,k,A);f<B[i]&&f>=B[i-1]&&(context.globalAlpha=q[i-1])}context.beginPath(),context.moveTo(m[M[c].start].x0,m[M[c].start].y0),context.lineTo(m[M[c].end].x0,m[M[c].end].y0),context.strokeStyle=L,context.stroke()}}window.requestAnimationFrame(l)}var h=document.getElementById(n);h.style.margin=0,h.style.padding=0,h.style.display="block",h.style.position="fixed",h.style.top=0,h.style.left=0,h.style.zIndex=-1,h.style.width="100%",h.style.height="100%";var t="undefined"==typeof t?{}:t,u=window.innerWidth/2,y=window.innerHeight/2,s=window.innerWidth,g=window.innerHeight,_="undefined"==typeof t.dot_number?800:t.dot_number,w=i(-s/2,s/2,s),v=i(-g/2,g/2,g),p="undefined"==typeof t.connections_number?5:t.connections_number,m=[],b=[],M=[],k=0,A=0,H=[],P=[20,40],W=60,I=10,C="undefined"==typeof t.max_opacity?.5:t.max_opacity,E="undefined"==typeof t.max_dot_radius?5:t.max_dot_radius,T="undefined"==typeof t.discovered_area_radius?150:t.discovered_area_radius,q=i(C,0,I),B=i(0,T,I),R=i(E,.5,I),z="undefined"==typeof t.dot_delay_factor?1.5:t.dot_delay_factor,F=e(_);F.forEach(function(n,t,e){e[t]=z+Math.random()/2});var L="undefined"==typeof t.line_color?"black":t.line_color,S="undefined"==typeof t.dot_color?"black":t.dot_color;window.addEventListener("resize",f,!1),window.addEventListener("mousemove",function(n){var t=x(h,n);k=t.x,A=t.y},!1),c()}