diff --git a/manim/utils/color/core.py b/manim/utils/color/core.py index eac3127225..d8731f5d1b 100644 --- a/manim/utils/color/core.py +++ b/manim/utils/color/core.py @@ -601,7 +601,8 @@ def to_hsl(self) -> HSL_Array_Float: HSL_Array_Float An HSL array of 3 floats from 0.0 to 1.0. """ - return np.array(colorsys.rgb_to_hls(*self.to_rgb())) + hls = colorsys.rgb_to_hls(*self.to_rgb()) + return np.array([hls[0], hls[2], hls[1]]) def invert(self, with_alpha: bool = False) -> Self: """Return a new, linearly inverted version of this :class:`ManimColor` (no @@ -906,7 +907,7 @@ def from_hsl( The :class:`ManimColor` with the corresponding RGB values to the given HSL array. """ - rgb = colorsys.hls_to_rgb(*hsl) + rgb = colorsys.hls_to_rgb(hsl[0], hsl[2], hsl[1]) return cls._from_internal(ManimColor(rgb, alpha)._internal_value) @overload diff --git a/tests/module/utils/test_manim_color.py b/tests/module/utils/test_manim_color.py index 9a35b006d8..4b169fd48e 100644 --- a/tests/module/utils/test_manim_color.py +++ b/tests/module/utils/test_manim_color.py @@ -116,9 +116,19 @@ def test_to_hsv() -> None: def test_to_hsl() -> None: color = ManimColor((0x1, 0x2, 0x3, 0x4)) - nt.assert_array_equal( - color.to_hsl(), colorsys.rgb_to_hls(0x1 / 255, 0x2 / 255, 0x3 / 255) - ) + hls = colorsys.rgb_to_hls(0x1 / 255, 0x2 / 255, 0x3 / 255) + + nt.assert_array_equal(color.to_hsl(), np.array([hls[0], hls[2], hls[1]])) + + +def test_from_hsl() -> None: + hls = colorsys.rgb_to_hls(0x1 / 255, 0x2 / 255, 0x3 / 255) + hsl = np.array([hls[0], hls[2], hls[1]]) + + color = ManimColor.from_hsl(hsl) + rgb = np.array([0x1 / 255, 0x2 / 255, 0x3 / 255]) + + nt.assert_allclose(color.to_rgb(), rgb) def test_invert() -> None: