Skip to content

Commit

Permalink
Bring voroboids examples up-to-date
Browse files Browse the repository at this point in the history
  • Loading branch information
kitmonisit committed Apr 7, 2012
1 parent 30ad8bc commit 29ece58
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
12 changes: 6 additions & 6 deletions examples/voroboids/boid.js
Expand Up @@ -184,10 +184,10 @@ var boid = (function() {
}

function d3_ai_boidWrap(position) {
if (position[0] > w) position[0] = 0;
else if (position[0] < 0) position[0] = w;
if (position[1] > h) position[1] = 0;
else if (position[1] < 0) position[1] = h;
if (position[0] > width) position[0] = 0;
else if (position[0] < 0) position[0] = width;
if (position[1] > height) position[1] = 0;
else if (position[1] < 0) position[1] = height;
}

function d3_ai_boidGravity(center, position, neighborRadius) {
Expand All @@ -207,8 +207,8 @@ var boid = (function() {
function d3_ai_boidDistance(a, b) {
var dx = a[0] - b[0],
dy = a[1] - b[1];
if (dx > w / 2) dx = w - dx;
if (dy > h / 2) dy = h - dy;
if (dx > width / 2) dx = width - dx;
if (dy > height / 2) dy = height - dy;
return Math.sqrt(dx * dx + dy * dy);
}

Expand Down
17 changes: 10 additions & 7 deletions examples/voroboids/voroboids.js
@@ -1,12 +1,15 @@
var w = 960,
h = 500,
mouse = [null, null],
fill = d3.scale.linear().domain([0, 1e4]).range(["brown", "steelblue"]);
var width = 960,
height = 500,
mouse = [null, null];

var fill = d3.scale.linear()
.domain([0, 1e4])
.range(["brown", "steelblue"]);

// Initialise boids.
var boids = d3.range(100).map(function() {
return boid()
.position([Math.random() * w, Math.random() * h])
.position([Math.random() * width, Math.random() * height])
.velocity([Math.random() * 2 - 1, Math.random() * 2 - 1])
.gravityCenter(mouse);
});
Expand All @@ -20,8 +23,8 @@ d3.select(window).on("blur", nullGravity);

var svg = d3.select("#vis")
.append("svg")
.attr("width", w)
.attr("height", h)
.attr("width", width)
.attr("height", height)
.attr("class", "PiYG")
.on("mousemove", function() {
var m = d3.mouse(this);
Expand Down

0 comments on commit 29ece58

Please sign in to comment.