From 2def4606de1aff4158e4149eda49a7caf6b8fef6 Mon Sep 17 00:00:00 2001 From: BOT Alex <44818698+MagicBOTAlex@users.noreply.github.com> Date: Thu, 11 Jan 2024 13:14:08 +0100 Subject: [PATCH] "WeAreText" animation WIP --- src/App.svelte | 4 +- src/lib/Universal/ZUtilities.js | 57 ++++++++++++++++++++++++++++ src/lib/WeAreText.svelte | 66 ++++++++++++++++++++++++++++++++- src/lib/WeAreText.svelte.css | 8 ++++ src/main.js | 2 +- 5 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 src/lib/Universal/ZUtilities.js create mode 100644 src/lib/WeAreText.svelte.css diff --git a/src/App.svelte b/src/App.svelte index 0eb34ba..4e9eca2 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -66,8 +66,8 @@ - - + + diff --git a/src/lib/Universal/ZUtilities.js b/src/lib/Universal/ZUtilities.js new file mode 100644 index 0000000..b589c0f --- /dev/null +++ b/src/lib/Universal/ZUtilities.js @@ -0,0 +1,57 @@ +/** + * Re-maps a number from one range to another. + * + * This function behaves similarly to the Arduino `map` function. It takes a number defined + * within a certain range (inclusive) and maps it to a new number within a different range + * (also inclusive). Optionally, the function can allow the output to exceed the mapped range. + * The function is especially useful for adapting sensor values or other input data to a specific scale. + * + * @param {number} x - The number to re-map. Expected to be within the range of in_min to in_max (inclusive). + * @param {number} in_min - The lower bound of the current range of x (inclusive). + * @param {number} in_max - The upper bound of the current range of x (inclusive). + * @param {number} out_min - The lower bound of the target range (inclusive). + * @param {number} out_max - The upper bound of the target range (inclusive). + * @param {boolean} [allowExceed=false] - Optional. If true, allows the output to exceed the specified range. + * @return {number} The re-mapped number. Constrained within out_min and out_max if allowExceed is false. + * + * @example + * // Map a sensor value from a range of 0-1023 to a range of 0-100 + * let sensorValue = 512; + * let mappedValue = map(sensorValue, 0, 1023, 0, 100); + * console.log(mappedValue); // Outputs: 50 + * + * // Example where output exceeds the range + * mappedValue = map(sensorValue, 0, 1023, 0, 100, true); + * console.log(mappedValue); // Output may exceed 100 if sensorValue > 1023 + */ +export function map(x, in_min, in_max, out_min, out_max, allowExceed = false) { + let mapped = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; + + if (!allowExceed) { + mapped = clamp(mapped, out_min, out_max); + } + + return mapped; +} + + +/** + * Clamps a number between two inclusive bounds. + * + * This function forces a number to be within a specified range. If the number is less than + * the lower bound, the lower bound is returned. If the number is greater than the upper bound, + * the upper bound is returned. Otherwise, the original number is returned. Both the lower and + * upper bounds are inclusive. + * + * @param {number} value - The number to clamp. + * @param {number} minVal - The lower bound of the clamping range (inclusive). + * @param {number} maxVal - The upper bound of the clamping range (inclusive). + * @return {number} The clamped value. + * + * @example + * console.log(clamp(7, 1, 5)); // Outputs: 5 + * console.log(clamp(2, 1, 5)); // Outputs: 2 + */ +function clamp(value, minVal, maxVal) { + return Math.max(minVal, Math.min(maxVal, value)); +} diff --git a/src/lib/WeAreText.svelte b/src/lib/WeAreText.svelte index 0faeacc..5608909 100644 --- a/src/lib/WeAreText.svelte +++ b/src/lib/WeAreText.svelte @@ -1,22 +1,84 @@
-
+
We are
\ No newline at end of file diff --git a/src/lib/WeAreText.svelte.css b/src/lib/WeAreText.svelte.css new file mode 100644 index 0000000..97b7f60 --- /dev/null +++ b/src/lib/WeAreText.svelte.css @@ -0,0 +1,8 @@ +.shine:after { + width: 120%; + background-color: rgba(255,255,255,0); + + -webkit-transition: all 0.4s ease-in-out; + -moz-transition: all 0.4s ease-in-out; + transition: all 0.4s ease-in-out; +} \ No newline at end of file diff --git a/src/main.js b/src/main.js index 8a909a1..e2b2c33 100644 --- a/src/main.js +++ b/src/main.js @@ -5,4 +5,4 @@ const app = new App({ target: document.getElementById('app'), }) -export default app +export default app \ No newline at end of file