-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGaussians.js
101 lines (98 loc) · 2.64 KB
/
Gaussians.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
function getGaussian(mean, standardDeviation, maxHeight,x) {
return maxHeight * Math.pow(Math.E, -Math.pow(x - mean, 2) / (2 * (standardDeviation * standardDeviation)));
};
function attachGaussian(angle,heights)
{
var left_side = Math.floor(angle) - 50;
if (left_side < 0){
left_side = 360 - Math.abs(left_side);
}
for (var a = 1; a <= 50; a++)
{
var temp_angle = left_side + a;
if (temp_angle > 360){
temp_angle = temp_angle - 360;
}
if (heights[temp_angle]>.01)
{
heights[temp_angle] = heights[temp_angle] + .5*getGaussian(50,8,.1,a);
}
else
{
heights[temp_angle] = getGaussian(50,8,.1,a);
}
if (heights[temp_angle] < .01)
{
heights[temp_angle] = 0;
}
}
for (var b=1; b <= 50; b++)
{
var temp_angle = Math.floor(angle) + b;
if (temp_angle>360){
temp_angle = temp_angle - 360;
}
if (temp_angle < 0){
temp_angle = 360 - Math.abs(temp_angle);
}
if (heights[temp_angle]>.01)
{
heights[temp_angle] = heights[temp_angle] + .5*getGaussian(50,8,.1,(b+50-1));
}
else
{
heights[temp_angle] = getGaussian(50,8,.1,(b+50-1));
}
if (heights[temp_angle] < .01)
{
heights[temp_angle] = 0;
}
}
return heights;
};
function moveGaussian(angle)
{
var heights = Array(360).fill(0);
var left_side = Math.floor(angle) - 50;
if (left_side <= 0){
left_side = 360 - Math.abs(left_side);
}
for (var a = 1; a <= 50; a++)
{
var temp_angle = left_side + a;
if (temp_angle >= 360){
temp_angle = temp_angle - 360;
}
if (heights[temp_angle]>.01)
{
heights[temp_angle] = heights[temp_angle] + .5*getGaussian(50,8,.1,a);
}
else
{
heights[temp_angle] = getGaussian(50,8,.1,a);
}
}
for (var b=1; b <= 50; b++)
{
var temp_angle = Math.floor(angle) + b;
if (temp_angle>=360){
temp_angle = temp_angle - 360;
}
if (temp_angle < 0){
temp_angle = 360 - Math.abs(temp_angle);
}
if (heights[temp_angle]>.01)
{
heights[temp_angle] = heights[temp_angle] + .5*getGaussian(50,8,.1,(b+50-1));
}
else
{
heights[temp_angle] = getGaussian(50,8,.1,(b+50-1));
}
if (heights[temp_angle] < .01)
{
heights[temp_angle] = 0;
}
}
return heights;
};