Skip to content

Instantly share code, notes, and snippets.

@enjalot
Created August 4, 2013 04:01
Show Gist options
  • Save enjalot/6149065 to your computer and use it in GitHub Desktop.
Save enjalot/6149065 to your computer and use it in GitHub Desktop.
bart paths
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{"description":"bart paths","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"bart.svg":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"seglist.js":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":true,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/r3ZQL7b.png"}
var svg = d3.select("svg");
var trains = [];
var circleData = d3.range(6).map(function() { return {} });
var lines = svg.select("#lines")
.selectAll("path")
.data(circleData)
.each(function(d) {
var n = Math.floor(1 + Math.random() * 6);
var node = this;
d3.range(n).forEach(function() {
trains.push({
len: node.getTotalLength(),
node: node,
start: Math.random()
})
})
})
var circles = svg.selectAll("circle")
.data(trains)
circles.enter()
.append("circle").classed("train", true)
.attr({
cx: function(d) { return d.x },
cy: function(d) { return d.y },
r: 5,
fill: "#5C5A61",
stroke: "#eeeeee"
})
tributary.run = function(g,t) {
circles.each(function(d,i) {
var o = (Math.sin(2 *Math.PI * (d.start + t/10)) + 1)/2;
var p = d.node.getPointAtLength(o*d.len);
d3.select(this).attr({
cx: p.x,
cy: p.y
})
})
}
tributary.loop_type = "period";
/*
var richmond = svg.select("#richmond")
path = richmond;
var seglist = path.node().pathSegList;
//console.log(seglist);
var segPathData = d3.range(seglist.numberOfItems).map(function(d, i){
var item = seglist.getItem(i);
return item;
});
//console.log("list:", segPathData);
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment