LoginSignup
1
0

More than 3 years have passed since last update.

manimの作法 その49

Posted at

概要

manimの作法、調べてみた。
ComplexPlane使ってみた。

サンプルコード

from manimlib.imports import *

class test(Scene):
    CONFIG = {
        "plane_config": {
            "x_radius": 9,
            "y_radius": 9,
            "stroke_width": 3,
        },
        "background_plane_config": {
            "color": LIGHT_GREY,
            "secondary_color": DARK_GREY,
            "stroke_width": 0.5,
            "stroke_opacity": 0.5,
            "secondary_line_ratio": 0,
        }
    }
    def construct(self):
        self.add_planes()
        z_tuples = [(complex(2, 1), "2 + i", UP), (complex(5, 2), "5 + 2i", LEFT), (complex(-np.sqrt(2) / 2, np.sqrt(2) / 2), "-\\frac{\\sqrt{2}}{2} + \\frac{\\sqrt{2}}{2} i", LEFT, ), (complex(-4, 1.5), "-4 + 1.5i", RIGHT), (complex(3, 0), "3 + 0i", UP), (complex(4, -3), "4 + -3i", UP), ]
        for z, z_tex, label_vect in z_tuples:
            self.show_multiplication(z, z_tex, label_vect)
    def add_planes(self, include_title = True):
        plane = ComplexPlane(**self.plane_config)
        self.plane = plane
        background_plane = ComplexPlane(**self.background_plane_config)
        background_plane.add_coordinates()
        self.background_plane = background_plane
        self.add(background_plane)
        self.add(plane)
        if include_title:
            title = TextMobject("Complex plane")
            title.scale(1.5)
            title.to_corner(UL, buff = MED_LARGE_BUFF)
            title.shift(SMALL_BUFF * UR)
            self.title = title
            self.add_foreground_mobjects(title)
    def show_multiplication(self, z, z_tex, label_vect):
        z_color = WHITE
        plane = self.plane
        new_plane = plane.deepcopy()
        real_tex, imag_tex = z_tex.split("+")
        label = TexMobject("\\text{Multiply by}\\\\", real_tex, "+", imag_tex, alignment = "", )
        label[1].set_color(GREEN)
        label[3].set_color(RED)
        label.scale(1.2)
        h_line = Line(plane.number_to_point(0), plane.number_to_point(z.real), color = GREEN, stroke_width = 5, )
        v_line = Line(plane.number_to_point(z.real), plane.number_to_point(z), color = RED, stroke_width = 5, )
        lines = VGroup(h_line, v_line)
        z_point = plane.number_to_point(z)
        z_dot = Dot(z_point)
        z_dot.set_color(z_color)
        label[1:].next_to(z_dot, label_vect)
        label[0].next_to(label[1:], UP)
        for mob in label:
            label.add_to_back(BackgroundRectangle(mob))
        one_dot = Dot(plane.number_to_point(1))
        one_dot.set_color(YELLOW)
        for dot in z_dot, one_dot:
            dot.save_state()
            dot.scale(5)
            dot.set_fill(opacity = 0)
            dot.set_stroke(width = 1, opacity = 0.5)
        to_fade_out = VGroup(plane, label, lines, z_dot, one_dot)
        self.play(ShowCreation(lines), FadeInFromDown(label), Restore(z_dot), )
        self.play(Restore(one_dot))
        angle = np.log(z).imag
        self.play(one_dot.move_to, z_dot, plane.apply_complex_function, lambda w: z * w, path_arc = angle, run_time = 3)
        self.wait()
        self.play(FadeOut(to_fade_out), FadeIn(new_plane), )
        self.plane = new_plane





生成した動画

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0