Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Get rid of lag_factor

Grant Sanderson707a2f6f6343
diff --git a/active_projects/eop/chapter1/area_model_bayes.py b/active_projects/eop/chapter1/area_model_bayes.py
index e86adf211..b740d9c6c 100644
--- a/active_projects/eop/chapter1/area_model_bayes.py
+++ b/active_projects/eop/chapter1/area_model_bayes.py
@@ -43,7 +43,7 @@ class IllustrateAreaModelBayes(Scene):
label_not_A = TexMobject("P(\\text{not }A)").next_to(brace_not_A, DOWN).scale(0.7)
# self.play(
- # OldLaggedStart(FadeIn, VGroup(rect_A, rect_not_A), lag_factor = 0.5)
+ # OldLaggedStart(FadeIn, VGroup(rect_A, rect_not_A))
# )
# self.play(
# ShowCreation(brace_A),
@@ -75,7 +75,7 @@ class IllustrateAreaModelBayes(Scene):
label_not_B = TexMobject("P(\\text{not }B)").next_to(brace_not_B, LEFT).scale(0.7)
# self.play(
- # OldLaggedStart(FadeIn, VGroup(rect_B, rect_not_B), lag_factor = 0.5)
+ # OldLaggedStart(FadeIn, VGroup(rect_B, rect_not_B))
# )
# self.play(
# ShowCreation(brace_B),
diff --git a/active_projects/eop/chapter1/intro.py b/active_projects/eop/chapter1/intro.py
index 361f2df9e..ad7c858ee 100644
--- a/active_projects/eop/chapter1/intro.py
+++ b/active_projects/eop/chapter1/intro.py
@@ -6,7 +6,6 @@ class Chapter1OpeningQuote(OpeningQuote):
"fade_in_kwargs": {
"lag_ratio": 0.5,
"rate_func": linear,
- "lag_factor": 9,
"run_time": 10,
},
"text_size" : "\\normalsize",
diff --git a/active_projects/eop/independence.py b/active_projects/eop/independence.py
index b378868e3..6c7294dff 100644
--- a/active_projects/eop/independence.py
+++ b/active_projects/eop/independence.py
@@ -1023,7 +1023,6 @@ class ThousandPossibleQuizzes(Scene):
MoveToTarget(
movers,
lag_ratio = 0.5,
- lag_factor = 4,
run_time = 3,
),
Transform(left_label_equation, new_equation)
diff --git a/manimlib/animation/animation.py b/manimlib/animation/animation.py
index 238b2ccbc..13a798eb4 100644
--- a/manimlib/animation/animation.py
+++ b/manimlib/animation/animation.py
@@ -15,16 +15,12 @@ class Animation(object):
"name": None,
# Does this animation add or remove a mobject form the screen
"remover": False,
- # TODO, replace this with a single lag parameter
-
# If 0, the animation is applied to all submobjects
# at the same time
# If 1, it is applied to each successively.
# If 0 < lag_ratio < 1, its applied to each
# with lagged start times
"lag_ratio": 0,
- # TODO, remove anything with lag_factor
- "lag_factor": 2,
}
def __init__(self, mobject, **kwargs):
diff --git a/manimlib/animation/creation.py b/manimlib/animation/creation.py
index 935259ff6..95ba6fd8d 100644
--- a/manimlib/animation/creation.py
+++ b/manimlib/animation/creation.py
@@ -116,12 +116,7 @@ class Write(DrawBorderThenFill):
if "run_time" not in kwargs:
self.establish_run_time(mobject)
- if "lag_factor" not in kwargs:
- if len(mobject.family_members_with_points()) < 4:
- min_lag_factor = 1
- else:
- min_lag_factor = 2
- self.lag_factor = max(self.run_time - 1, min_lag_factor)
+ # Something to be smart about lag_ratio?
DrawBorderThenFill.__init__(self, mobject, **kwargs)
def establish_run_time(self, mobject):
diff --git a/manimlib/animation/indication.py b/manimlib/animation/indication.py
index 04e46b7bb..6469cb92e 100644
--- a/manimlib/animation/indication.py
+++ b/manimlib/animation/indication.py
@@ -211,7 +211,6 @@ class ApplyWave(Homotopy):
def homotopy(x, y, z, t):
alpha = (x - left_x) / (right_x - left_x)
- # lf = self.lag_factor
power = np.exp(2.0 * (alpha - 0.5))
nudge = there_and_back(t**power)
return np.array([x, y, z]) + nudge * vect
diff --git a/manimlib/animation/transform.py b/manimlib/animation/transform.py
index 0b054292d..321d5878a 100644
--- a/manimlib/animation/transform.py
+++ b/manimlib/animation/transform.py
@@ -119,15 +119,18 @@ class CounterclockwiseTransform(Transform):
class MoveToTarget(Transform):
def __init__(self, mobject, **kwargs):
+ self.check_validity_of_input(mobject)
+ Transform.__init__(self, mobject, mobject.target, **kwargs)
+
+ def check_validity_of_input(self, mobject):
if not hasattr(mobject, "target"):
raise Exception(
- "MoveToTarget called on mobject without attribute 'target' ")
- Transform.__init__(self, mobject, mobject.target, **kwargs)
+ "MoveToTarget called on mobject"
+ "without attribute 'target'"
+ )
class ApplyMethod(Transform):
- CONFIG = {}
-
def __init__(self, method, *args, **kwargs):
"""
method is a method of Mobject, *args are arguments for
@@ -183,10 +186,17 @@ class ApplyPointwiseFunction(ApplyMethod):
class ApplyPointwiseFunctionToCenter(ApplyPointwiseFunction):
def __init__(self, function, mobject, **kwargs):
+ self.function = function
ApplyMethod.__init__(
- self, mobject.move_to, function(mobject.get_center()), **kwargs
+ self, mobject.move_to, **kwargs
)
+ def begin(self):
+ self.method_args = [
+ self.function(self.mobject.get_center())
+ ]
+ super().begin()
+
class FadeToColor(ApplyMethod):
def __init__(self, mobject, color, **kwargs):
@@ -195,8 +205,9 @@ class FadeToColor(ApplyMethod):
class ScaleInPlace(ApplyMethod):
def __init__(self, mobject, scale_factor, **kwargs):
- ApplyMethod.__init__(self, mobject.scale_in_place,
- scale_factor, **kwargs)
+ ApplyMethod.__init__(
+ self, mobject.scale, scale_factor, **kwargs
+ )
class Restore(ApplyMethod):
@@ -205,18 +216,18 @@ class Restore(ApplyMethod):
class ApplyFunction(Transform):
- CONFIG = {
- "lag_ratio": 0,
- }
-
def __init__(self, function, mobject, **kwargs):
+ self.function = function
+ temp_target = mobject
Transform.__init__(
- self,
- mobject,
- function(mobject.copy()),
- **kwargs
+ self, mobject, temp_target, **kwargs
)
- self.name = "ApplyFunctionTo" + str(mobject)
+
+ def begin(self):
+ self.target_mobject = self.function(
+ self.mobject.copy()
+ )
+ super().begin()
class ApplyMatrix(ApplyPointwiseFunction):
diff --git a/manimlib/for_3b1b_videos/common_scenes.py b/manimlib/for_3b1b_videos/common_scenes.py
index fef8904b1..9835d6044 100644
--- a/manimlib/for_3b1b_videos/common_scenes.py
+++ b/manimlib/for_3b1b_videos/common_scenes.py
@@ -35,7 +35,6 @@ class OpeningQuote(Scene):
"fade_in_kwargs": {
"lag_ratio": 0.5,
"rate_func": linear,
- "lag_factor": 4,
"run_time": 5,
},
"text_size": "\\Large",
@@ -272,7 +271,7 @@ class LogoGenerationTemplate(MovingCameraScene):
name = self.channel_name
self.play(
- Write(name, run_time=3, lag_factor=2.5),
+ Write(name, run_time=3),
*self.get_logo_animations(logo)
)
self.wait()
diff --git a/old_projects/crypto.py b/old_projects/crypto.py
index d26c2e4c3..ab9fb0a70 100644
--- a/old_projects/crypto.py
+++ b/old_projects/crypto.py
@@ -2980,7 +2980,6 @@ class IntroduceBlockChain(Scene):
OldLaggedStart(
ShowCreation, arrows,
run_time = 1,
- lag_factor = 0.6,
)
)
self.wait()
diff --git a/old_projects/dandelin.py b/old_projects/dandelin.py
index bfa8ebf1d..3786e7569 100644
--- a/old_projects/dandelin.py
+++ b/old_projects/dandelin.py
@@ -978,7 +978,7 @@ class UseDefiningFeatures(Scene):
tip.set_color(YELLOW)
self.add(title)
- self.play(Write(tip, lag_factor=5, run_time=4))
+ self.play(Write(tip, run_time=4))
self.wait()
@@ -1272,7 +1272,7 @@ class NameDandelin(Scene):
self.add(title[0])
self.play(FadeInFromDown(portrait))
- self.play(Write(title[1], lag_factor=4))
+ self.play(Write(title[1]))
self.wait()
self.play(FadeInFrom(google_result, LEFT))
self.play(Write(cmon_google, run_time=1))
diff --git a/old_projects/eoc/chapter4.py b/old_projects/eoc/chapter4.py
index 3a3285814..5a17a44fc 100644
--- a/old_projects/eoc/chapter4.py
+++ b/old_projects/eoc/chapter4.py
@@ -1728,7 +1728,6 @@ class ThreeLinesChainRule(ReconfigurableScene):
self.play(
all_x_squared_relevant_labels.restore,
lag_ratio = 0.5,
- lag_factor = 3,
run_time = 3,
)
self.__dict__.update(self.__class__.CONFIG)
diff --git a/old_projects/eoc/chapter7.py b/old_projects/eoc/chapter7.py
index 082349f15..4c6962542 100644
--- a/old_projects/eoc/chapter7.py
+++ b/old_projects/eoc/chapter7.py
@@ -104,7 +104,6 @@ class LimitJustMeansApproach(PiCreatureScene):
Transform(
expression, next_expression,
lag_ratio = 0.5,
- lag_factor = 1.2,
),
self.pi_creature.look_at, next_expression[-1]
)
@@ -664,7 +663,6 @@ class OtherViewsOfDx(TeacherStudentsScene):
statements[0].h.copy(), h_group,
run_time = 2,
lag_ratio = 0.5,
- lag_factor = 1.5,
))
self.wait()
@@ -824,7 +822,6 @@ class GraphLimitExpression(GraphScene):
anims = [FadeIn(
VGroup(*expression[i:j]),
lag_ratio = 0.5,
- lag_factor = 1.5
)]
new_graph = self.get_graph(func, color = BLUE)
if graph is None:
diff --git a/old_projects/eoc/chapter8.py b/old_projects/eoc/chapter8.py
index afc72c846..5160fcfd7 100644
--- a/old_projects/eoc/chapter8.py
+++ b/old_projects/eoc/chapter8.py
@@ -2413,7 +2413,7 @@ class FundamentalTheorem(GraphScene):
""")
words.to_edge(RIGHT)
- self.play(Write(words, lag_factor = 3))
+ self.play(Write(words))
self.wait()
def show_integral_considering_continuum(self):
diff --git a/old_projects/eola/chapter7.py b/old_projects/eola/chapter7.py
index d8d73e44d..e5b3a2fa0 100644
--- a/old_projects/eola/chapter7.py
+++ b/old_projects/eola/chapter7.py
@@ -47,7 +47,6 @@ class OpeningQuote(Scene):
self.play(Write(
quote,
run_time = rt,
- lag_factor = 5 if rt > 3 else 2,
))
self.wait(2)
@@ -2121,7 +2120,7 @@ class RememberGraphDuality(Scene):
early video I did on graph duality
""")
words.to_edge(UP)
- self.play(Write(words, lag_factor = 4))
+ self.play(Write(words))
self.wait()
class LooseDualityDescription(Scene):
diff --git a/old_projects/hanoi.py b/old_projects/hanoi.py
index 6c118b528..714a9befa 100644
--- a/old_projects/hanoi.py
+++ b/old_projects/hanoi.py
@@ -899,7 +899,7 @@ class IntroduceBase10(Scene):
""")
digits.next_to(self.title, DOWN, buff = LARGE_BUFF)
digits.shift(2*RIGHT)
- self.play(Write(digits, lag_factor = 5))
+ self.play(Write(digits))
self.wait()
class RhythmOfDecimalCounting(CountingScene):
@@ -1181,7 +1181,6 @@ class BinaryCountingAtEveryScale(Scene):
VGroup(*reversed(list(curr_bits))),
VGroup(*reversed(list(bit_mobs[2**(self.num_bits-1)]))),
lag_ratio = 0.5,
- lag_factor = self.num_bits
))
self.wait()
self.play(
@@ -2970,7 +2969,6 @@ class IntroduceGraphStructure(SierpinskiGraphScene):
self.nodes,
run_time = 3,
lag_ratio = 0.5,
- lag_factor = 7,
))
vect = LEFT
for index in 3, 21, 8, 17, 10, 13:
diff --git a/old_projects/leibniz.py b/old_projects/leibniz.py
index b52fd6560..678e49a3e 100644
--- a/old_projects/leibniz.py
+++ b/old_projects/leibniz.py
@@ -819,7 +819,6 @@ class CountLatticePoints(LatticePointScene):
point_copies, squares,
run_time = 3,
lag_ratio = 0.5,
- lag_factor = 4,
),
Animation(self.lattice_points)
)
diff --git a/old_projects/nn/part1.py b/old_projects/nn/part1.py
index 86e14449a..54477e305 100644
--- a/old_projects/nn/part1.py
+++ b/old_projects/nn/part1.py
@@ -670,7 +670,6 @@ class LayOutPlan(TeacherStudentsScene, NetworkScene):
network_mob.edge_groups,
lag_ratio = 0.5,
run_time = 2,
- lag_factor = 8,
rate_func=linear,
))
in_vect = np.random.random(self.network.sizes[0])
diff --git a/old_projects/nn/part2.py b/old_projects/nn/part2.py
index abe45717f..9e1eeaee9 100644
--- a/old_projects/nn/part2.py
+++ b/old_projects/nn/part2.py
@@ -2673,7 +2673,6 @@ class GradientNudging(PreviewLearning):
return MoveToTarget(
edges,
lag_ratio = 0.5,
- lag_factor = 8,
run_time = 1.5
)
diff --git a/old_projects/patreon.py b/old_projects/patreon.py
index 557404ece..574343894 100644
--- a/old_projects/patreon.py
+++ b/old_projects/patreon.py
@@ -163,7 +163,6 @@ class GrowingToDoList(Scene):
morty.look_at, lines,
Write(
VGroup(*lines[3:]),
- lag_factor = 7
)
)
@@ -551,7 +550,6 @@ class MakeALotOfPiCreaturesHappy(Scene):
pis,
run_time = 2,
lag_ratio = 0.5,
- lag_factor = 5,
)
)
for x in range(10):
diff --git a/old_projects/turbulence.py b/old_projects/turbulence.py
index 230cd3ac1..287fa4d4e 100644
--- a/old_projects/turbulence.py
+++ b/old_projects/turbulence.py
@@ -971,7 +971,7 @@ class FeynmanOnTurbulence(Scene):
self.play(
FadeInFrom(feynman, UP),
FadeInFrom(name, DOWN),
- Write(quote, run_time=4, lag_factor=5)
+ Write(quote, run_time=4)
)
self.wait()
diff --git a/old_projects/wallis.py b/old_projects/wallis.py
index b66020f05..3f8aebc00 100644
--- a/old_projects/wallis.py
+++ b/old_projects/wallis.py
@@ -4066,7 +4066,7 @@ class MentionJohnWallis(Scene):
self.play(GrowFromEdge(image, UP))
self.play(Write(image_name))
self.wait(2)
- self.play(Write(infinity, run_time=3, lag_factor=1))
+ self.play(Write(infinity, run_time=3))
self.wait(2)
diff --git a/old_projects/wcat.py b/old_projects/wcat.py
index 050c85347..5884576d6 100644
--- a/old_projects/wcat.py
+++ b/old_projects/wcat.py
@@ -2060,7 +2060,7 @@ class CreditThree(Scene):
)
self.wait()
self.play(
- Write(domains, run_time = 5, lag_factor = 5),
+ Write(domains, run_time = 5),
randy.look_at, domains
)
self.wait()