Created
August 25, 2016 21:54
-
-
Save chrisprice/318ab8e6b1f46bbd3729d6f20884f3d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { totalCols, | |
leftCols, | |
frontCols, | |
rightCols, | |
backCols, | |
totalRows, } = config | |
// https://d3js.org/d3-collection/ Version 1.0.1. Copyright 2016 Mike Bostock. | |
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n.d3=n.d3||{})}(this,function(n){"use strict";function t(){}function e(n,e){var r=new t;if(n instanceof t)n.each(function(n,t){r.set(t,n)});else if(Array.isArray(n)){var i,u=-1,o=n.length;if(null==e)for(;++u<o;)r.set(u,n[u]);else for(;++u<o;)r.set(e(i=n[u],u,n),i)}else if(n)for(var s in n)r.set(s,n[s]);return r}function r(){function n(t,i,u,o){if(i>=a.length)return null!=f?f(t):null!=r?t.sort(r):t;for(var s,c,h,l=-1,v=t.length,p=a[i++],y=e(),d=u();++l<v;)(h=y.get(s=p(c=t[l])+""))?h.push(c):y.set(s,[c]);return y.each(function(t,e){o(d,e,n(t,i,u,o))}),d}function t(n,e){if(++e>a.length)return n;var r,i=h[e-1];return null!=f&&e>=a.length?r=n.entries():(r=[],n.each(function(n,i){r.push({key:i,values:t(n,e)})})),null!=i?r.sort(function(n,t){return i(n.key,t.key)}):r}var r,f,c,a=[],h=[];return c={object:function(t){return n(t,0,i,u)},map:function(t){return n(t,0,o,s)},entries:function(e){return t(n(e,0,o,s),0)},key:function(n){return a.push(n),c},sortKeys:function(n){return h[a.length-1]=n,c},sortValues:function(n){return r=n,c},rollup:function(n){return f=n,c}}}function i(){return{}}function u(n,t,e){n[t]=e}function o(){return e()}function s(n,t,e){n.set(t,e)}function f(){}function c(n,t){var e=new f;if(n instanceof f)n.each(function(n){e.add(n)});else if(n){var r=-1,i=n.length;if(null==t)for(;++r<i;)e.add(n[r]);else for(;++r<i;)e.add(t(n[r],r,n))}return e}function a(n){var t=[];for(var e in n)t.push(e);return t}function h(n){var t=[];for(var e in n)t.push(n[e]);return t}function l(n){var t=[];for(var e in n)t.push({key:e,value:n[e]});return t}var v="$";t.prototype=e.prototype={constructor:t,has:function(n){return v+n in this},get:function(n){return this[v+n]},set:function(n,t){return this[v+n]=t,this},remove:function(n){var t=v+n;return t in this&&delete this[t]},clear:function(){for(var n in this)n[0]===v&&delete this[n]},keys:function(){var n=[];for(var t in this)t[0]===v&&n.push(t.slice(1));return n},values:function(){var n=[];for(var t in this)t[0]===v&&n.push(this[t]);return n},entries:function(){var n=[];for(var t in this)t[0]===v&&n.push({key:t.slice(1),value:this[t]});return n},size:function(){var n=0;for(var t in this)t[0]===v&&++n;return n},empty:function(){for(var n in this)if(n[0]===v)return!1;return!0},each:function(n){for(var t in this)t[0]===v&&n(this[t],t.slice(1),this)}};var p=e.prototype;f.prototype=c.prototype={constructor:f,has:p.has,add:function(n){return n+="",this[v+n]=n,this},remove:p.remove,clear:p.clear,values:p.keys,size:p.size,empty:p.empty,each:p.each},n.nest=r,n.set=c,n.map=e,n.keys=a,n.values=h,n.entries=l,Object.defineProperty(n,"__esModule",{value:!0})}); | |
// https://d3js.org/d3-dispatch/ Version 1.0.1. Copyright 2016 Mike Bostock. | |
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(n.d3=n.d3||{})}(this,function(n){"use strict";function e(){for(var n,e=0,r=arguments.length,o={};e<r;++e){if(!(n=arguments[e]+"")||n in o)throw new Error("illegal type: "+n);o[n]=[]}return new t(o)}function t(n){this._=n}function r(n,e){return n.trim().split(/^|\s+/).map(function(n){var t="",r=n.indexOf(".");if(r>=0&&(t=n.slice(r+1),n=n.slice(0,r)),n&&!e.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:t}})}function o(n,e){for(var t,r=0,o=n.length;r<o;++r)if((t=n[r]).name===e)return t.value}function i(n,e,t){for(var r=0,o=n.length;r<o;++r)if(n[r].name===e){n[r]=f,n=n.slice(0,r).concat(n.slice(r+1));break}return null!=t&&n.push({name:e,value:t}),n}var f={value:function(){}};t.prototype=e.prototype={constructor:t,on:function(n,e){var t,f=this._,l=r(n+"",f),u=-1,a=l.length;{if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++u<a;)if(t=(n=l[u]).type)f[t]=i(f[t],n.name,e);else if(null==e)for(t in f)f[t]=i(f[t],n.name,null);return this}for(;++u<a;)if((t=(n=l[u]).type)&&(t=o(f[t],n.name)))return t}},copy:function(){var n={},e=this._;for(var r in e)n[r]=e[r].slice();return new t(n)},call:function(n,e){if((t=arguments.length-2)>0)for(var t,r,o=new Array(t),i=0;i<t;++i)o[i]=arguments[i+2];if(!this._.hasOwnProperty(n))throw new Error("unknown type: "+n);for(r=this._[n],i=0,t=r.length;i<t;++i)r[i].value.apply(e,o)},apply:function(n,e,t){if(!this._.hasOwnProperty(n))throw new Error("unknown type: "+n);for(var r=this._[n],o=0,i=r.length;o<i;++o)r[o].value.apply(e,t)}},n.dispatch=e,Object.defineProperty(n,"__esModule",{value:!0})}); | |
// https://d3js.org/d3-quadtree/ Version 1.0.1. Copyright 2016 Mike Bostock. | |
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i(t.d3=t.d3||{})}(this,function(t){"use strict";function i(t){var i=+this._x.call(null,t),r=+this._y.call(null,t);return e(this.cover(i,r),i,r,t)}function e(t,i,e,r){if(isNaN(i)||isNaN(e))return t;var n,h,s,o,a,u,l,_,f,y=t._root,x={data:r},c=t._x0,d=t._y0,v=t._x1,p=t._y1;if(!y)return t._root=x,t;for(;y.length;)if((u=i>=(h=(c+v)/2))?c=h:v=h,(l=e>=(s=(d+p)/2))?d=s:p=s,n=y,!(y=y[_=l<<1|u]))return n[_]=x,t;if(o=+t._x.call(null,y.data),a=+t._y.call(null,y.data),i===o&&e===a)return x.next=y,n?n[_]=x:t._root=x,t;do n=n?n[_]=new Array(4):t._root=new Array(4),(u=i>=(h=(c+v)/2))?c=h:v=h,(l=e>=(s=(d+p)/2))?d=s:p=s;while((_=l<<1|u)===(f=(a>=s)<<1|o>=h));return n[f]=y,n[_]=x,t}function r(t){var i,r,n,h,s=t.length,o=new Array(s),a=new Array(s),u=1/0,l=1/0,_=-(1/0),f=-(1/0);for(r=0;r<s;++r)isNaN(n=+this._x.call(null,i=t[r]))||isNaN(h=+this._y.call(null,i))||(o[r]=n,a[r]=h,n<u&&(u=n),n>_&&(_=n),h<l&&(l=h),h>f&&(f=h));for(_<u&&(u=this._x0,_=this._x1),f<l&&(l=this._y0,f=this._y1),this.cover(u,l).cover(_,f),r=0;r<s;++r)e(this,o[r],a[r],t[r]);return this}function n(t,i){if(isNaN(t=+t)||isNaN(i=+i))return this;var e=this._x0,r=this._y0,n=this._x1,h=this._y1;if(isNaN(e))n=(e=Math.floor(t))+1,h=(r=Math.floor(i))+1;else{if(!(e>t||t>n||r>i||i>h))return this;var s,o,a=n-e,u=this._root;switch(o=(i<(r+h)/2)<<1|t<(e+n)/2){case 0:do s=new Array(4),s[o]=u,u=s;while(a*=2,n=e+a,h=r+a,t>n||i>h);break;case 1:do s=new Array(4),s[o]=u,u=s;while(a*=2,e=n-a,h=r+a,e>t||i>h);break;case 2:do s=new Array(4),s[o]=u,u=s;while(a*=2,n=e+a,r=h-a,t>n||r>i);break;case 3:do s=new Array(4),s[o]=u,u=s;while(a*=2,e=n-a,r=h-a,e>t||r>i)}this._root&&this._root.length&&(this._root=u)}return this._x0=e,this._y0=r,this._x1=n,this._y1=h,this}function h(){var t=[];return this.visit(function(i){if(!i.length)do t.push(i.data);while(i=i.next)}),t}function s(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]}function o(t,i,e,r,n){this.node=t,this.x0=i,this.y0=e,this.x1=r,this.y1=n}function a(t,i,e){var r,n,h,s,a,u,l,_=this._x0,f=this._y0,y=this._x1,x=this._y1,c=[],d=this._root;for(d&&c.push(new o(d,_,f,y,x)),null==e?e=1/0:(_=t-e,f=i-e,y=t+e,x=i+e,e*=e);u=c.pop();)if(!(!(d=u.node)||(n=u.x0)>y||(h=u.y0)>x||(s=u.x1)<_||(a=u.y1)<f))if(d.length){var v=(n+s)/2,p=(h+a)/2;c.push(new o(d[3],v,p,s,a),new o(d[2],n,p,v,a),new o(d[1],v,h,s,p),new o(d[0],n,h,v,p)),(l=(i>=p)<<1|t>=v)&&(u=c[c.length-1],c[c.length-1]=c[c.length-1-l],c[c.length-1-l]=u)}else{var w=t-+this._x.call(null,d.data),N=i-+this._y.call(null,d.data),g=w*w+N*N;if(g<e){var A=Math.sqrt(e=g);_=t-A,f=i-A,y=t+A,x=i+A,r=d.data}}return r}function u(t){if(isNaN(h=+this._x.call(null,t))||isNaN(s=+this._y.call(null,t)))return this;var i,e,r,n,h,s,o,a,u,l,_,f,y=this._root,x=this._x0,c=this._y0,d=this._x1,v=this._y1;if(!y)return this;if(y.length)for(;;){if((u=h>=(o=(x+d)/2))?x=o:d=o,(l=s>=(a=(c+v)/2))?c=a:v=a,i=y,!(y=y[_=l<<1|u]))return this;if(!y.length)break;(i[_+1&3]||i[_+2&3]||i[_+3&3])&&(e=i,f=_)}for(;y.data!==t;)if(r=y,!(y=y.next))return this;return(n=y.next)&&delete y.next,r?(n?r.next=n:delete r.next,this):i?(n?i[_]=n:delete i[_],(y=i[0]||i[1]||i[2]||i[3])&&y===(i[3]||i[2]||i[1]||i[0])&&!y.length&&(e?e[f]=y:this._root=y),this):(this._root=n,this)}function l(t){for(var i=0,e=t.length;i<e;++i)this.remove(t[i]);return this}function _(){return this._root}function f(){var t=0;return this.visit(function(i){if(!i.length)do++t;while(i=i.next)}),t}function y(t){var i,e,r,n,h,s,a=[],u=this._root;for(u&&a.push(new o(u,this._x0,this._y0,this._x1,this._y1));i=a.pop();)if(!t(u=i.node,r=i.x0,n=i.y0,h=i.x1,s=i.y1)&&u.length){var l=(r+h)/2,_=(n+s)/2;(e=u[3])&&a.push(new o(e,l,_,h,s)),(e=u[2])&&a.push(new o(e,r,_,l,s)),(e=u[1])&&a.push(new o(e,l,n,h,_)),(e=u[0])&&a.push(new o(e,r,n,l,_))}return this}function x(t){var i,e=[],r=[];for(this._root&&e.push(new o(this._root,this._x0,this._y0,this._x1,this._y1));i=e.pop();){var n=i.node;if(n.length){var h,s=i.x0,a=i.y0,u=i.x1,l=i.y1,_=(s+u)/2,f=(a+l)/2;(h=n[0])&&e.push(new o(h,s,a,_,f)),(h=n[1])&&e.push(new o(h,_,a,u,f)),(h=n[2])&&e.push(new o(h,s,f,_,l)),(h=n[3])&&e.push(new o(h,_,f,u,l))}r.push(i)}for(;i=r.pop();)t(i.node,i.x0,i.y0,i.x1,i.y1);return this}function c(t){return t[0]}function d(t){return arguments.length?(this._x=t,this):this._x}function v(t){return t[1]}function p(t){return arguments.length?(this._y=t,this):this._y}function w(t,i,e){var r=new N(null==i?c:i,null==e?v:e,NaN,NaN,NaN,NaN);return null==t?r:r.addAll(t)}function N(t,i,e,r,n,h){this._x=t,this._y=i,this._x0=e,this._y0=r,this._x1=n,this._y1=h,this._root=void 0}function g(t){for(var i={data:t.data},e=i;t=t.next;)e=e.next={data:t.data};return i}var A=w.prototype=N.prototype;A.copy=function(){var t,i,e=new N(this._x,this._y,this._x0,this._y0,this._x1,this._y1),r=this._root;if(!r)return e;if(!r.length)return e._root=g(r),e;for(t=[{source:r,target:e._root=new Array(4)}];r=t.pop();)for(var n=0;n<4;++n)(i=r.source[n])&&(i.length?t.push({source:i,target:r.target[n]=new Array(4)}):r.target[n]=g(i));return e},A.add=i,A.addAll=r,A.cover=n,A.data=h,A.extent=s,A.find=a,A.remove=u,A.removeAll=l,A.root=_,A.size=f,A.visit=y,A.visitAfter=x,A.x=d,A.y=p,t.quadtree=w,Object.defineProperty(t,"__esModule",{value:!0})}); | |
// https://d3js.org/d3-timer/ Version 1.0.2. Copyright 2016 Mike Bostock. | |
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.d3=t.d3||{})}(this,function(t){"use strict";function n(){return w||(F(e),w=b.now()+x)}function e(){w=0}function i(){this._call=this._time=this._next=null}function o(t,n,e){var o=new i;return o.restart(t,n,e),o}function r(){n(),++p;for(var t,e=m;e;)(t=w-e._time)>=0&&e._call.call(null,t),e=e._next;--p}function u(t){w=(d=t||b.now())+x,p=h=0;try{r()}finally{p=0,c(),w=0}}function l(){var t=b.now(),n=t-d;n>y&&(x-=n,d=t)}function c(){for(var t,n,e=m,i=1/0;e;)e._call?(i>e._time&&(i=e._time),t=e,e=e._next):(n=e._next,e._next=null,e=t?t._next=n:m=n);_=t,a(i)}function a(t){if(!p){h&&(h=clearTimeout(h));var n=t-w;n>24?(t<1/0&&(h=setTimeout(u,n)),v&&(v=clearInterval(v))):(v||(v=setInterval(l,y)),p=1,F(u))}}function f(t,n,e){var o=new i;return n=null==n?0:+n,o.restart(function(e){o.stop(),t(e+n)},n,e),o}function s(t,e,o){var r=new i,u=e;return null==e?(r.restart(t,e,o),r):(e=+e,o=null==o?n():+o,r.restart(function n(i){i+=u,r.restart(n,u+=e,o),t(i)},e,o),r)}var m,_,p=0,h=0,v=0,y=1e3,d=0,w=0,x=0,b="object"==typeof performance&&performance.now?performance:Date,F="function"==typeof requestAnimationFrame?b===Date?function(t){requestAnimationFrame(function(){t(b.now())})}:requestAnimationFrame:function(t){setTimeout(t,17)};i.prototype=o.prototype={constructor:i,restart:function(t,e,i){if("function"!=typeof t)throw new TypeError("callback is not a function");i=(null==i?n():+i)+(null==e?0:+e),this._next||_===this||(_?_._next=this:m=this,_=this),this._call=t,this._time=i,a()},stop:function(){this._call&&(this._call=null,this._time=1/0,a())}},t.now=n,t.timer=o,t.timerFlush=r,t.timeout=f,t.interval=s,Object.defineProperty(t,"__esModule",{value:!0})}); | |
// https://d3js.org/d3-force/ Version 1.0.2. Copyright 2016 Mike Bostock. | |
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-quadtree"),require("d3-collection"),require("d3-dispatch"),require("d3-timer")):"function"==typeof define&&define.amd?define(["exports","d3-quadtree","d3-collection","d3-dispatch","d3-timer"],t):t(n.d3=n.d3||{},n.d3,n.d3,n.d3,n.d3)}(this,function(n,t,e,r,i){"use strict";function u(n,t){function e(){var e,i,u=r.length,o=0,f=0;for(e=0;e<u;++e)i=r[e],o+=i.x,f+=i.y;for(o=o/u-n,f=f/u-t,e=0;e<u;++e)i=r[e],i.x-=o,i.y-=f}var r;return null==n&&(n=0),null==t&&(t=0),e.initialize=function(n){r=n},e.x=function(t){return arguments.length?(n=+t,e):n},e.y=function(n){return arguments.length?(t=+n,e):t},e}function o(n){return function(){return n}}function f(){return 1e-6*(Math.random()-.5)}function a(n){return n.x+n.vx}function c(n){return n.y+n.vy}function l(n){function e(){function n(n,t,r,i,u){var o=n.data,a=n.r,c=g+a;{if(!o)return t>y+c||i<y-c||r>d+c||u<d-c;if(o.index>e){var h=y-o.x-o.vx,s=d-o.y-o.vy,p=h*h+s*s;p<c*c&&(0===h&&(h=f(),p+=h*h),0===s&&(s=f(),p+=s*s),p=(c-(p=Math.sqrt(p)))/p*l,v.vx+=(h*=p)*(c=(a*=a)/(x+a)),v.vy+=(s*=p)*c,o.vx-=h*(c=1-c),o.vy-=s*c)}}}for(var e,o,v,y,d,g,x,s=i.length,p=0;p<h;++p)for(o=t.quadtree(i,a,c).visitAfter(r),e=0;e<s;++e)v=i[e],g=u[e],x=g*g,y=v.x+v.vx,d=v.y+v.vy,o.visit(n)}function r(n){if(n.data)return n.r=u[n.data.index];for(var t=n.r=0;t<4;++t)n[t]&&n[t].r>n.r&&(n.r=n[t].r)}var i,u,l=1,h=1;return"function"!=typeof n&&(n=o(null==n?1:+n)),e.initialize=function(t){var e,r=(i=t).length;for(u=new Array(r),e=0;e<r;++e)u[e]=+n(i[e],e,i)},e.iterations=function(n){return arguments.length?(h=+n,e):h},e.strength=function(n){return arguments.length?(l=+n,e):l},e.radius=function(t){return arguments.length?(n="function"==typeof t?t:o(+t),e):n},e}function h(n,t){return t}function v(n){function t(n){return 1/Math.min(y[n.source.index],y[n.target.index])}function r(t){for(var e=0,r=n.length;e<p;++e)for(var i,u,o,a,h,v,y,g=0;g<r;++g)i=n[g],u=i.source,o=i.target,a=o.x+o.vx-u.x-u.vx||f(),h=o.y+o.vy-u.y-u.vy||f(),v=Math.sqrt(a*a+h*h),v=(v-l[g])/v*t*c[g],a*=v,h*=v,o.vx-=a*(y=d[g]),o.vy-=h*y,u.vx+=a*(y=1-y),u.vy+=h*y}function i(){if(v){var t,r,i=v.length,o=n.length,f=e.map(v,g);for(t=0,y=new Array(i);t<i;++t)y[t]=0;for(t=0;t<o;++t)r=n[t],r.index=t,"object"!=typeof r.source&&(r.source=f.get(r.source)),"object"!=typeof r.target&&(r.target=f.get(r.target)),++y[r.source.index],++y[r.target.index];for(t=0,d=new Array(o);t<o;++t)r=n[t],d[t]=y[r.source.index]/(y[r.source.index]+y[r.target.index]);c=new Array(o),u(),l=new Array(o),a()}}function u(){if(v)for(var t=0,e=n.length;t<e;++t)c[t]=+x(n[t],t,n)}function a(){if(v)for(var t=0,e=n.length;t<e;++t)l[t]=+s(n[t],t,n)}var c,l,v,y,d,g=h,x=t,s=o(30),p=1;return null==n&&(n=[]),r.initialize=function(n){v=n,i()},r.links=function(t){return arguments.length?(n=t,i(),r):n},r.id=function(n){return arguments.length?(g=n,r):g},r.iterations=function(n){return arguments.length?(p=+n,r):p},r.strength=function(n){return arguments.length?(x="function"==typeof n?n:o(+n),u(),r):x},r.distance=function(n){return arguments.length?(s="function"==typeof n?n:o(+n),a(),r):s},r}function y(n){return n.x}function d(n){return n.y}function g(n){function t(){u(),x.call("tick",a),c<l&&(g.stop(),x.call("end",a))}function u(){var t,e,r=n.length;for(c+=(v-c)*h,d.each(function(n){n(c)}),t=0;t<r;++t)e=n[t],null==e.fx?e.x+=e.vx*=y:(e.x=e.fx,e.vx=0),null==e.fy?e.y+=e.vy*=y:(e.y=e.fy,e.vy=0)}function o(){for(var t,e=0,r=n.length;e<r;++e){if(t=n[e],t.index=e,isNaN(t.x)||isNaN(t.y)){var i=M*Math.sqrt(e),u=e*q;t.x=i*Math.cos(u),t.y=i*Math.sin(u)}(isNaN(t.vx)||isNaN(t.vy))&&(t.vx=t.vy=0)}}function f(t){return t.initialize&&t.initialize(n),t}var a,c=1,l=.001,h=1-Math.pow(l,1/300),v=0,y=.6,d=e.map(),g=i.timer(t),x=r.dispatch("tick","end");return null==n&&(n=[]),o(),a={tick:u,restart:function(){return g.restart(t),a},stop:function(){return g.stop(),a},nodes:function(t){return arguments.length?(n=t,o(),d.each(f),a):n},alpha:function(n){return arguments.length?(c=+n,a):c},alphaMin:function(n){return arguments.length?(l=+n,a):l},alphaDecay:function(n){return arguments.length?(h=+n,a):+h},alphaTarget:function(n){return arguments.length?(v=+n,a):v},velocityDecay:function(n){return arguments.length?(y=1-n,a):1-y},force:function(n,t){return arguments.length>1?(null==t?d.remove(n):d.set(n,f(t)),a):d.get(n)},find:function(t,e,r){var i,u,o,f,a,c=0,l=n.length;for(null==r?r=1/0:r*=r,c=0;c<l;++c)f=n[c],i=t-f.x,u=e-f.y,o=i*i+u*u,o<r&&(a=f,r=o);return a},on:function(n,t){return arguments.length>1?(x.on(n,t),a):x.on(n)}}}function x(){function n(n){var e,o=u.length,f=t.quadtree(u,y,d).visitAfter(r);for(c=n,e=0;e<o;++e)a=u[e],f.visit(i)}function e(){if(u){var n,t=u.length;for(l=new Array(t),n=0;n<t;++n)l[n]=+h(u[n],n,u)}}function r(n){var t,e,r,i,u,o=0;if(n.length){for(r=i=u=0;u<4;++u)(t=n[u])&&(e=t.value)&&(o+=e,r+=e*t.x,i+=e*t.y);n.x=r/o,n.y=i/o}else{t=n,t.x=t.data.x,t.y=t.data.y;do o+=l[t.data.index];while(t=t.next)}n.value=o}function i(n,t,e,r){if(!n.value)return!0;var i=n.x-a.x,u=n.y-a.y,o=r-t,h=i*i+u*u;if(o*o/x<h)return h<g&&(0===i&&(i=f(),h+=i*i),0===u&&(u=f(),h+=u*u),h<v&&(h=Math.sqrt(v*h)),a.vx+=i*n.value*c/h,a.vy+=u*n.value*c/h),!0;if(!(n.length||h>=g)){(n.data!==a||n.next)&&(0===i&&(i=f(),h+=i*i),0===u&&(u=f(),h+=u*u),h<v&&(h=Math.sqrt(v*h)));do n.data!==a&&(o=l[n.data.index]*c/h,a.vx+=i*o,a.vy+=u*o);while(n=n.next)}}var u,a,c,l,h=o(-30),v=1,g=1/0,x=.81;return n.initialize=function(n){u=n,e()},n.strength=function(t){return arguments.length?(h="function"==typeof t?t:o(+t),e(),n):h},n.distanceMin=function(t){return arguments.length?(v=t*t,n):Math.sqrt(v)},n.distanceMax=function(t){return arguments.length?(g=t*t,n):Math.sqrt(g)},n.theta=function(t){return arguments.length?(x=t*t,n):Math.sqrt(x)},n}function s(n){function t(n){for(var t,e=0,o=r.length;e<o;++e)t=r[e],t.vx+=(u[e]-t.x)*i[e]*n}function e(){if(r){var t,e=r.length;for(i=new Array(e),u=new Array(e),t=0;t<e;++t)i[t]=isNaN(u[t]=+n(r[t],t,r))?0:+f(r[t],t,r)}}var r,i,u,f=o(.1);return"function"!=typeof n&&(n=o(null==n?0:+n)),t.initialize=function(n){r=n,e()},t.strength=function(n){return arguments.length?(f="function"==typeof n?n:o(+n),e(),t):f},t.x=function(r){return arguments.length?(n="function"==typeof r?r:o(+r),e(),t):n},t}function p(n){function t(n){for(var t,e=0,o=r.length;e<o;++e)t=r[e],t.vy+=(u[e]-t.y)*i[e]*n}function e(){if(r){var t,e=r.length;for(i=new Array(e),u=new Array(e),t=0;t<e;++t)i[t]=isNaN(u[t]=+n(r[t],t,r))?0:+f(r[t],t,r)}}var r,i,u,f=o(.1);return"function"!=typeof n&&(n=o(null==n?0:+n)),t.initialize=function(n){r=n,e()},t.strength=function(n){return arguments.length?(f="function"==typeof n?n:o(+n),e(),t):f},t.y=function(r){return arguments.length?(n="function"==typeof r?r:o(+r),e(),t):n},t}var M=10,q=Math.PI*(3-Math.sqrt(5));n.forceCenter=u,n.forceCollide=l,n.forceLink=v,n.forceManyBody=x,n.forceSimulation=g,n.forceX=s,n.forceY=p,Object.defineProperty(n,"__esModule",{value:!0})}); | |
const nodes = []; | |
for (let i = 0; i < 50; i++) { | |
nodes.push({ | |
offset: Math.random() * 360 | |
}); | |
} | |
const center = d3.forceX(totalCols / 2, 0); | |
const simulation = d3.forceSimulation(nodes) | |
.force("charge", d3.forceManyBody().strength(1)) | |
.force("center", center); | |
simulation.stop(); | |
setTimeout(function bob() { simulation.alpha(Math.random() * 0.5 + 0.5); center.x(Math.random() * totalCols); setTimeout(bob, Math.random() * 6000) }, 3000) | |
function update(currentLights, time) { | |
simulation.tick(); | |
const newLights = new Lights() | |
for (const node of nodes) { | |
const color = Color().hsl((time * 25) % 360, 100, 50) | |
let x = (Math.round(node.x) - (totalCols / 2)) % totalCols; | |
x = x >= 0 ? x : (totalCols + x); | |
newLights.set( | |
x, | |
node.y > 0 ? color : null, | |
node.y <= 0 ? color : null | |
); | |
} | |
return newLights | |
} | |
// Registers a visualization. | |
register(update) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment