Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <meta charset="utf-8">
- <body bgcolor="grey">
- <svg width="960" height="500"></svg>
- <script src="//d3js.org/d3.v4.min.js"></script>
- <script>
- var tau = 2 * Math.PI;
- var arc = d3.arc()
- .innerRadius(180)
- .outerRadius(240)
- .startAngle(0);
- var svg = d3.select("svg"),
- width = +svg.attr("width"),
- height = +svg.attr("height"),
- g = svg.append("g").attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
- var background = g.append("path")
- .datum({endAngle: tau})
- .style("fill", "#000")
- .attr("d", arc);
- var foreground = g.append("path")
- .datum({endAngle: 0.127 * tau})
- .style("fill", "red")
- .attr("d", arc);
- d3.interval(function() {
- foreground.transition()
- .duration(750)
- .attrTween("d", arcTween(Math.random() * tau));
- }, 100);
- function arcTween(newAngle) {
- return function(d) {
- var interpolate = d3.interpolate(d.endAngle, newAngle);
- return function(t) {
- d.endAngle = interpolate(t);
- return arc(d);
- };
- };
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment