Skip to content

Instantly share code, notes, and snippets.

@hemulin
Created October 28, 2012 23:23
Show Gist options
  • Save hemulin/3970409 to your computer and use it in GitHub Desktop.
Save hemulin/3970409 to your computer and use it in GitHub Desktop.
just another inlet to tributary
{"endpoint":"","display":"svg","public":true,"require":[],"tab":"edit","display_percent":0.7,"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,"editor_editor":{"coffee":false,"vim":false,"emacs":false,"width":600,"height":300,"hide":false}}
var w = 900, h = 600;
var r = 2, rStep = 0.06,
cr = 10, crStep = 1.2, n = 222,
step = (9*Math.PI)/n, angle = 0;
var circles = new Array();
var newColor = function(d) {
return 'rgb(' + Math.floor(255 * Math.random()) +
', ' + Math.floor(255 * Math.random()) +
', ' + Math.floor(255 * Math.random()) + ')';
}
//############################
var visArea = d3.select("svg")
.attr("width", w)
.attr("height", h);
var circle;
for (var i = 0; i < n; i++) {
circle = createCircle();
circles.push(circle);
angle += step;
cr += crStep;
r += rStep;
}
function createCircle() {
var circle = visArea.append("circle")
.attr("r", r)
.attr("cx", (w/2)+cr*Math.cos(angle))
.attr("cy", (h/2)+cr*Math.sin(angle))
.style("fill", newColor);
return {"r": r, "cr": cr, "a": angle, "element": circle};
}
function rotateAll() {
for (var i = 0; i < circles.length; i++) {
circles[i].a -= Math.floor(i/10)/circles.length//0.01064;
//circles[i].a -= 0.01064;
circles[i].element//.transition().duration()
.attr("cx", (w/2)+circles[i].cr*Math.cos(circles[i].a))
.attr("cy", (h/2)+circles[i].cr*Math.sin(circles[i].a));
}
}
tributary.run = function(g,t) {
rotateAll();
}
//window.rotateAll = rotateAll;
//setInterval(window.rotateAll, 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment