From 29ece588f0581eb1f7397017056cba18cb57b2b2 Mon Sep 17 00:00:00 2001 From: Kristofer Monisit Date: Sat, 7 Apr 2012 12:33:34 +0800 Subject: [PATCH] Bring voroboids examples up-to-date --- examples/voroboids/boid.js | 12 ++++++------ examples/voroboids/voroboids.js | 17 ++++++++++------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/examples/voroboids/boid.js b/examples/voroboids/boid.js index 0033c89b2a9aa..c0e24b2ad3efe 100644 --- a/examples/voroboids/boid.js +++ b/examples/voroboids/boid.js @@ -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); } diff --git a/examples/voroboids/voroboids.js b/examples/voroboids/voroboids.js index 2d9801dd5cb4a..72510a7b47c59 100644 --- a/examples/voroboids/voroboids.js +++ b/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); }); @@ -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);