Skip to content

Instantly share code, notes, and snippets.

@ptvans
Created July 26, 2012 03:05
Show Gist options
  • Save ptvans/3180008 to your computer and use it in GitHub Desktop.
Save ptvans/3180008 to your computer and use it in GitHub Desktop.
just another inlet to tributary
// Original at http://www.jasondavies.com/sunflower-phyllotaxis/
//forked from Kai's (syntagmatic) implementation
//http://enjalot.com/cypress/3114111/
var w = tributary.sw,
h = tributary.sh,
p = 9,
n = 2372,
scale = 10,
radius = 10,
c = 0.72,
theta = 0.6;
var colors = ["#D5CE2A", "#00D37E", "#4806AA"];
"#47227E"
var fopacity = 0.9408;
var sopacity = .78;
var stroke_color = "#F2FC00";
var stroke_width =2;
var colour = d3.scale.linear().domain([0, n / 2, n])
.interpolate(d3.cie.interpolateLch)
.range(colors);
tributary.loop = "pingpong";
tributary.init = function(g) {
var vis = g.append("g")
.attr("transform", "translate(" + (p + w / 2) + "," + (p + h / 2) + ")");
var points = d3.range(1, n)
vis.selectAll("circle")
.data(points)
.enter().append("circle")
.attr("r", radius)
.style("fill-opacity", fopacity)
.style("stroke", stroke_color)
.style("stroke-width", stroke_width)
.style("stroke-opacity", sopacity)
.style("fill", function(d, i) { return colour(i); }) ;
};
tributary.run = function(g,t) {
/*angles = [Math.PI * (1 - Math.sqrt(5)),
Math.PI * (2 - Math.sqrt(5))];
var angle = d3.interpolateNumber(angles[0], angles[1])(t);*/
var angle = Math.PI * (theta - Math.sqrt(5)) + t/50;
g.selectAll("circle")
.attr("cx", function(d) {
var r = c * Math.sqrt(d);
var a = d * angle;
return scale * r * Math.cos(a);
})
.attr("cy", function(d) {
var r = c * Math.sqrt(d);
var a = d * angle;
return scale * r * Math.sin(a);
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment