aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjcardus <asklocation.net@gmail.com>2024-06-30 18:07:25 +0100
committerjcardus <asklocation.net@gmail.com>2024-06-30 18:07:25 +0100
commit27f6cc527d7ca7d52c3a8fd3f70de6105c944e24 (patch)
treef9ee2c09be3ab8cdea988f2b78692f98f500e8de /src
parent28d8a5b202c6a04364144533409755c92385982a (diff)
downloadtrackermap-web-27f6cc527d7ca7d52c3a8fd3f70de6105c944e24.tar.gz
trackermap-web-27f6cc527d7ca7d52c3a8fd3f70de6105c944e24.tar.bz2
trackermap-web-27f6cc527d7ca7d52c3a8fd3f70de6105c944e24.zip
add colors.js
Diffstat (limited to 'src')
-rw-r--r--src/common/util/colors.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/common/util/colors.js b/src/common/util/colors.js
new file mode 100644
index 00000000..1cb35c04
--- /dev/null
+++ b/src/common/util/colors.js
@@ -0,0 +1,23 @@
+import { decomposeColor } from '@mui/material';
+
+export const interpolateColor = (color1, color2, factor) => {
+ if (factor > 1) factor = 1;
+ if (factor < 0) factor = 0;
+
+ const c1 = decomposeColor(color1).values;
+ const c2 = decomposeColor(color2).values;
+
+ const r = Math.round(c1[0] + factor * (c2[0] - c1[0]));
+ const g = Math.round(c1[1] + factor * (c2[1] - c1[1]));
+ const b = Math.round(c1[2] + factor * (c2[2] - c1[2]));
+
+ return `rgb(${r}, ${g}, ${b})`;
+};
+
+export const getSpeedColor = (color1, color2, color3, speed, max) => {
+ const factor = speed / max;
+ if (factor <= 0.5) {
+ return interpolateColor(color1, color2, factor * 2);
+ }
+ return interpolateColor(color2, color3, (factor - 0.5) * 2);
+};