Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created January 27, 2013 17:38
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 tmcw/4649351 to your computer and use it in GitHub Desktop.
Save tmcw/4649351 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":false,"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}
var pts = [];
d3.range(0, 30).forEach(function(x) {
return d3.range(0, 30).forEach(function(y) {
pts.push([x, y]);
});
});
var x = d3.scale.linear().range([10, 200]).domain([0, 10]);
var y = d3.scale.linear().range([10, 200]).domain([0, 10]);
var svg = d3.select("svg")
.append("svg:g")
var rect = svg.selectAll('rect')
.data(pts)
.enter()
.append('rect')
.attr({ width: 15, height: 15 })
.attr('transform', function(d) {
return 'translate(' + [x(d[0]), y(d[1])] + ')';
});
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