Skip to content

Instantly share code, notes, and snippets.

@enjalot
Created March 7, 2013 19:23
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 enjalot/5110960 to your computer and use it in GitHub Desktop.
Save enjalot/5110960 to your computer and use it in GitHub Desktop.
clowning around
{"description":"clowning around","endpoint":"","display":"svg","public":true,"require":[{"name":"perlin","url":"https://raw.github.com/josephg/noisejs/master/perlin.js"}],"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":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,"thumbnail":"http://i.imgur.com/86ReLcF.jpg"}
//playing with noise.js from Joseph Gentle
//https://github.com/josephg/noisejs
var n = 2148;
var period = 0.204;
var rbase = 9;
var r = tributary.sw/66;
var xspace = 25;
var nx = n/(r+xspace)
var yspace = 28;
var z = 0;
var zspeed = 0.01;
//noise.seed(Math.random());
var particles = d3.range(n).map(function(i) {
return {
x: (i % nx) * (r + xspace),
y: Math.floor(i/nx) * (r + yspace),
r: r
}
});
var svg = d3.select("svg");
var parts = svg.selectAll("circle.particle")
.data(particles)
.enter()
.append("circle")
.classed("particle", true)
.attr({
cx: function(d) { return d.x },
cy: function(d) { return d.y },
r: function(d) { return d.r }
})
.style({
fill: function(d){return ("hsl(" + (d.r*d.x*d.y) + ", 100%, 50%)")},
"fill-opacity": 0.5,
stroke: "#65119C",
"stroke-opacity": 0.91,
"stroke-width": 2.56
})
//v = noise.simplex2(p.x * period, p.y * period);
tributary.run = function(g,t) {
parts.each(function(d) {
d.v = noise.simplex3(d.x * period, d.y * period, z);
})
parts.attr({
r: function(d,i) {
d.r = rbase + (r * d.v + 5);
return d.r;
}
})
.style({
fill: function(d){return ("hsl(" + (255 - d.v * 255) + ", 100%, 50%)")}
})
z += zspeed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment