Skip to content

Instantly share code, notes, and snippets.

@mbostock
Last active February 8, 2016 23:30
Show Gist options
  • Save mbostock/714554 to your computer and use it in GitHub Desktop.
Save mbostock/714554 to your computer and use it in GitHub Desktop.
Moiré Patterns
license: gpl-3.0

Interactive Moiré pattern implemented in D3. Inspired by Max Ogden.

<!DOCTYPE html>
<meta charset="utf-8">
<title>Moiré Patterns</title>
<style>
rect {
fill: none;
pointer-events: all;
}
circle {
fill: none;
stroke: #000;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>
var w = 960,
h = 500;
var svg = d3.select("body").append("svg")
.attr("width", w)
.attr("height", h);
svg.append("rect")
.attr("width", w)
.attr("height", h);
svg.append("g").selectAll("circle")
.data(d3.range(110))
.enter().append("circle")
.attr("transform", "translate(" + w / 2 + "," + h / 2 + ")")
.attr("r", function(d) { return d * 5; });
var circle = svg.append("g").selectAll("circle")
.data(d3.range(60))
.enter().append("circle")
.attr("transform", "translate(" + w / 2 + "," + h / 2 + ")")
.attr("r", function(d) { return d * 3; });
svg.on("mousemove", function() {
var mouse = d3.mouse(this),
r = (Math.sqrt(mouse[0]) + 10) / 10;
circle
.attr("transform", "translate(" + mouse + ")")
.attr("r", function(d) { return d * r; });
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment