Skip to content

Instantly share code, notes, and snippets.

@thole
Last active October 20, 2018 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thole/4ec8d1afa35a43c2a5981497ecb9ac1b to your computer and use it in GitHub Desktop.
Save thole/4ec8d1afa35a43c2a5981497ecb9ac1b to your computer and use it in GitHub Desktop.
analysis
<!DOCTYPE html>
<meta charset="utf-8">
<body style="background-color:#000000">
<script type="text/javascript" src="//d3js.org/d3.v3.min.js"></script>
<script>
var width = 500,
height = 500;
var nodes = d3.range(width/2).map(function() { return {radius: Math.random()+ 1.0, angle: Math.random()*Math.PI*2} });
nodes.sort(function(a,b){ return a.angle - b.angle;})
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var margin = 20;
var circles = svg.selectAll('circle')
.data(nodes)
.enter()
.append("circle")
.attr("cx",function(d){return width/2})
.attr("cy",function(d){return height/2})
.attr("r",function(d){ return d.radius})
.style("fill","white")
.each(warp)
setTimeout(function(){
circles.transition()
.attr("cx",function(d){return width/2 + (width/2-margin) * Math.cos(d.angle)})
.attr("cy",function(d){return height/2 + (width/2-margin) * Math.sin(d.angle)})
wave()
setInterval(wave,Math.PI*1000);
},4000)
function wave(){
circles.transition()
.delay(function(d,i){return d.angle * 1000;})
.duration(250)
.attr("cx",function(d){return width/2 + (width/2-2*margin) * Math.cos(d.angle)})
.attr("cy",function(d){return height/2 + (width/2-2*margin) * Math.sin(d.angle)})
.transition()
.duration(250)
.attr("cx",function(d){return width/2 + (width/2) * Math.cos(d.angle)})
.attr("cy",function(d){return height/2 + (width/2) * Math.sin(d.angle)})
.transition()
.duration(250)
.attr("cx",function(d){return width/2 + (width/2-margin) * Math.cos(d.angle)})
.attr("cy",function(d){return height/2 + (width/2-margin) * Math.sin(d.angle)})
}
function warp() {
var circle = d3.select(this);
(function repeat() {
circle = circle.transition()
.duration(function(d){ return Math.random() * 1000 + 1000})
.attr("",function(d){ d.newR = (width/2-2*margin + Math.random() * 25) })
.attr("cx",function(d){return width/2 + d.newR * Math.cos(d.angle)})
.attr("cy",function(d){return height/2 + d.newR * Math.sin(d.angle)})
.each("end", repeat);
})();
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment