Skip to content

Instantly share code, notes, and snippets.

@roundrobin
Created August 4, 2012 06:52
Show Gist options
  • Save roundrobin/3255239 to your computer and use it in GitHub Desktop.
Save roundrobin/3255239 to your computer and use it in GitHub Desktop.
just another inlet to tributary
function randomXToY(minVal,maxVal,floatVal)
{
var randVal = minVal+(Math.random()*(maxVal-minVal));
return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
}
tributary.init = function(g) {
var data = d3.range(0,232);
var enterSelection = g.append('g')
.attr('class','groupi')
var gg = enterSelection.selectAll('.elemets')
.data(data)
.enter()
var rect = gg.append('rect')
.attr("width",function(d,i){
return d;
})
.attr("height",function(d,i){
return d;
})
.attr("x",function(d,i){
return Math.sin(d)*1994.32;
})
.attr("y", function(d,i){
return Math.sin(d)*(211);
})
.attr("fill","#0F3D57")
.attr("stroke","#000000")
.attr("stroke-width",5);
g.rect = rect;
};
var toogle = 1;
tributary.run = function(g,t) {
var delta = Math.floor(t * 100);
var rect = g.rect;
if(delta % 96 == 0 ){
rect
.transition()
.ease('')
.duration(2000)
.attr('stroke-width',function(){
return randomXToY(0,10);
})
.attr('stroke',function(){
return '#'+Math.floor(Math.random()*16777215).toString(16);
})
.attr('x',function(){
return Math.random()*900;
})
.attr('y',function(){
return Math.random()*900;
})
.attr('opacity',function(){
return randomXToY(0,1);
})
.attr('fill',function(d,i){
var color = d3.select(this).attr('fill')
var rgb = d3.rgb(color);
if(rgb.r == 0){
toogle *= -1;
}
if(toogle == 1){
var new_color = rgb.darker();
var mode = 'drark';
}else{
var new_color = rgb.brighter();
var mode = 'bright';
}
if(i % 1000 == 0){
//console.log(new_color.toString(),rgb.r,toogle,mode)
return '#'+Math.floor(Math.random()*16777215).toString(16);
}
return new_color.toString();
})
.attr('transform',function(d,i){
var rotate = Math.random()*100;
var x = d3.select(this).attr('x')
var y = d3.select(this).attr('y')
return 'rotate('+rotate+','+x+','+y+')';
})
}
if(delta % 34 == 0 ){
//console.log(rect);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment