jumping mode

This commit is contained in:
Micho 2013-05-19 09:55:11 +02:00
parent 4038f1667c
commit 564f78c2c6
1 changed files with 28 additions and 17 deletions

View File

@ -9,6 +9,7 @@ var decay = Math.pow(0.8, 1/timeStep);
var stepSize = 50*timeStep; var stepSize = 50*timeStep;
var frameDuration = 40; var frameDuration = 40;
var radius = 1.4; var radius = 1.4;
var jump = false;
var interval; var interval;
var time2index = []; var time2index = [];
@ -38,6 +39,7 @@ function init() {
var node = $('<span class="button">T'+d+' '+h+':00</span>'); var node = $('<span class="button">T'+d+' '+h+':00</span>');
node.click(function () { node.click(function () {
currentTime = time; currentTime = time;
jump = true;
start(); start();
}) })
menu.append(node); menu.append(node);
@ -147,25 +149,34 @@ function updateData() {
} }
function updatePosition() { function updatePosition() {
clients.forEach(function (client) { if (jump) {
client.xo = client.x; clients.forEach(function (client) {
client.yo = client.y; client.x = client.xo = client.x0;
client.y = client.yo = client.y0;
client.r = client.r0;
});
} else {
clients.forEach(function (client) {
client.xo = client.x;
client.yo = client.y;
var dx = (client.x0 - client.x); var dx = (client.x0 - client.x);
var dy = (client.y0 - client.y); var dy = (client.y0 - client.y);
var r = Math.sqrt(dx*dx + dy+dy); var r = Math.sqrt(dx*dx + dy*dy);
if (r > 1e-2) { if (r > 1e-2) {
var rn = Math.max(r-stepSize, 0); var rn = Math.max(r-stepSize, 0);
var f = 1-rn/r; var f = 1-rn/r;
client.x += (client.x0 - client.x)*f; client.x += (client.x0 - client.x)*f;
client.y += (client.y0 - client.y)*f; client.y += (client.y0 - client.y)*f;
} else { } else {
client.x = client.x0; client.x = client.x0;
client.y = client.y0; client.y = client.y0;
} }
client.r += (client.r0 - client.r)*decay; client.r += (client.r0 - client.r)*decay;
}) });
}
jump = false;
} }
function renderCanvas() { function renderCanvas() {