-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutilities.js
71 lines (58 loc) · 1.63 KB
/
utilities.js
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//Copyright 2016 Christian Battista, PhD
//Stanford Cognitive and Systems Neuroscience Lab
//UTILITY FUNCTIONS
function makeSVG(circles){
output = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"350\" height=\"600\">";
for (i=0;i<circles.length;i++) {
output += "<circle cx=" + circles[i][0]/2 + " cy=" + circles[i][1]/2 + " r=" + circles[i][2]/2 + " fill=blue />";
}
output += "</svg>";
return output;
}
function arraysEqual(a, b) {
if (a === b) return true;
if (a == null || b == null) return false;
if (a.length != b.length) return false;
// If you don't care about the order of the elements inside
// the array, you should sort both arrays here.
for (var i = 0; i < a.length; ++i) {
if (a[i] !== b[i]) return false;
}
return true;
}
function shuffle(array) {
var currentIndex = array.length
, temporaryValue
, randomIndex
;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
function jsonToHTML(data) {
output = "";
for (var key in data) {
output += key + ": " + data[key] + "<br/>";
}
return output;
}
function clamp(value, mi, ma) {
if ((value >= mi) && (value >= ma)) {
return value;
}
else {
return Math.floor((Math.random()* ma)+1);
}
}
function range(i) {
var r = Array.apply(null, Array(i)).map(function (_, i) {return i;});;
return r;
}