-
Notifications
You must be signed in to change notification settings - Fork 1
/
curve.ts
67 lines (54 loc) · 1.07 KB
/
curve.ts
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
inlets = 3;
outlets = 1;
var beta = 1;
var center = 1;
var len = 2;
function msg_float(v: number) {
switch (inlet) {
case 0:
beta = v;
break;
case 1:
center = v * len;
break;
}
bang();
}
function msg_int(v: number) {
switch (inlet) {
case 0:
beta = v;
break;
case 1:
center = v;
break;
case 2:
len = v;
break;
}
bang();
}
function bang() {
let curve: number[] = [];
let max = 0;
let i = 1;
for (; i < center; i++) {
const e = len * ((center - i) / center);
const s = 1. / Math.pow(e, beta);
max = s > max ? s : max;
curve.push(s);
}
for (; i < len; i++) {
const e = i - center + 1;
const s = 1. / Math.pow(e, beta);
max = s > max ? s : max;
curve.push(s);
}
for (const i in curve) {
curve[i] = curve[i] / max;
}
curve.unshift(1);
outlet(0, curve);
}
let module = {};
export = {};