Skip to content

Instantly share code, notes, and snippets.

Created July 30, 2012 12:55
Show Gist options
  • Save anonymous/3206702 to your computer and use it in GitHub Desktop.
Save anonymous/3206702 to your computer and use it in GitHub Desktop.
created by livecoding - http://livecoding.gabrielflor.it
svg {
background: #000000;
}
path {
stroke: #FFFFFF;
}
var width = $('svg').width();
var height = $('svg').height();
var svg = d3.select('svg');
var g = svg.append('g');
var branches = [];
var line;
var trunk;
var createLeftBranch;
svg
.attr('width', width)
.attr('height', height);
line = d3.svg.line()
.x(function(d) { return d.x; })
.y(function(d) { return d.y; })
.interpolate('basis');
trunk = [
{ 'x': width/2, 'y': height },
{ 'x': width/2, 'y': height - 100 }
];
branches.push(trunk);
createLeftBranch = function(parent) {
var angle_degrees = 10;
var branch = [
{ 'x': parent[1].x, 'y': parent[1].y },
{ 'x': 0, 'y': 10 }
];
return branch;
};
branches.push(createLeftBranch(trunk));
g.selectAll('path')
.data(branches)
.enter().append('path')
.attr('d', line)
.style('stroke-width', 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment