Skip to content

Instantly share code, notes, and snippets.

@ptvans
Created July 26, 2012 05:08
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 ptvans/3180371 to your computer and use it in GitHub Desktop.
Save ptvans/3180371 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 = 43,
n = 2738,
scale = 69,
radius = 36,
c = 0.17741,
theta = 0.6;
var colors = ["#D5CE2A", "#D30054", "#6800B9"];
"#67007A"
var fopacity = 0.35;
var sopacity = .5;
var stroke_color = "#F2FC00";
var stroke_width =-0;
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