Built with blockbuilder.org
Last active
July 1, 2017 04:42
-
-
Save ElaineYu/89a71386cd661a45da85bd3dbf2909ad to your computer and use it in GitHub Desktop.
Sam Francis Icosahedron Art Toy For Tim
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: mit |
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"> | |
<style> | |
body { | |
background-color: black; | |
} | |
path { | |
fill: black; | |
stroke: white; | |
stroke-width: 2px; | |
} | |
</style> | |
<body> | |
<svg id="mySvg" width="10" height="10"> | |
<defs id="mdef"> | |
<pattern id="image" x="0" y="0" height="10" width="10"> | |
<image x="-130" y="-130" width="700" height="700" xlink:href="https://s3-us-west-2.amazonaws.com/sfmomamedia/media/t/collection_images/7rTmTYOv1aUb.jpg"></image> | |
</pattern> | |
</defs> | |
</svg> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script> | |
var width = 960, | |
height = 500; | |
var velocity = [.01, .01], | |
t0 = Date.now(); | |
var projection = d3.geo.orthographic() | |
.scale(height / 2 - 10); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
var face = svg.selectAll("path") | |
.data(icosahedronFaces) | |
.enter().append("path") | |
.each(function(d) { d.polygon = d3.geom.polygon(d.map(projection)); }); | |
d3.timer(function() { | |
var time = Date.now() - t0; | |
projection.rotate([time * velocity[0], time * velocity[1]]); | |
face | |
.each(function(d) { d.forEach(function(p, i) { d.polygon[i] = projection(p); }); }) | |
.style("display", function(d) { return d.polygon.area() > 0 ? null : "none"; }) | |
.style("fill", "url(#image)") | |
.attr("d", function(d) { return "M" + d.polygon.join("L") + "Z"; }); | |
}); | |
function icosahedronFaces() { | |
var faces = [], | |
y = Math.atan2(1, 2) * 180 / Math.PI; | |
for (var x = 0; x < 360; x += 72) { | |
faces.push( | |
[[x + 0, -90], [x + 0, -y], [x + 72, -y]], | |
[[x + 36, y], [x + 72, -y], [x + 0, -y]], | |
[[x + 36, y], [x + 0, -y], [x - 36, y]], | |
[[x + 36, y], [x - 36, y], [x - 36, 90]] | |
); | |
} | |
return faces; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment