Conversation
|
Hey @umutsoysalansys - you could use matplotlib for this purpose. See this example: import matplotlib.colors as mcolors
# Convert RGB to HEX
rgb = (0.5, 0.5, 0.5) # values between 0 and 1
hex_code = mcolors.to_hex(rgb)
print(hex_code) # Output: '#808080'
# Convert color name to HEX
color_name = 'blue'
hex_code = mcolors.to_hex(mcolors.CSS4_COLORS[color_name])
print(hex_code) # Output: '#0000FF'
# Convert HEX to HEX (just returns the same HEX code)
hex_code = '#ff6347'
hex_code = mcolors.to_hex(hex_code)
print(hex_code) # Output: '#ff6347'Matplotlib is already a dependency so no need to worry. You would need to implement some logic to check whether the input value exists in import matplotlib.colors as mcolors
def rgb_to_hex(rgb):
# Normalize RGB values (0-255) to (0-1)
rgb_normalized = [x / 255.0 for x in rgb]
# Convert to hex (implicitly treats as RGBA with A=1)
return mcolors.to_hex(rgb_normalized)
# Example usage
rgb = (127, 127, 127) # RGB values in range 0-255
hex_code = rgb_to_hex(rgb)
print(hex_code) # Output: '#7f7f7f'Implement as many sanity checks as needed for this. |
|
Since unstable image is working, I am pushing image to stable |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1357 +/- ##
==========================================
- Coverage 91.92% 91.86% -0.06%
==========================================
Files 86 86
Lines 6739 6788 +49
==========================================
+ Hits 6195 6236 +41
- Misses 544 552 +8 ☔ View full report in Codecov by Sentry. |
Description
Summary:
This pull request introduces new functionality to the geometry core, enabling users to get and set the color of a Body object. This enhancement extends the existing API by adding properties and methods that allow for seamless color management within the design environment.
New Features:
Get Color: Users can now retrieve the current color of a Body object using the color property. This property will return the color in a hexadecimal format (e.g., "#0000FF").
Set Color: The set_color method allows users to set the color of a Body object. The method accepts color values in various formats:
Formats supported:
Hexadecimal color codes (e.g., "#0000FF").
Named color strings (e.g., "blue").
RGB values as a tuple, either in the range (0-1) as floats or (0-255) as integers.
Usage Example
Issue linked
#433 related but also recent customer feedback.
Checklist
feat: extrude circle to cylinder)