-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
36 lines (30 loc) · 1.17 KB
/
utils.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
export function BinaryRandom() {
return Math.floor(Math.random() + 0.5);
}
export function Random(from, to) {
return Math.floor(Math.random() * (to - from + 1)) + from;
}
export function toReduceSound(sound, duration) { // sound / duration sec
sound.currentTime = 0; // start playing from the beginning
sound.play().then(() => {
return setTimeout(() => {
sound.pause(); // pause playback after
}, duration * 1000); // duration sec
})
}
export function toLoopMusic(music) {
music.play();
music.loop = false; // Ensure the music does not loop automatically
music.addEventListener('ended', () => {
music.currentTime = 0; // Reset to the start
music.play(); // Play again
})
};
export function showMessage(message) {
const messageElement = document.getElementById('message');
messageElement.style.display = 'block'; // show message
messageElement.innerText = message;
setTimeout(() => {
messageElement.style.display = 'none';
}, 1500);
}