Skip to content

Instantly share code, notes, and snippets.

@enjalot
Created March 7, 2013 19:00
Show Gist options
  • Save enjalot/5110744 to your computer and use it in GitHub Desktop.
Save enjalot/5110744 to your computer and use it in GitHub Desktop.
perlin circles
{"description":"perlin circles","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/KOrPW4A.png"}
//playing with noise.js from Joseph Gentle
//https://github.com/josephg/noisejs
var n = 1000;
var period = 0.15;
var rbase = 5;
var r = tributary.sw/100;
var xspace = 25;
var nx = n/(r+xspace)
var yspace = 25;
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": "#198CB1",
"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.attr({
r: function(d,i) {
v = noise.simplex3(d.x * period, d.y * period, z);
return rbase + (r * v + 5);
}
})
z += zspeed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment