A Pen By
Cameron Browning

` ````
var svgContainer = d3.select("body").append("svg")
.attr("width", 1920)
.attr("height", 1080);
var c = {
x: 300,
y: 300
};
var colors = d3.scale.category20b();
var fanmodel = {
origin: {
x: 0,
y: 0
},
angle: 0,
branchCount: 3,
radius:128,
spread: Math.PI * 2
}
fanmodel.origin = {
x: 500,
y: 500
};
fan(fanmodel, 7);
function fan(f, g) {
if (f.branchCount >= 1) {
for (var i = 0; i < f.branchCount; i++) {
var newAngle;
if (f.branchCount == 1) {
newAngle = f.angle;
} else if(f.spread == Math.PI*2){
newAngle = i/f.branchCount * f.spread + f.angle;
}else {
newAngle = i / (f.branchCount - 1) * (f.spread) - f.spread / 2 + f.angle;
}
var end = {
x: (f.origin.x + Math.cos(newAngle) * f.radius),
y: (f.origin.y + Math.sin(newAngle) * f.radius)
}
//if(isNaN(end.x)){
// console.log(f.angle+ ", " + newAngle);
// console.log(f);
// }
var thisLine = svgContainer.append("line")
.attr("x1", f.origin.x)
.attr("y1", f.origin.y)
.attr("x2", end.x)
.attr("y2", end.y)
.attr("stroke-width", 7-g)
.attr("stroke",colors(g+i))
.style("opacity", 1);
var f2 = {
origin: end,
angle: newAngle,
branchCount: f.branchCount+i%2,
radius: f.radius /1.75,
spread: f.spread
};
if (g > 1 && f2.branchCount >= 1) {
fan(f2, g - 1);
} else {
}
}
}
}
```

999px

Loading
..................

Alt F
Opt F
Find & Replace

Also see: Tab Triggers