Permalink
Browse files

Bring voroboids examples up-to-date

  • Loading branch information...
1 parent 30ad8bc commit 29ece588f0581eb1f7397017056cba18cb57b2b2 @kitmonisit kitmonisit committed Apr 7, 2012
Showing with 16 additions and 13 deletions.
  1. +6 −6 examples/voroboids/boid.js
  2. +10 −7 examples/voroboids/voroboids.js
View
@@ -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) {
@@ -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);
}
@@ -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);
});
@@ -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);

0 comments on commit 29ece58

Please sign in to comment.