diff --git a/animation/movement.py b/animation/movement.py index 8842240f..201ed779 100644 --- a/animation/movement.py +++ b/animation/movement.py @@ -34,6 +34,18 @@ class SmoothedVectorizedHomotopy(Homotopy): Homotopy.update_submobject(self, submob, start, alpha) submob.make_smooth() +class ComplexHomotopy(Homotopy): + def __init__(self, complex_homotopy, mobject, **kwargs): + """ + Complex Hootopy a function Cx[0, 1] to C + """ + def homotopy(event): + x, y, z, t = event + c = complex_homotopy((complex(x, y), t)) + return (c.real, c.imag, z) + Homotopy.__init__(self, homotopy, mobject, *args, **kwargs) + + class PhaseFlow(Animation): CONFIG = { "virtual_time" : 1, diff --git a/animation/transform.py b/animation/transform.py index 38778c28..c684e91e 100644 --- a/animation/transform.py +++ b/animation/transform.py @@ -12,8 +12,10 @@ from utils.config_ops import digest_config from utils.iterables import adjacent_pairs from utils.paths import path_along_arc from utils.paths import straight_path +from utils.config_ops import instantiate from utils.rate_functions import smooth from utils.rate_functions import squish_rate_func +from utils.space_ops import complex_to_R3 class Transform(Animation): CONFIG = { @@ -162,6 +164,21 @@ class ApplyMatrix(ApplyPointwiseFunction): return np.dot(p, transpose) ApplyPointwiseFunction.__init__(self, func, mobject, **kwargs) +class ComplexFunction(ApplyPointwiseFunction): + def __init__(self, function, mobject, **kwargs): + if "path_func" not in kwargs: + self.path_func = path_along_arc( + np.log(function(complex(1))).imag + ) + ApplyPointwiseFunction.__init__( + self, + lambda (x, y, z) : complex_to_R3(function(complex(x, y))), + instantiate(mobject), + **kwargs + ) + +### + class CyclicReplace(Transform): CONFIG = { "path_arc" : np.pi/2 diff --git a/big_ol_pile_of_manim_imports.py b/big_ol_pile_of_manim_imports.py index 06de7344..88420935 100644 --- a/big_ol_pile_of_manim_imports.py +++ b/big_ol_pile_of_manim_imports.py @@ -61,12 +61,12 @@ from scene.zoomed_scene import * from once_useful_constructs.arithmetic import * from once_useful_constructs.combinatorics import * +from once_useful_constructs.complex_transformation_scene import * from once_useful_constructs.counting import * from once_useful_constructs.fractals import * from once_useful_constructs.graph_theory import * from once_useful_constructs.light import * -from topics.complex_numbers import * from topics.functions import * from topics.graph_scene import * from topics.matrix import * diff --git a/topics/complex_numbers.py b/once_useful_constructs/complex_transformation_scene.py similarity index 79% rename from topics/complex_numbers.py rename to once_useful_constructs/complex_transformation_scene.py index 3d7370d2..efbbe21b 100644 --- a/topics/complex_numbers.py +++ b/once_useful_constructs/complex_transformation_scene.py @@ -1,23 +1,12 @@ from constants import * - from animation.animation import Animation -from animation.creation import ShowCreation -from animation.movement import Homotopy from animation.movement import SmoothedVectorizedHomotopy from animation.transform import ApplyPointwiseFunction from animation.transform import MoveToTarget -from mobject.coordinate_systems import NumberPlane from mobject.coordinate_systems import ComplexPlane -from mobject.svg.tex_mobject import TexMobject -from mobject.svg.tex_mobject import TextMobject from mobject.types.vectorized_mobject import VGroup from scene.scene import Scene -from utils.config_ops import digest_config -from utils.config_ops import instantiate -from utils.paths import path_along_arc -from utils.space_ops import R3_to_complex -from utils.space_ops import complex_to_R3 class ComplexTransformationScene(Scene): CONFIG = { @@ -167,35 +156,6 @@ class ComplexTransformationScene(Scene): *added_anims ) -##### Unsure about what comes under here... - -def complex_string(complex_num): - return filter(lambda c : c not in "()", str(complex_num)) - -class ComplexFunction(ApplyPointwiseFunction): - def __init__(self, function, mobject = ComplexPlane, **kwargs): - if "path_func" not in kwargs: - self.path_func = path_along_arc( - np.log(function(complex(1))).imag - ) - ApplyPointwiseFunction.__init__( - self, - lambda (x, y, z) : complex_to_R3(function(complex(x, y))), - instantiate(mobject), - **kwargs - ) - -class ComplexHomotopy(Homotopy): - def __init__(self, complex_homotopy, mobject = ComplexPlane, **kwargs): - """ - Complex Hootopy a function Cx[0, 1] to C - """ - def homotopy(event): - x, y, z, t = event - c = complex_homotopy((complex(x, y), t)) - return (c.real, c.imag, z) - Homotopy.__init__(self, homotopy, mobject, *args, **kwargs) - diff --git a/utils/strings.py b/utils/strings.py index bfed3b66..54eaae3e 100644 --- a/utils/strings.py +++ b/utils/strings.py @@ -16,4 +16,7 @@ def initials(name, sep_values = [" ", "_"]): ]) def camel_case_initials(name): - return filter(lambda c : c.isupper(), name) \ No newline at end of file + return filter(lambda c : c.isupper(), name) + +def complex_string(complex_num): + return filter(lambda c : c not in "()", str(complex_num))