Skip to content

Instantly share code, notes, and snippets.

@enjalot
Forked from anonymous/inlet.js
Created September 10, 2012 18:01
Show Gist options
  • Save enjalot/3692573 to your computer and use it in GitHub Desktop.
Save enjalot/3692573 to your computer and use it in GitHub Desktop.
just another inlet to tributary
{"editor_editor":{"coffee":false,"vim":false,"emacs":false,"width":495,"height":260,"hide":true},"endpoint":"cypress"}
// View live at http://enjalot.com/cypress/3114111
// Original at http://www.jasondavies.com/sunflower-phyllotaxis/
var w = tributary.sw,
h = tributary.sh,
p = 6,
n = 2000,
k = 1/1500;
scale = 5;
tributary.t = 100;
tributary.init = function(ctx) {
d3.select('#display').style('background', '#111');
};
tributary.run = function(ctx,t) {
tributary.clear(); //helper function to clear the canvas
GOLDEN_ANGLE = Math.PI * (t/1500 + Math.sqrt(k*t));
var points = d3.range(1, n).map(place);
points.forEach(circle);
function circle(p,i) {
ctx.fillStyle = 'hsla(' + Math.round(310+50*i/n) + ',50%,60%,' + Math.sqrt((i/n)) + ')'
ctx.beginPath();
ctx.arc(p[0],p[1],4,0,2*Math.PI);
ctx.fill();
}
function place(n) {
var r = Math.sqrt(n),
a = n * GOLDEN_ANGLE;
return [scale * r * Math.cos(a)+w/2, scale * r * Math.sin(a)+h/2 -30];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment