Skip to content

Instantly share code, notes, and snippets.

@lennyjpg
Created December 15, 2012 21:14
Show Gist options
  • Save lennyjpg/4299282 to your computer and use it in GitHub Desktop.
Save lennyjpg/4299282 to your computer and use it in GitHub Desktop.
Another Inlet
{"description":"Another Inlet","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":false,"vim":true,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"tab":"edit","display_percent":0.5539876432580297,"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,"hidepanel":false}
var dataset=[], lineData=[], a=0, data=[], i, num=26, r, step= (360 / num) / 180 *Math.PI ;
var svg = d3.select("svg");
svg.append("rect").attr(
{"width":"100%","height":"100%","fill":"#EEE"}
)
// generates 26 fake numbers in an array
var fakearray = function(){
var tmp=[];
for( i = 0; i < num; i++ )tmp[i]=Math.ceil(Math.random()*50);
return tmp;
}
// creates a stack of fake objects to work with
for(var e = 0; e < 99; e++ ){
var tmp = { "color":"#000333","stuff":{"num":2,"values":fakearray(),"moarvalues":fakearray()}};
dataset.push(tmp);
}
//console.log(dataset);
var xxx = d3.scale.linear()
.range([0, 273]);
var s=[];
function pick(){
var chosen="";
for( var f = 0; f < 3; f++){
var index=Math.round(Math.random()*dataset.length);
chosen+=index+" ";
s[f]= dataset[ index ] ;
}
//console.log(chosen);
}
pick();
var yo= function(d,i){
var m=[];
for( i = 0; i < num; i++ ){
r = 80+d[i];
a += step;
m[i]= {"x": Math.sin(a)*r, "y": Math.cos(a)*r} ;
}
return m;
}
var lineFunction = d3.svg.line()
.x(function(d) { return d.x; })
.y(function(d) { return d.y; })
.interpolate("basis-closed");
var t=svg.selectAll("g")
.data(s)
.enter()
.append("g")
.attr({"transform":function(d,i){ return "translate("+xxx(i)+",300)"},"x":function(d,i){return i*200},"y":0});
var one = t.data(s,function(d){return d.stuff.values;})
.append("path")
.attr("class","one")
.attr('opacity',0.76)
.attr('fill','#F01046')
.transition().duration(200).attr({"d": function(d){ return lineFunction(yo(d.stuff.values)) } });
var two = t.data(s,function(d){return d.stuff.moarvalues;})
.append("path")
.attr("class","two")
.attr('opacity',0.56)
.attr('fill','#00ADFF')
.transition().duration(200).attr({"d": function(d){ return lineFunction(yo(d.stuff.moarvalues)) } });
svg.selectAll("path").attr("transform", "translate(200,200)");
t.selectAll("g")
.data(function(d){return d.stuff.moarvalues})
.enter()
.append("rect")
.attr( { "opacity":0.5,"fill":"#9DA09D","x":function(d,i){return i*8+59},"y":function(d){return 60-d-50;},"width":3, "height": function(d){return d;} } );
t.selectAll("g")
.data(function(d){return d.stuff.values})
.enter()
.append("rect")
.attr( { "opacity":0.5,"fill":"#050505","x":function(d,i){return i*8+59+3},"y":function(d){return 60-d-50;},"width":3, "height": function(d){return d;} } );
setInterval(function() {
pick();
}, 2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment