[ Launch: hexagones ] 0fbcff9edbba10ca3f24 by enjalot
-
-
Save enjalot/0fbcff9edbba10ca3f24 to your computer and use it in GitHub Desktop.
hexagones
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
{"description":"hexagones","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"ajax-caching":true,"thumbnail":"http://i.imgur.com/p1bxJ3c.png","inline-console":false} |
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
// probably from beesandbombs.tumblr.com | |
// http://i.imgur.com/ePjfPqI.gifv | |
//magic variables that will always be the width and height of the display | |
var width = tributary.sw; | |
var height = tributary.sh; | |
//the dimensions of each blade (rectangle) | |
var bladewidth = 6; | |
var bladeheight = 45; | |
//the number of prop (prop is set of 3 blades) is based on display's dimensions | |
var cols = Math.floor(width/bladeheight); | |
var rows = height / bladeheight; | |
var num = cols * rows; | |
var colwidth = bladeheight*2; | |
var colheight = colwidth; | |
var data = d3.range(num).map(function(i) { | |
var blades = d3.range(3).map(function(j) { | |
return { r: j * 120, h: bladeheight, w: bladewidth } | |
}) | |
return { | |
i: i, | |
blades: blades | |
} | |
}) | |
var svg = d3.select("svg").append("g") | |
svg.attr("transform", "translate(-30, -30)"); | |
var gs = svg.selectAll("g.prop") | |
.data(data) | |
gs.enter().append("g").classed("prop", true) | |
gs.attr({ | |
transform: function(d,i) { | |
var j = Math.floor(i/cols); | |
var x = (i % cols) * (colwidth - bladeheight/3.5 - bladewidth/2) + (j % 2 ? bladeheight*0.85 : bladewidth); | |
var y = j * (colheight - bladeheight/2 - bladewidth/2); | |
var r = j % 2 ? 0 : 120; | |
return "translate(" + [x, y] + ")rotate(" + r + ")"; | |
} | |
}) | |
var bs = gs | |
.selectAll("rect.blade") | |
.data(function(d) { return d.blades }) | |
bs.enter().append("rect").classed("blade", true) | |
bs.attr({ | |
width: function(d) { return d.w }, | |
height: function(d) { return d.h }, | |
transform: function(d) { return "rotate(" + d.r + "," + [d.w/2, 0] + ")translate(" + [0, 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
svg { | |
background: #042b3d; | |
} | |
.blade { | |
fill: #f0f8f9; | |
rx: 2; | |
ry: 2; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment