Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Bugfix: Allow using #hex colors with 3 characters (#998)

Álvaro Mondéjar14df62c3e1e2
diff --git a/manim/utils/color.py b/manim/utils/color.py
index e6506cc80..6a999dcde 100644
--- a/manim/utils/color.py
+++ b/manim/utils/color.py
@@ -289,7 +289,7 @@ def rgb_to_hex(rgb):
def hex_to_rgb(hex_code):
hex_part = hex_code[1:]
if len(hex_part) == 3:
- "".join([2 * c for c in hex_part])
+ hex_part = "".join([2 * c for c in hex_part])
return np.array([int(hex_part[i : i + 2], 16) / 255 for i in range(0, 6, 2)])
diff --git a/tests/test_color.py b/tests/test_color.py
index d64ab4c73..8e793f0aa 100644
--- a/tests/test_color.py
+++ b/tests/test_color.py
@@ -20,6 +20,10 @@ def test_background_color():
S.renderer.update_frame(S)
assert np.all(S.renderer.get_frame()[0, 0] == np.array([67, 111, 128, 255]))
+ S.camera.background_color = "#fff"
+ S.renderer.update_frame(S)
+ assert np.all(S.renderer.get_frame()[0, 0] == np.array([255, 255, 255, 255]))
+
S.camera.background_color = "#bbffbb"
S.camera.background_opacity = 0.5
S.renderer.update_frame(S)