-
-
Save roundrobin/4491384 to your computer and use it in GitHub Desktop.
delta: play it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"description":"delta: play it","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"tab":"edit","display_percent":0.6269755525096976,"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,"hidepanel":false} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var svg = d3.select("svg") | |
var n = 7; | |
var cx = 200; | |
var cy = 200; | |
var opacity = 1; | |
var iterations = 7; | |
var stepSize = 1 / iterations * 2; | |
var toggle = 1; | |
//hiii | |
var rw = [51, 200] | |
var rh = [51, 200] | |
var x = [24, 410]; | |
var y = [59, 351]; | |
var color = ["#ff0000", "#0000ff"] | |
var corners = 24; | |
var nr = 6; | |
var nc = 6; | |
tributary.duration = 1500; | |
tributary.ease = d3.ease("linear") | |
//tributary.ease = d3.ease("bounce") | |
//delta.ease = d3.ease("cubic") | |
tributary.clone_opacity = 0.34145 | |
tributary.nclones = 15; | |
tributary.loop_type = 'pingpong'; | |
console.log(tributary) | |
function Path(canvas, path){ | |
this.dataPoints = []; | |
if(path != undefined){ | |
this.path = path; | |
}else{ | |
this.path = canvas.append('svg:path') | |
.attr("stroke","black") | |
.attr("stroke-width",3) | |
.attr("fill","none"); | |
} | |
} | |
Path.prototype.el = function(wayPoint){ | |
return this.path; | |
} | |
Path.prototype.add = function(wayPoint){ | |
this.dataPoints.push(wayPoint); | |
} | |
Path.prototype.render = function(){ | |
this.path.attr("d",this.pathWay()); | |
} | |
Path.prototype.pathWay = function(){ | |
var way = ''; | |
for(var i=0;i < this.dataPoints.length;i++){ | |
var elem = this.dataPoints[i]; | |
way += elem.join(' '); | |
} | |
return way; | |
} | |
var sw = parseInt(d3.select("svg").style("width")) | |
var sh = parseInt(d3.select("svg").style("height")) | |
var xoffset = sw / nr; | |
var yoffset = sh / nc; | |
var special_range = [2, 4] | |
tributary.init = function(g) { | |
for(var j = 0; j < iterations; j++){ | |
var path = new Path(svg) | |
var strokeWidth = (toggle == 1 ? 15 : 12) | |
path.el() | |
.attr("transform","translate("+[376,262]+")rotate("+(0)+")") | |
.attr('fill','none') | |
.attr('stroke','#'+Math.floor(Math.random()*16777215).toString(16)) | |
.attr('stroke-width',strokeWidth) | |
.attr('stroke-opacity', 0.5); | |
var r = 36 + (j * 13); | |
path.add(['M',r,0]); | |
for(var i = 0; i < n; i++){ | |
var cx = r * Math.cos(2 * Math.PI * i / n); | |
var cy = r * Math.sin(2 * Math.PI * i / n); | |
path.add(['L',cx,cy]); | |
} | |
path.add(['z']); | |
path.render(); | |
toggle *= -1; | |
} | |
} | |
tributary.run = function(g,t) { | |
d3.selectAll('path') | |
.attr('fill', function(d,i){ | |
var path = new Path(g,d3.select(this)) | |
var r = 36 * (i * 1); | |
path.add(['M',r, 0]); | |
for(var i = 0; i < n; i++){ | |
var cx = r * Math.cos(d3.interpolate(special_range[0], special_range[1])(t) * Math.PI * i / n); | |
var cy = r * Math.sin(d3.interpolate(special_range[0], special_range[1])(t) * Math.PI * i / n); | |
path.add(['L',cx,cy]); | |
} | |
path.add(['z']); | |
path.pathWay(); | |
path.render(); | |
return 'none'; | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment