Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fix 258: set_color(COLOR) doesn't change the self.color attribute (#751)

Leo Torres84fb96bce9b4
diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py
index 904fb50a2..d0249fd98 100644
--- a/manim/mobject/mobject.py
+++ b/manim/mobject/mobject.py
@@ -704,7 +704,7 @@ class Mobject(Container):
if family:
for submob in self.submobjects:
submob.set_color(color, family=family)
- self.color = color
+ self.color = Color(color)
return self
def set_color_by_gradient(self, *colors):
diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py
index fb51c541b..7c2b00af3 100644
--- a/manim/mobject/types/vectorized_mobject.py
+++ b/manim/mobject/types/vectorized_mobject.py
@@ -252,6 +252,7 @@ class VMobject(Mobject):
def set_color(self, color, family=True):
self.set_fill(color, family=family)
self.set_stroke(color, family=family)
+ self.color = colour.Color(color)
return self
def set_opacity(self, opacity, family=True):
diff --git a/tests/test_color.py b/tests/test_color.py
index 354d512e8..d64ab4c73 100644
--- a/tests/test_color.py
+++ b/tests/test_color.py
@@ -1,7 +1,7 @@
import pytest
import numpy as np
-from manim import Camera, Scene, tempconfig, config
+from manim import Mobject, VMobject, Camera, Scene, tempconfig, config, WHITE, BLACK
def test_import_color():
@@ -24,3 +24,15 @@ def test_background_color():
S.camera.background_opacity = 0.5
S.renderer.update_frame(S)
assert np.all(S.renderer.get_frame()[0, 0] == np.array([187, 255, 187, 127]))
+
+
+def test_set_color():
+ m = Mobject()
+ assert m.color.hex == "#fff"
+ m.set_color(BLACK)
+ assert m.color.hex == "#000"
+
+ m = VMobject()
+ assert m.color.hex == "#fff"
+ m.set_color(BLACK)
+ assert m.color.hex == "#000"
diff --git a/tests/test_scene_rendering/test_caching_related.py b/tests/test_scene_rendering/test_caching_related.py
index 03395571a..2d7ddc708 100644
--- a/tests/test_scene_rendering/test_caching_related.py
+++ b/tests/test_scene_rendering/test_caching_related.py
@@ -6,6 +6,7 @@ from ..utils.commands import capture
from ..utils.video_tester import *
@video_comparison(
"SceneWithMultipleWaitCallsWithNFlag.json",
"videos/simple_scenes/480p15/SceneWithMultipleWaitCalls.mp4",
@@ -29,6 +30,7 @@ def test_wait_skip(tmp_path, manim_cfg_file, simple_scenes_path):
assert exit_code == 0, err
@video_comparison(
"SceneWithMultiplePlayCallsWithNFlag.json",
"videos/simple_scenes/480p15/SceneWithMultipleCalls.mp4",