From 13ed7a63a1c43ddf65397c9fe4d57f035470f7ac Mon Sep 17 00:00:00 2001 From: Micho Date: Sat, 18 May 2013 17:48:16 +0200 Subject: [PATCH] new time index function --- clients/anim/main.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/clients/anim/main.js b/clients/anim/main.js index db59c63..596f3ab 100644 --- a/clients/anim/main.js +++ b/clients/anim/main.js @@ -10,6 +10,8 @@ var stepSize = 50*timeStep; var frameDuration = 50; var interval; +var time2index = []; +var random = []; $(function () { init(); @@ -38,6 +40,12 @@ function init() { menu.append(node); })(); } + + var index = -1; + for (var time = -60; time <= (4*24+1)*60; time++) { + while (data.times[index+1] <= time) index++; + time2index[time] = index; + } } function start() { @@ -75,22 +83,19 @@ function renderTime() { } function updateData() { - var timeId = -1; - data.times.forEach(function (time, index) { - if (time < currentTime) timeId = index; - }); - var points = []; data.points.forEach(function (point, index) { points[index] = []; }) data.matrix.forEach(function (times, index) { + var timeId = time2index[Math.floor(currentTime + 15*random[index])]; + var point = undefined; if (isFinite(times[timeId])) point = times[timeId]; var client = clients[index]; - if ((client.point != point) && (Math.random() > 0.8)) { + if (client.point != point) { if (valid(point)) { client.x0 = data.points[point].x; client.y0 = data.points[point].y;