🔢 Adds math function to convert to uint8

This commit is contained in:
Rune Harlyk
2024-02-23 12:45:11 +01:00
parent eb5d5b90e1
commit 0421560603
3 changed files with 36 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
export const toUint8 = (number:number, min:number, max:number) => {
number = Math.max(min, Math.min(max, number));
let scaled = ((number - min) / (max - min)) * 255;
return Math.round(scaled) & 0xFF;
}