Skip to content

Instantly share code, notes, and snippets.

@adilapapaya
Created January 19, 2016 14:58
Show Gist options
  • Save adilapapaya/f2467e769bbb7da62bdb to your computer and use it in GitHub Desktop.
Save adilapapaya/f2467e769bbb7da62bdb to your computer and use it in GitHub Desktop.
Emanating Circles
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<div id="svg-div"></div>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script>
var DEG_TO_RADIAN = Math.PI / 180; // convert degrees to radian
var minRadius = 100;
var maxRadius = 340;
var degrees = [0, 15, 30, 45, 60, 75];
var radius = new Array(6);
var svg = d3.select("#svg-div")
.append("svg")
.attr("width", 800)
.attr("height", 800)
var g = svg.append("g")
.attr("transform", "translate(400, 400)");
function incrementArray(){
degrees.forEach(function(d, i){
degrees[i] = (degrees[i] + 1) % 90;
var radian = degrees[i] * DEG_TO_RADIAN;
var sine = Math.sin(radian);
radius[i] = Math.round(minRadius + sine * (maxRadius-minRadius))
});
// console.log("Radius = " + radius.join(", "))
// -----------------------------------
// show what the output looks like
var circles = g.selectAll("circle")
.data(radius)
circles
.enter().append("circle")
circles
.attr("r", Number)
.style("fill", "none")
.style("stroke", "#aaa")
circles.exit().remove();
}
setInterval(incrementArray, 50)
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment