-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f92858a
commit 734ca55
Showing
3 changed files
with
26 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export function floatToHex(value) { | ||
// courtesy of GPT :3 | ||
// Ensure the input value is within the valid range [0, 1] | ||
value = Math.min(1, Math.max(0, value)); | ||
|
||
// Interpolate between white (#FFFFFF) and black (#000000) | ||
var red = Math.round((1 - value) * 255); | ||
var green = Math.round((1 - value) * 255); | ||
var blue = Math.round((1 - value) * 255); | ||
|
||
// Convert RGB values to hexadecimal format | ||
var redHex = red.toString(16).padStart(2, '0'); | ||
var greenHex = green.toString(16).padStart(2, '0'); | ||
var blueHex = blue.toString(16).padStart(2, '0'); | ||
|
||
// Return the color as a hexadecimal string | ||
return '#' + redHex + greenHex + blueHex; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters