Interactive Moiré pattern implemented in D3. Inspired by Max Ogden.
Last active
February 8, 2016 23:30
-
-
Save mbostock/714554 to your computer and use it in GitHub Desktop.
Moiré Patterns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: gpl-3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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