new time index function

This commit is contained in:
Micho 2013-05-18 17:48:16 +02:00
parent 5589945a27
commit 13ed7a63a1
1 changed files with 11 additions and 6 deletions

View File

@ -10,6 +10,8 @@ var stepSize = 50*timeStep;
var frameDuration = 50; var frameDuration = 50;
var interval; var interval;
var time2index = [];
var random = [];
$(function () { $(function () {
init(); init();
@ -38,6 +40,12 @@ function init() {
menu.append(node); 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() { function start() {
@ -75,22 +83,19 @@ function renderTime() {
} }
function updateData() { function updateData() {
var timeId = -1;
data.times.forEach(function (time, index) {
if (time < currentTime) timeId = index;
});
var points = []; var points = [];
data.points.forEach(function (point, index) { data.points.forEach(function (point, index) {
points[index] = []; points[index] = [];
}) })
data.matrix.forEach(function (times, index) { data.matrix.forEach(function (times, index) {
var timeId = time2index[Math.floor(currentTime + 15*random[index])];
var point = undefined; var point = undefined;
if (isFinite(times[timeId])) point = times[timeId]; if (isFinite(times[timeId])) point = times[timeId];
var client = clients[index]; var client = clients[index];
if ((client.point != point) && (Math.random() > 0.8)) { if (client.point != point) {
if (valid(point)) { if (valid(point)) {
client.x0 = data.points[point].x; client.x0 = data.points[point].x;
client.y0 = data.points[point].y; client.y0 = data.points[point].y;