Skip to content

Instantly share code, notes, and snippets.

/_.md

Created December 15, 2012 18:32
Show Gist options
  • Save anonymous/4297902 to your computer and use it in GitHub Desktop.
Save anonymous/4297902 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.5528887421591288,"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");
// 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 = 87+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});
t.selectAll("g")
.data(function(d){return d.stuff.moarvalues})
.enter()
.append("rect")
.attr( { "x":function(d,i){return i*4},"width":3, "height": function(d){return d;} } );
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)) } });
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,100)");
// t.selectAll("g").data(s,function(d){ return d.stuff.moarvalues;}).enter().append("rect")
// .attr( { "fill":"#F73DD9","x":function(d,i){return i*8+4}, "width":3, "height": function(d){return d;} } );
setInterval(function() {
pick();
svg.selectAll("g").selectAll("path")
.data(s,function(d){return d})
.transition().duration(1500)
.attr({"d": function(d){ return lineFunction(yo(d.stuff.values)) } });
//svg.selectAll("rect").data(data)
//.transition()
//.duration(500)
//.attr({"fill":"#3D9DF7","x":13,"height":3,"y":function(d,i){return i*4+223;},"width":function(d){return d;}});
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment