-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoise_maker.js
More file actions
25 lines (24 loc) · 928 Bytes
/
noise_maker.js
File metadata and controls
25 lines (24 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"use strict";
var _ = require('lodash');
module.exports = function (app) {
var spots = [];
var loop = function (i) {
var rand = Math.round(Math.random() * 6000) + 1000;
setTimeout(function () {
var new_val = (Number(spots[i].value) + (Math.random() * Math.pow(-1, Math.floor(Math.random() * 2 + 1)))).toFixed(2);
spots[i].direction = new_val > spots[i].value ? 'positive' : 'negative';
spots[i].value = (Number(spots[i].value) + (Math.random() * Math.pow(-1, Math.floor(Math.random() * 2 + 1)))).toFixed(2);
app.webSockets.emit('spot update', spots[i]);
loop(i);
}, rand);
};
for (var i = 0; i < 300; i++) {
spots.push({title: 'spot' + i, value: (Math.random() * 1000).toFixed(2), direction: 'neutral'});
loop(i);
}
return {
getSpots: function () {
return spots;
}
};
};