Skip to content

Instantly share code, notes, and snippets.

@philipcdavis
Last active January 22, 2017 00:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipcdavis/2b626bdef4133921615a5e4fbb921e70 to your computer and use it in GitHub Desktop.
Save philipcdavis/2b626bdef4133921615a5e4fbb921e70 to your computer and use it in GitHub Desktop.
Moire
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Moire</title>
<style>
body {
background-color: black;
}
.container {
background-color: black;
margin: 0 auto;
display: block;
}
</style>
</head>
<body>
<div id="chart"></div>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var width = 960;
var height = 500;
var padding = {top: 30, right: 30, bottom: 30, left: 30};
var svg = d3.select("#chart").append("svg")
.attr("width", width)
.attr("height", height)
.attr("class", "container")
.append("g")
.attr("transform", "translate("+width / 2+", "+height / 2+")");
var data = d3.range(30).map(function(d) {
return d;
})
var angle = d3.scaleLinear()
.domain([0, d3.max(data)])
.range([0, 2 * Math.PI]);
var radius = d3.scaleLinear()
.domain([0, d3.max(data)])
.range([100, 400]);
var radialLine = d3.radialLine()
.angle(function(d) { return angle(d)})
.radius(function(d) { return radius(10 * Math.random())})
.curve(d3.curveBasisClosed);
var moire = svg.selectAll("path")
.data(Array(12).fill(1))
.enter()
.append("path")
.attr("d", radialLine(data))
.attr("fill", "none")
.attr("stroke", function(d,i) {
if (i===0) {
return "none";
} else {
return "white"
}
})
.attr("transform", function(d,i) {
return "scale("+ (i+2) / 10 +")"
})
.attr("stroke-width", 4);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment