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.category10();
var fanmodel = {
origin: {
x: 0,
y: 0
},
angle: 0,
branchCount: 10,
radius:128,
spread: Math.PI * 2
}
fanmodel.origin = {
x: 500,
y: 500
};
fan(fanmodel, 4);
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", g*3-2)
.attr("stroke",colors(i))
.style("opacity", 0.3);
var f2 = {
origin: end,
angle: newAngle*1.01,
branchCount: f.branchCount,
radius: f.radius / 1.75,
spread: f.spread / 1.25
};
if (g > 1 && f2.branchCount >= 1) {
fan(f2, g - 1);
} else {
}
}
}
}
```

999px

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

Alt F
Opt F
Find & Replace

Also see: Tab Triggers