[ Launch: antisocial dots 2 ] 6542901 by georules
[ Launch: antisocial dots ] 6517275 by georules
[ 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
antisocial dots 2
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":"antisocial dots 2","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/knLP7VF.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 = -100; // try more for more chaos | |
var n = 500; | |
tributary.delay = 40; | |
var w = tributary.sw, | |
h = tributary.sh, | |
nodes = pv.range(n).map(function(i) { | |
return {x: w * Math.random(), | |
y: h * Math.random(), | |
r: 10 + 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") | |
svg.append("rect").attr({width: "100%", height: "100%"}).style("fill", "#655BAA"); | |
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) | |
if (d.fy >0) color = "#00ff00" | |
if (d.fy <=0) color = "#1F00FF" | |
color = d3.interpolateRgb("#DA1E1E","#000000")(d.vy) | |
return color; | |
} | |
}) | |
} | |
var tlast = 0 | |
tributary.run = function(g,t) { | |
tdiff = t-tlast | |
if (tdiff < 10) { | |
sim.step(); | |
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