diff --git a/manim/utils/color/core.py b/manim/utils/color/core.py index 23864921e0..5b7b97c4dc 100644 --- a/manim/utils/color/core.py +++ b/manim/utils/color/core.py @@ -1021,6 +1021,9 @@ def __xor__(self, other: Self) -> Self: self._internal_from_integer(self.to_integer() ^ int(other), 1.0) ) + def __hash__(self) -> int: + return hash(self.to_hex(with_alpha=True)) + RGBA = ManimColor """RGBA Color Space""" diff --git a/tests/module/utils/test_color.py b/tests/module/utils/test_color.py index c3d468328b..602f56460e 100644 --- a/tests/module/utils/test_color.py +++ b/tests/module/utils/test_color.py @@ -2,7 +2,7 @@ import numpy as np -from manim import BLACK, Mobject, Scene, VMobject +from manim import BLACK, RED, WHITE, ManimColor, Mobject, Scene, VMobject def test_import_color(): @@ -49,3 +49,9 @@ def test_set_color(): assert m.color.to_hex() == "#FFFFFF" m.set_color(BLACK) assert m.color.to_hex() == "#000000" + + +def test_color_hash(): + assert hash(WHITE) == hash(ManimColor([1.0, 1.0, 1.0, 1.0])) + assert hash(WHITE) == hash("#FFFFFFFF") + assert hash(WHITE) != hash(RED)