From c99a1dfd6aa9ffe39081ee53cd733ad37459e98e Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Mon, 5 Oct 2015 17:45:13 -0700 Subject: [PATCH] scene.apply method, which required switching order or ApplyFunction arguments --- animation/transform.py | 15 ++++----------- scene/scene.py | 6 ++++++ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/animation/transform.py b/animation/transform.py index 8c73bf59..79f7a753 100644 --- a/animation/transform.py +++ b/animation/transform.py @@ -139,7 +139,7 @@ class ScaleInPlace(ApplyMethod): ApplyMethod.__init__(self, mobject.scale_in_place, scale_factor, **kwargs) class ApplyFunction(Transform): - def __init__(self, function, mobject, **kwargs): + def __init__(self, mobject, function, **kwargs): Transform.__init__( self, mobject, @@ -152,7 +152,7 @@ class ApplyPointwiseFunction(Transform): DEFAULT_CONFIG = { "run_time" : DEFAULT_ANIMATION_RUN_TIME } - def __init__(self, function, mobject, **kwargs): + def __init__(self, mobject, function, **kwargs): digest_config(self, ApplyPointwiseFunction, kwargs) map_image = copy.deepcopy(mobject) map_image.points = np.array(map(function, map_image.points)) @@ -164,20 +164,13 @@ class ApplyPointwiseFunction(Transform): ]) class ComplexFunction(ApplyPointwiseFunction): - def __init__(self, function, *args, **kwargs): + def __init__(self, mobject, function, **kwargs): def point_map(point): x, y, z = point c = np.complex(x, y) c = function(c) return c.real, c.imag, z - if len(args) > 0: - args = list(args) - mobject = args.pop(0) - elif "mobject" in kwargs: - mobject = kwargs.pop("mobject") - else: - mobject = Grid() - ApplyPointwiseFunction.__init__(self, point_map, mobject, *args, **kwargs) + ApplyPointwiseFunction.__init__(self, mobject, point_map, *args, **kwargs) self.name = "ComplexFunction" + to_cammel_case(function.__name__) #Todo, abstract away function naming' diff --git a/scene/scene.py b/scene/scene.py index 20db87f6..8efb01a7 100644 --- a/scene/scene.py +++ b/scene/scene.py @@ -154,6 +154,12 @@ class Scene(object): animation.clean_up() return self + def apply(self, AnimationClass, *args, **kwargs): + self.play(*[ + AnimationClass(mobject, *args, **kwargs) + for mobject in self.mobjects + ]) + def get_frame(self): return disp.paint_mobject( CompoundMobject(*self.mobjects), self.background