A community-maintained Python framework for creating mathematical animations.
Fixed rotation of gradients while rotating a VMobject (#1513)
sparshg272b0d521db4
diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.pyindex 10816f8a6..dc70ec5b9 100644--- a/manim/mobject/types/vectorized_mobject.py+++ b/manim/mobject/types/vectorized_mobject.py@@ -405,7 +405,26 @@ class VMobject(Mobject):return self.get_stroke_color()return self.get_fill_color()- def set_sheen_direction(self, direction, family=True):+ def set_sheen_direction(self, direction: np.ndarray, family=True):+ """Sets the direction of the applied sheen.++ Parameters+ ----------+ direction : :class:`numpy.ndarray`, optional+ Direction from where the gradient is applied.++ Examples+ --------+ Normal usage::++ Circle().set_sheen_direction(UP)++ See Also+ --------+ :meth:`~.VMobject.set_sheen`+ :meth:`~.VMobject.rotate_sheen_direction`+ """+direction = np.array(direction)if family:for submob in self.get_family():@@ -414,7 +433,58 @@ class VMobject(Mobject):self.sheen_direction = directionreturn self- def set_sheen(self, factor, direction=None, family=True):+ def rotate_sheen_direction(self, angle: np.ndarray, axis: float = OUT, family=True):+ """Rotates the direction of the applied sheen.++ Parameters+ ----------+ angle : :class:`float`+ Angle by which the direction of sheen is rotated.+ axis : :class:`numpy.ndarray`+ Axis of rotation.++ Examples+ --------+ Normal usage::++ Circle().set_sheen_direction(UP).rotate_sheen_direction(PI)++ See Also+ --------+ :meth:`~.VMobject.set_sheen_direction`+ """+ if family:+ for submob in self.get_family():+ submob.sheen_direction = rotate_vector(+ submob.sheen_direction, angle, axis+ )+ else:+ self.sheen_direction = rotate_vector(self.sheen_direction, angle, axis)+ return self++ def set_sheen(self, factor, direction: np.ndarray = None, family=True):+ """Applies a color gradient from a direction.++ Parameters+ ----------+ factor : :class:`float`+ The extent of lustre/gradient to apply. If negative, the gradient+ starts from black, if positive the gradient starts from white and+ changes to the current color.+ direction : :class:`numpy.ndarray`, optional+ Direction from where the gradient is applied.++ Examples+ --------+ .. manim:: SetSheen+ :save_last_frame:++ class SetSheen(Scene):+ def construct(self):+ circle = Circle(fill_opacity=1).set_sheen(-0.3, DR)+ self.add(circle)+ """+if family:for submob in self.submobjects:submob.set_sheen(factor, direction, family)@@ -734,6 +804,17 @@ class VMobject(Mobject):self.make_smooth()return self+ def rotate(+ self,+ angle: float,+ axis: np.ndarray = OUT,+ about_point: Optional[Sequence[float]] = None,+ **kwargs,+ ):+ self.rotate_sheen_direction(angle, axis)+ super().rotate(angle, axis, about_point, **kwargs)+ return self+def scale_handle_to_anchor_distances(self, factor: float) -> "VMobject":"""If the distance between a given handle point H and its associatedanchor point A is d, then it changes H to be a distances factor*ddiff --git a/tests/control_data/graphical_units_data/modifier_methods/GradientRotationTest.npz b/tests/control_data/graphical_units_data/modifier_methods/GradientRotationTest.npznew file mode 100644index 000000000..52d888ee2Binary files /dev/null and b/tests/control_data/graphical_units_data/modifier_methods/GradientRotationTest.npz differdiff --git a/tests/test_graphical_units/test_modifier_methods.py b/tests/test_graphical_units/test_modifier_methods.pyindex 29c2ee8a7..7a475a4cf 100644--- a/tests/test_graphical_units/test_modifier_methods.py+++ b/tests/test_graphical_units/test_modifier_methods.py@@ -12,6 +12,12 @@ class GradientTest(Scene):self.add(c)+class GradientRotationTest(Scene):+ def construct(self):+ c = Circle(fill_opacity=1).set_color(color=[YELLOW, GREEN]).rotate(PI)+ self.add(c)++MODULE_NAME = "modifier_methods"