Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Added custom `.interpolate` method for ValueTracker

Aathish Sivasubrahmanian2c05939e42e4
diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py
index 350d0c106..e657c9617 100644
--- a/manim/mobject/mobject.py
+++ b/manim/mobject/mobject.py
@@ -1088,17 +1088,6 @@ class Mobject(Container):
def interpolate_color(self, mobject1, mobject2, alpha):
raise NotImplementedError('Please override in a child class.')
- def become_partial(self, mobject, a, b):
- """
- Set points in such a way as to become only
- part of mobject.
- Inputs 0 <= a < b <= 1 determine what portion
- of mobject to become.
- """
- raise NotImplementedError('Please override in a child class.')
-
- # TODO, color?
-
def pointwise_become_partial(self, mobject, a, b):
raise NotImplementedError('Please override in a child class.')
@@ -1120,7 +1109,7 @@ class Mobject(Container):
"for a Mobject with no points"
caller_name = sys._getframe(1).f_code.co_name
raise Exception(message.format(caller_name))
-
+
# About z-index
def set_z_index(self, z_index_value):
"""Sets the mobject's :attr:`z_index` to the value specified in `z_index_value`.
@@ -1129,7 +1118,7 @@ class Mobject(Container):
----------
z_index_value : Union[:class:`int`, :class:`float`]
The new value of :attr:`z_index` set.
-
+
Returns
-------
:class:`Mobject`
@@ -1137,10 +1126,10 @@ class Mobject(Container):
"""
self.z_index = z_index_value
return self
-
+
def set_z_index_by_z_coordinate(self):
"""Sets the mobject's z coordinate to the value of :attr:`z_index`.
-
+
Returns
-------
:class:`Mobject`
diff --git a/manim/mobject/value_tracker.py b/manim/mobject/value_tracker.py
index 5872d7105..f832c172e 100644
--- a/manim/mobject/value_tracker.py
+++ b/manim/mobject/value_tracker.py
@@ -1,11 +1,12 @@
import numpy as np
+from ..utils.paths import straight_path
from ..mobject.mobject import Mobject
class ValueTracker(Mobject):
"""
- Note meant to be displayed. Instead the position encodes some
+ Not meant to be displayed. Instead the position encodes some
number, often one which another animation or continual_animation
uses for its update function, and by treating it as a mobject it can
still be animated and manipulated just like anything else.
@@ -26,6 +27,17 @@ class ValueTracker(Mobject):
def increment_value(self, d_value):
self.set_value(self.get_value() + d_value)
+ def interpolate(self, mobject1, mobject2,
+ alpha, path_func=straight_path):
+ """
+ Turns self into an interpolation between mobject1
+ and mobject2.
+ """
+ self.points = path_func(
+ mobject1.points, mobject2.points, alpha
+ )
+ return self
+
class ExponentialValueTracker(ValueTracker):
"""