From 6b173a8b391b5532b59152346d250d8b334ba9fc Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 18 Apr 2022 00:56:31 +0200 Subject: Add manimgl variant --- manimgl/custom_config.yml | 33 ++++++++++++++++++++++ manimgl/harmonics.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 manimgl/custom_config.yml create mode 100644 manimgl/harmonics.py (limited to 'manimgl') diff --git a/manimgl/custom_config.yml b/manimgl/custom_config.yml new file mode 100644 index 0000000..0819a13 --- /dev/null +++ b/manimgl/custom_config.yml @@ -0,0 +1,33 @@ +break_into_partial_movies: false +camera_qualities: + default_quality: high + high: + frame_rate: 60 + resolution: 1920x1080 + low: + frame_rate: 15 + resolution: 854x480 + medium: + frame_rate: 30 + resolution: 1280x720 + ultra_high: + frame_rate: 60 + resolution: 3840x2160 +directories: + mirror_module_path: false + output: media + raster_images: media/rasters + sounds: media/sound + vector_images: media/vectors +full_screen: false +style: + background_color: '#333333' + font: Consolas +tex: + executable: latex + intermediate_filetype: dvi + template_file: tex_template.tex + text_to_replace: '[tex_expression]' +universal_import_line: from manimlib import * +window_monitor: 0 +window_position: UR diff --git a/manimgl/harmonics.py b/manimgl/harmonics.py new file mode 100644 index 0000000..0a15566 --- /dev/null +++ b/manimgl/harmonics.py @@ -0,0 +1,71 @@ +from manimlib import * + +import numpy as np +from scipy.special import sph_harm + +# configure style +config.background_color = '#202020' +# config.tex_template.add_to_preamble( +# r"\usepackage[p,osf]{scholax}" +# r"\usepackage{amsmath}" +# r"\usepackage[scaled=1.075,ncf,vvarbb]{newtxmath}" +# ) + +class FourierOnS1(ThreeDScene): + @staticmethod + def harmonic_cos(m, n, theta, phi): + # get only the cos() part + r = np.real(sph_harm(m, n, theta, phi)) * 5 # Y_n^m + + # coordinates transformation + x = r * np.cos(theta) * np.sin(phi) + y = r * np.sin(phi) * np.sin(theta) + z = r * np.cos(phi) + + return [x, y, z] + + @staticmethod + def harmonic_surf(m, n): + surf = Surface(uv_func=lambda u, v: FourierOnS1.harmonic_cos(m, n, u, v), + u_range=[0, 2 * PI], v_range=[-PI, PI], + color=GREY, resolution=(101, 101), shadow=0.1) + + surf.mesh = SurfaceMesh(surf) + surf.mesh.set_stroke(BLACK, 1, opacity=0.7) + + return surf + + def construct(self): + axes = ThreeDAxes(x_range=[-2, 2], y_range=[-2, 2], z_range=[-3, 3]) + self.add(axes) + + frame = self.camera.frame + frame.set_euler_angles(theta=-30*DEGREES, phi=70*DEGREES) + frame.add_updater(lambda m, dt: m.increment_theta(-0.1 * dt)) + + last_surf = None + last_label = None + for n in range(0, 5): + for m in range(0, n): + surf = FourierOnS1.harmonic_surf(m, n) + label = Tex(r"Y_{%d}^{%d}(\theta, \phi)" % (n, m)) + + if last_surf is None: + self.play(ShowCreation(surf)) + self.play(ShowCreation(surf.mesh, lag_ratio=0.01)) + else: + self.play(FadeOut(last_surf), FadeOut(last_surf.mesh)) + self.play(ShowCreation(surf)) + self.play(ShowCreation(surf.mesh, lag_ratio=0.01)) + + if last_label is not None: + self.remove(last_label) + + label.to_corner(UL) + + last_surf = surf + last_label = label + + self.wait(3) + + self.wait(5) -- cgit v1.2.1