chart = {
const svg = d3.create("svg")
.attr("height", 512)
.attr("width", 512)
.attr('viewBox', "-256 -256 512 512")
.attr('style', 'background: #25321E')
let points = (new Array(2048)).fill(0).map(p => {
let x = (Math.random()-.5)*512
let y = (Math.random()-.5)*512
let z = (Math.random()-.5)*512
let source = new THREE.Vector3(x, y, z);
let distance, norm, diff, target
target = source.clone()
for(let i = 0; i < 3; i++) {
distance = mpa(source, new THREE.Vector3(0, 0, 0));
norm = normal(source).multiplyScalar(-1);
diff = norm.clone().multiplyScalar(distance);
source = target.clone();
target.add(diff);
if(Math.abs(distance)<1e-10){
let slideDistance = 10;
let slide = norm.clone().applyAxisAngle(new THREE.Vector3(0,0,1), 3.1415/2).multiplyScalar(slideDistance);
target.add(slide);
}
}
let destination = target.clone();
return [source, destination]
})
svg.selectAll('line')
.data( points )
.enter()
.append('line')
.attr('x1', p => p[0].x)
.attr('y1', p => p[0].y)
.attr('x2', p => p[1].x)
.attr('y2', p => p[1].y)
.attr('stroke', p => mpa(p[0], new THREE.Vector3(0, 0, 0)) < 0 ? '#00A1BC' : '#FCE000')
.attr('stroke-width', 1)
svg.selectAll('circle')
.data( points )
.enter()
.append('circle')
.attr('cx', p => p[1].x)
.attr('cy', p => p[1].y)
.attr('r', p => 1)
.attr('fill', p => mp(p[0]) < 0 ? '#00A1BC' : '#FCE000')
return svg.node()
}