Skip to content

Instantly share code, notes, and snippets.

@enjalot
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enjalot/0fbcff9edbba10ca3f24 to your computer and use it in GitHub Desktop.
Save enjalot/0fbcff9edbba10ca3f24 to your computer and use it in GitHub Desktop.
hexagones
{"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}
// 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] + ")" }
})
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