From f83b5aa258520549c07b1956433720158feba065 Mon Sep 17 00:00:00 2001 From: sthag Date: Fri, 13 Feb 2026 17:35:09 +0100 Subject: [PATCH] feat: Move and add functions - Add global function randomFloatFrom() - Move getRandomColor() to app --- source/code/drag.js | 12 ----------- source/code/hippie/app.js | 22 +++++++++++++++++++++ source/screens/demo/examples/ui/drag.liquid | 1 + 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/source/code/drag.js b/source/code/drag.js index 01a489a..7bdd8e9 100644 --- a/source/code/drag.js +++ b/source/code/drag.js @@ -113,15 +113,3 @@ class NewDiv { space.appendChild(this.element); } } - -// Function to generate a random color -function getRandomColor() { - const letters = '0123456789ABCDEF'; - let color = '#'; - - for (let i = 0; i < 6; i++) { - color += letters[Math.floor(Math.random() * 16)]; - } - - return color; -} diff --git a/source/code/hippie/app.js b/source/code/hippie/app.js index 2e69574..f00f364 100644 --- a/source/code/hippie/app.js +++ b/source/code/hippie/app.js @@ -423,6 +423,12 @@ function randomIntFrom(min, max, pos = 0) { return Math.floor((Math.random() * (max - min + 1) + min) / pos) * pos; } +function randomFloatFrom(min, max, dec = 0) { + dec = Math.pow(10, dec); + + return Math.round((Math.random() * (max - min + 1) + min) * dec) / dec; +} + /** * Ersetzt \n durch
. * @@ -437,6 +443,22 @@ function replaceLineBreaks(text) { return text.split('\n').join('
'); } +/** + * Gibt eine zufällige Farbe als HEX-Wert aus. + * + * @returns {string} + */ +function getRandomColor() { + const letters = '0123456789ABCDEF'; + let color = '#'; + + for (let i = 0; i < 6; i++) { + color += letters[Math.floor(Math.random() * 16)]; + } + + return color; +} + // CONCEPTS // NOTE: Benutzt private Zuweisungen diff --git a/source/screens/demo/examples/ui/drag.liquid b/source/screens/demo/examples/ui/drag.liquid index fe8ef43..7b46674 100755 --- a/source/screens/demo/examples/ui/drag.liquid +++ b/source/screens/demo/examples/ui/drag.liquid @@ -22,6 +22,7 @@ tags: {% endblock %} {%- block script %} +