[ Launch: dots more stable ] 6513427 by georules
[ Launch: dots more colors ] 6503227 by georules
[ Launch: dots2 ] 6502873 by georules
[ Launch: dots ] 6502163 by georules
[ Launch: dots ] 6497226 by georules
-
-
Save georules/6513427 to your computer and use it in GitHub Desktop.
dots with gravish
This file contains 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":"dots with gravish","endpoint":"","display":"svg","public":true,"require":[{"name":"seedrandom","url":"http://davidbau.com/encode/seedrandom-min.js"},{"name":"protovis","url":"http://mbostock.github.io/protovis/protovis-r3.2.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},"dots.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":true,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/yTy2Qir.gif","inline-console":false} |
This file contains 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
//nbody code from http://mbostock.github.io/protovis/ex/nbody.html | |
Math.seedrandom("djhkjsdhfksdf"); | |
var charge = 1; // try more for more chaos | |
var n = 500; | |
tributary.delay = 40; | |
gravity = 0.1 | |
var w = tributary.sw, | |
h = tributary.sh, | |
nodes = pv.range(n).map(function(i) { | |
return {x: w * Math.random(), | |
y: h * Math.random(), | |
r: 2 + Math.random() * 8}; | |
}); | |
var sim = pv.simulation(nodes) | |
.force(pv.Force.charge(charge)) | |
.constraint(pv.Constraint.collision(function(d) {return d.r})) | |
.stabilize(); | |
var svg = d3.select("svg") | |
var render = function(data) { | |
var circle = svg.selectAll("circle").data(data).attr( | |
{ | |
"cx":function(d) { | |
if (d.x > w) d.x = w | |
if (d.x < 0) d.x = 0 | |
return d.x.toFixed(5); | |
}, | |
"cy":function(d) { | |
if (d.y > h) d.y = h | |
if (d.y < 0) d.y = 0 | |
return d.y.toFixed(5) | |
}, | |
"r":function(d) {return d.r} | |
}) | |
.style( | |
{ | |
fill: function(d) { | |
heat = Math.sqrt(d.vx * d.vx + d.vy * d.vy)/10 | |
color = d3.interpolateHsl("#4C24EB","#34EE44")(heat) | |
return color; | |
} | |
}) | |
} | |
var grav = function(data) { | |
data.forEach(function(e,i) { | |
e.fy += gravity | |
}) | |
} | |
var tlast = 0 | |
tributary.run = function(g,t) { | |
tdiff = t-tlast | |
if (tdiff < 10) { | |
sim.step(); | |
grav(nodes); | |
render(nodes); | |
} | |
tlast = t | |
} | |
var circle = svg.selectAll("circle").data(nodes).enter().append("circle").attr( | |
{ | |
"cx":function(d) {return d.x}, | |
"cy":function(d) {return d.y}, | |
"r":function(d) {return d.r} | |
}) | |
.style( | |
{ | |
fill: function(d) {return d.c} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment