Created
July 21, 2012 07:06
-
-
Save ptvans/3154925 to your computer and use it in GitHub Desktop.
just another inlet to tributary
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
var txt; | |
var n = 120; | |
var tfactor = -3.5*-10; | |
var afactor = 53.2175*16; | |
var sfactor = 101; | |
var colors = ["#2232A5", "#690083"]; | |
var size = 1.27814; | |
var percent = 0.9364; | |
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", -12.5) | |
.attr("width", 25) | |
.attr("height", 25) | |
.attr("transform", function(d, i) { return "scale(" + (d) * 20 + ")"; }) | |
.style("opacity", 0.09792) | |
.style("fill", function(d,i) { | |
return colors[i%2]; | |
}); | |
squares.map(function(d) { | |
return {center: [tributary.sw/2.4,tributary.sh/2.1], 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 + ")"; | |
}); | |
squares.attr("opacity", function(d,i) { | |
return t+0.1; | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment