From 468d05d049242d51c9cf0f21f8c01c00ca5b1e16 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Wed, 28 Oct 2015 16:03:33 -0700 Subject: [PATCH] Redid digest_config and introduced digest_locals --- animation/__init__.py | 2 +- animation/animation.py | 5 +- animation/meta_animations.py | 7 +- animation/simple_animations.py | 11 +-- animation/transform.py | 14 +-- extract_scene.py | 87 ++++++++++++------- helpers.py | 49 +++++++---- image_mobject.py | 40 +-------- mobject.py | 23 +++-- .../matrix_as_transform_2d.py | 8 -- old_projects/music_and_measure.py | 6 +- {topics => old_projects}/pythagorean_proof.py | 2 - scene/__init__.py | 4 +- scene/scene.py | 3 +- tex_utils.py | 40 ++++++++- topics/__init__.py | 2 - topics/arithmetic.py | 3 +- topics/characters.py | 5 -- topics/complex_numbers.py | 4 +- topics/functions.py | 11 ++- topics/geometry.py | 42 +++------ topics/number_line.py | 10 +-- 22 files changed, 185 insertions(+), 193 deletions(-) rename {topics => old_projects}/matrix_as_transform_2d.py (99%) rename {topics => old_projects}/pythagorean_proof.py (99%) diff --git a/animation/__init__.py b/animation/__init__.py index 2ae2b51b..fc153ea0 100644 --- a/animation/__init__.py +++ b/animation/__init__.py @@ -1,4 +1,4 @@ from animation import * from meta_animations import * from simple_animations import * -from transform import * \ No newline at end of file +from transform import * diff --git a/animation/animation.py b/animation/animation.py index 7bb31ac9..d82c6641 100644 --- a/animation/animation.py +++ b/animation/animation.py @@ -9,8 +9,7 @@ import progressbar import inspect from helpers import * -from mobject import Mobject -from topics.geometry import Point +from mobject import Mobject, Point class Animation(object): DEFAULT_CONFIG = { @@ -21,7 +20,7 @@ class Animation(object): def __init__(self, mobject, **kwargs): mobject = instantiate(mobject) assert(isinstance(mobject, Mobject)) - digest_config(self, Animation, kwargs, locals()) + digest_config(self, kwargs, locals()) self.starting_mobject = copy.deepcopy(self.mobject) if self.alpha_func is None: self.alpha_func = (lambda x : x) diff --git a/animation/meta_animations.py b/animation/meta_animations.py index f452f755..489fa1a4 100644 --- a/animation/meta_animations.py +++ b/animation/meta_animations.py @@ -18,12 +18,12 @@ class DelayByOrder(Animation): "max_power" : 5 } def __init__(self, animation, **kwargs): - digest_config(self, DelayByOrder, kwargs, locals()) + digest_locals(self) + self.num_mobject_points = animation.mobject.get_num_points() kwargs.update(dict([ (attr, getattr(animation, attr)) for attr in Animation.DEFAULT_CONFIG ])) - self.num_mobject_points = animation.mobject.get_num_points() Animation.__init__(self, animation.mobject, **kwargs) self.name = self.__class__.__name__ + str(self.animation) @@ -44,14 +44,13 @@ class TransformAnimations(Transform): "alpha_func" : squish_alpha_func(smooth) } def __init__(self, start_anim, end_anim, **kwargs): - digest_config(self, TransformAnimations, kwargs, locals()) if "run_time" in kwargs: self.run_time = kwargs.pop("run_time") else: self.run_time = max(start_anim.run_time, end_anim.run_time) for anim in start_anim, end_anim: anim.set_run_time(self.run_time) - + if start_anim.starting_mobject.get_num_points() != end_anim.starting_mobject.get_num_points(): Mobject.align_data(start_anim.starting_mobject, end_anim.starting_mobject) for anim in start_anim, end_anim: diff --git a/animation/simple_animations.py b/animation/simple_animations.py index 0c7c6069..e4c28a55 100644 --- a/animation/simple_animations.py +++ b/animation/simple_animations.py @@ -16,10 +16,6 @@ class Rotating(Animation): "run_time" : 20.0, "alpha_func" : None, } - def __init__(self, mobject, **kwargs): - digest_config(self, Rotating, kwargs, locals()) - Animation.__init__(self, mobject, **kwargs) - def update_mobject(self, alpha): self.mobject.points = self.starting_mobject.points for axis in self.axes: @@ -61,7 +57,6 @@ class Flash(Animation): "alpha_func" : None, } def __init__(self, mobject, **kwargs): - digest_config(self, Flash, kwargs, locals()) self.intermediate = Mobject(color = self.color) self.intermediate.add_points([ point + (x, y, 0) @@ -82,12 +77,12 @@ class Flash(Animation): ) class Homotopy(Animation): - def __init__(self, homotopy, **kwargs): + def __init__(self, homotopy, mobject, **kwargs): """ Homotopy a function from (x, y, z, t) to (x', y', z') """ - digest_config(self, Homotopy, kwargs, locals()) - Animation.__init__(self, **kwargs) + digest_locals(self) + Animation.__init__(self, mobject, **kwargs) def update_mobject(self, alpha): self.mobject.points = np.array([ diff --git a/animation/transform.py b/animation/transform.py index 692ad3dc..1ab3a7ca 100644 --- a/animation/transform.py +++ b/animation/transform.py @@ -7,9 +7,7 @@ import warnings from helpers import * from animation import Animation -from mobject import Mobject -from topics.geometry import Point -from topics.complex_numbers import ComplexPlane +from mobject import Mobject, Point class Transform(Animation): DEFAULT_CONFIG = { @@ -18,7 +16,7 @@ class Transform(Animation): } def __init__(self, mobject, ending_mobject, **kwargs): mobject, ending_mobject = map(instantiate, [mobject, ending_mobject]) - digest_config(self, Transform, kwargs, locals()) + digest_config(self, kwargs, locals()) count1, count2 = mobject.get_num_points(), ending_mobject.get_num_points() if count2 == 0: ending_mobject.add_points([SPACE_WIDTH*RIGHT+SPACE_HEIGHT*UP]) @@ -73,24 +71,17 @@ class ClockwiseTransform(Transform): DEFAULT_CONFIG = { "interpolation_function" : clockwise_path() } - def __init__(self, *args, **kwargs): - digest_config(self, ClockwiseTransform, kwargs) - Transform.__init__(self, *args, **kwargs) class CounterclockwiseTransform(Transform): DEFAULT_CONFIG = { "interpolation_function" : counterclockwise_path() } - def __init__(self, *args, **kwargs): - digest_config(self, ClockwiseTransform, kwargs) - Transform.__init__(self, *args, **kwargs) class SpinInFromNothing(Transform): DEFAULT_CONFIG = { "interpolation_function" : counterclockwise_path() } def __init__(self, mob, **kwargs): - digest_config(self, SpinInFromNothing, kwargs) Transform.__init__(self, Point(mob.get_center()), mob, **kwargs) class ApplyMethod(Transform): @@ -121,7 +112,6 @@ class ApplyPointwiseFunction(ApplyMethod): "run_time" : DEFAULT_POINTWISE_FUNCTION_RUN_TIME } def __init__(self, function, mobject, **kwargs): - digest_config(self, ApplyPointwiseFunction, kwargs) ApplyMethod.__init__( self, mobject.apply_function, function, **kwargs ) diff --git a/extract_scene.py b/extract_scene.py index c909271b..8081e307 100644 --- a/extract_scene.py +++ b/extract_scene.py @@ -12,23 +12,31 @@ from helpers import * from scene import Scene HELP_MESSAGE = """ -