2026-04-24 FE Backup
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
def getHexColorFromInt(num, total=100):
|
||||
import colorsys
|
||||
|
||||
# Calculate the hue by evenly spacing values around the full 360-degree color wheel
|
||||
hue = (float(num) / total) * 360 # Ensure hue varies between 0 and 360 degrees
|
||||
hue = hue / 360 # Convert to range [0, 1] for colorsys compatibility
|
||||
saturation = 0.8 # High saturation for vibrant colors
|
||||
lightness = 0.5 # Moderate lightness for balanced colors
|
||||
|
||||
# Convert HSL to RGB using the colorsys module
|
||||
r, g, b = colorsys.hls_to_rgb(hue, lightness, saturation)
|
||||
|
||||
# Convert RGB values to the 0-255 range and format as a hex color
|
||||
r = int(r * 255)
|
||||
g = int(g * 255)
|
||||
b = int(b * 255)
|
||||
|
||||
# Return the color as a hex string
|
||||
color_hex = "#{:02x}{:02x}{:02x}".format(r, g, b)
|
||||
return color_hex
|
||||
|
||||
def getComplimentaryLabelColor(backgroundColor):
|
||||
# Convert hex color to RGB components
|
||||
r = int(backgroundColor[1:3], 16)
|
||||
g = int(backgroundColor[3:5], 16)
|
||||
b = int(backgroundColor[5:7], 16)
|
||||
|
||||
# Calculate luminance (perceived brightness) using the formula
|
||||
# Luminance formula adjusted for human perception
|
||||
luminance = 0.299 * r + 0.587 * g + 0.114 * b
|
||||
|
||||
# If the luminance is greater than 128, use black text; otherwise, use white text
|
||||
return '#000000' if luminance > 128 else '#FFFFFF'
|
||||
Reference in New Issue
Block a user