-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormal.js
56 lines (52 loc) · 1.56 KB
/
normal.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
function generateNormal() {
n = 8;
sum = 0;
for(var i = 1; i <= n; i++) {
sum = sum + Math.random();
}
return (2*sum - n) / n;
}
function draw(f, count, color) {
var total = 100; // Determines the bar widths in the histogram
var half = total/2;
var numbers = [];
for (var i = 0; i < total; i++) numbers[i] = 0;
for (var i = 0; i < count; i++) {
numbers[half + Math.round(half * f())]++;
}
var screenWidth = document.getElementById("maincontent").clientWidth;
var screenHeight = document.getElementById("maincontent").clientHeight;
var maxCount = Math.max(...numbers);
for (var i = 1; i < total; i++) {
$('#normal').append($('<div>').css({
left: screenWidth*i/total + 'px',
height: 0.45*screenHeight*numbers[i]/maxCount,
background: color,
width: 1.15*screenWidth/total + 'px'
}));
}
}
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
var count = 2000000; // The number of normal draws
var cols = [];
cols[1] = 143
cols[2] = 149
cols[3] = 158
draw(generateNormal, count,
'rgba('.concat(cols[1], ', ', cols[2], ', ', cols[3], ', 1)'));
// Redraw the histogram if the window is resized
$(function() {
$(window).resize(function() {
$('#normal').empty();
draw(generateNormal, count,
'rgba('.concat(cols[1], ', ', cols[2], ', ', cols[3], ', 1)'));
try {
progress(80, $('.prog-bar1'));
} catch(err) {
}
}).trigger('resize');
});