Skip to content

Instantly share code, notes, and snippets.

@georules
Created September 7, 2013 23:46
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 georules/6480514 to your computer and use it in GitHub Desktop.
Save georules/6480514 to your computer and use it in GitHub Desktop.
bugs2
{"description":"bugs2","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}},"fullscreen":false,"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,"thumbnail":"http://i.imgur.com/c4fkC8T.gif"}
/*
<--------- CLICK OVER THERE TO MAKE BUGS
*/
var svg = d3.select('svg');
function getRandomColor() {
return d3.scale.category20();
}
function handleBBClick() {
svg.append("circle").attr({
"cx":event.offsetX,
"cy":event.offsetY,
"r":10}).style({fill:getRandomColor()})
}
var moveit = function() {
d3.selectAll("circle").attr({
"cx":function() {
v1 =10;
v2 = v1/2
dv = Math.floor(Math.random()*v1)-v2+0.5
v = this.cx.baseVal.value + dv;
if(v > tributary.sw) v = tributary.sw
if(v < 0) v = 0
return v;
},
"cy":function() {
v1 =10;
v2 = v1/2
dv = Math.floor(Math.random()*v1)-v2+0.5
v = this.cy.baseVal.value + dv;
if(v > tributary.sh) v = tributary.sw
if(v < 0) v = 0
return v;
},
"r":function() {
v = this.r.baseVal.value + Math.random()*1-0.5
if (v < 5) v = 5
return v
}
})
}
svg.on('click',handleBBClick)
tributary.run = function(g,t) {
moveit()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment