working
This commit is contained in:
parent
466574a856
commit
3776791239
3 changed files with 17 additions and 7 deletions
|
|
@ -61,3 +61,10 @@ export function nanFallback(value, fallback) {
|
|||
}
|
||||
return value;
|
||||
}
|
||||
// modulo that works with negative numbers e.g. _mod(-1, 3) = 2. Works on numbers (rather than patterns of numbers, as @mod@ from pattern.mjs does)
|
||||
export const _mod = (n, m) => ((n % m) + m) % m;
|
||||
|
||||
// round to nearest int, negative numbers will output a subtracted index
|
||||
export const getSoundIndex = (n, numSounds) => {
|
||||
return _mod(Math.round(nanFallback(n, 0)), numSounds);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue