color.py - add some more color methods
Adds a few methods to the color module
to_hsv() -> [h, s, v]
to_hsl() -> [h, s, l]
get_complementary() -> Color
change_hue()
change_saturation_hsv()
change_saturation_hsl()
change_value()
change_lightness()
-
darken()
(uses change_sat_hsl) -
brighten()
(uses change_sat_hsl) __mul__() -> Color
__add__() -> Color
__sub__() -> Color
Merge request reports
Activity
mentioned in issue #30 (closed)
Thanks. I guess we can leave this open for a while and then someone needs to decide which of those make sense to include or not. I was going off the description int #30 (closed) - so I hope I didn't go too far off.
I like the functions you implemented! If it is ok, I'd like to request 3 more:
# Multiply with a scalar to dim the color. Clamp at 0 and 255 # to ensure the color stays within bounds. color2 = color * 0.5 # Adding two colors. Clamped like above color3 = color1 + color2 # Similarly, subtracting (this one is not too important) color3 = color2 - color1
You can implement this behavior using some special methods.
added 6 commits
-
e370c457...4f99f17c - 5 commits from branch
card10:master
- 9f40f534 - feat(color): more methods for color manipulation
-
e370c457...4f99f17c - 5 commits from branch
Ooo, this is very cool!
MicroPython v1.11-37-g62f004ba4 on 2019-07-17; card10 with max32665 Type "help()" for more information. >>> import color >>> color.RED + color.GREEN Color(red=255, green=255, blue=0) >>> color.RED + color.GREEN == color.YELLOW True
Sadly multiplication isn't quite working:
>>> color.RED * 0.5 Traceback (most recent call last): File "<stdin>", in <module> TypeError: unsupported types for : 'Color', 'float' >>> 0.5 * color.RED Traceback (most recent call last): File "<stdin>", in <module> TypeError: unsupported types for : 'float', 'Color'
It's working on CPython though so this might be a MicroPython specific problem. I'll open a bug-issue, this shouldn't block your MR. Awesome work, thank you very much!
mentioned in commit ddcd810e
Yes, the Unix port probably has
MICROPY_PY_ALL_SPECIAL_METHODS
enabled while it was turned off for ours. I fixed it in ddcd810e. :)