Skip to content

Instantly share code, notes, and snippets.

@ejfox
Created July 14, 2012 02:55
Show Gist options
  • Save ejfox/3108961 to your computer and use it in GitHub Desktop.
Save ejfox/3108961 to your computer and use it in GitHub Desktop.
just another inlet to tributary
var txt;
var n = 42;
var tfactor = 5 * Math.PI;
var afactor = 25 * Math.PI;
var sfactor = 18;
var colors = ["#76E4F3", "#000000"];
var size = 1.2;
var percent = 0.864;
var data = _.map(d3.range(n), function(d,i) {
size *= percent;
return size;
});
tributary.loop = "pingpong";
tributary.init = function(g) {
g.append("rect")
.attr("width", "100%")
.attr("height", "100%");
var squares = g.selectAll("g.square")
.data(data)
.enter().append("svg:g")
.classed("square", true)
.attr("transform", "translate(" + [0,0] + ")");
squares.append("svg:rect")
.attr("rx", 6)
.attr("ry", 6)
.attr("x", -12.5)
.attr("y", -15.5)
.attr("width", 200)
.attr("height", 25)
.attr("transform", function(d, i) { return "scale(" + (d) * 20 + ")"; })
.style("fill", function(d,i) {
return colors[i%2];
});
squares.map(function(d) {
return {center: [tributary.sw/2,tributary.sh/2], angle: 0};
});
};
tributary.run = function(g,t) {
var squares = g.selectAll("g.square")
squares.attr("transform", function(d, i) {
//d.center[0] += (mouse[0] - d.center[0]) / (i + 5);
//d.center[1] += (mouse[1] - d.center[1]) / (i + 5);
//shoudl be more elegant way to reset this
d.angle += Math.sin((t*tfactor + i) / afactor) * sfactor;
return "translate(" + d.center + ")rotate(" + d.angle + ")";
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment