Skip to content

Instantly share code, notes, and snippets.

@enjalot
Created January 28, 2013 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enjalot/4653576 to your computer and use it in GitHub Desktop.
Save enjalot/4653576 to your computer and use it in GitHub Desktop.
Tributary inlet
{"description":"Tributary inlet","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"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}},"play":true,"loop":true,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"fullscreen":false,"thumbnail":"http://i.imgur.com/lga4cXU.png"}
var pts = [];
var n = 20;
d3.range(0, n).forEach(function(x) {
return d3.range(0, n).forEach(function(y) {
pts.push([x, y]);
});
});
var x = d3.scale.linear().range([10, 355]).domain([0, 10]);
var y = d3.scale.linear().range([10, 306]).domain([0, 10]);
tributary.loop_type = "period";//"off", "normal"
tributary.init = function(g) {
var rect = g.selectAll('rect')
.data(pts)
.enter()
.append('rect')
.attr({ width: 65, height: 40 })
.attr('transform', function(d) {
return 'translate(' + [x(d[0]), y(d[1])] + ')';
});
};
tributary.run = function(g,tt,i) {
//console.log(t);
var t = tt * 12
g.selectAll("rect")
.attr({
"transform": function(d,i) {
return 'translate(' + [x(d[0]), y(d[1])] + ') rotate(' + (Math.sin(d[0] + d[1] + t) * 30) + ' 5 5)';}
,"fill": function(d,i) {
return 'hsl(' + (Math.sin(d[0] + d[1] + t) * 30) + ', 90%, 50%)';
},
"fill-opacity": 0.10944,
"stroke": "#ffffff",
"stroke-opacity": 0.38
})
}
/*
d3.timer(function() {
var t = (+new Date() / 1000);
rect.attr('transform', function(d) {
return 'translate(' + [x(d[0]), y(d[1])] + ') rotate(' + (Math.sin(d[0] + d[1] + t) * 30) + ' 5 5)';
})
.attr('fill', function(d) {
return 'hsl(' + (Math.sin(d[0] + d[1] + t) * 30) + ', 90%, 50%)';
});
}, 100);*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment