-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasics.js
executable file
·103 lines (79 loc) · 1.95 KB
/
Basics.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
102
103
color = "#fff"
function drawRect(x,y,w,h,c){
ctx.fillStyle = c;
ctx.fillRect(x, y, w, h);
}
function drawCircle(x,y,r,c,fill=true){
//ctx.fillStyle = c;
ctx.beginPath();
ctx.arc(x,y,r,0,2*Math.PI);
if(fill = true){
ctx.fill();
ctx.strokeStyle = c;
}
ctx.stroke();
}
function drawLine(x1,y1,x2,y2,c)
{
//make line:
ctx.beginPath();
ctx.moveTo(x1,y1);
ctx.lineTo(x2,y2);
//make visable:
ctx.strokeStyle = c;
ctx.stroke();
}
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1) ) + min;
}
function sign(int)
{
if(int >= 0)
{
return 1;
}else{
return -1
}
}
// Fisher–Yates shuffle
function shuffle(array) {
var m = array.length, t, i;
// While there remain elements to shuffle…
while (m) {
// Pick a remaining element…
i = Math.floor(Math.random() * m--);
// And swap it with the current element.
t = array[m];
array[m] = array[i];
array[i] = t;
}
return array;
}
function normalize(val, array){
let max = array.length;
let min = 0;
return (val - min) / (max - min);
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function playfreq(aindex){
aindex = normalize( aindex, imgcols);
//console.log(aindex>1);
let context = parent.context;
let o = context.createOscillator()
o.type = "sine"
o.frequency.value = 120 + 1200 * (aindex*aindex);
var g = context.createGain()
g.gain.value = 2;
o.connect(g);
g.connect(parent.compressor);
context.resume();
o.start();
// await sleep(parent.speed/2)
await sleep(parent.speed)
g.gain.exponentialRampToValueAtTime(
0.00001, context.currentTime + .6
)
o.stop(context.currentTime + .6);
}