• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python vectorized_mobject.VMobject类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mobject.vectorized_mobject.VMobject的典型用法代码示例。如果您正苦于以下问题:Python VMobject类的具体用法?Python VMobject怎么用?Python VMobject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了VMobject类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: show_overall_effect

    def show_overall_effect(self, matrix):
        everything = self.get_mobjects()
        everything = list_difference_update(
            everything, matrix.submobject_family()
        )
        self.play(*map(FadeOut, everything) + [Animation(matrix)])
        new_matrix = matrix.copy()
        new_matrix.center().to_edge(UP)
        self.play(Transform(matrix, new_matrix))
        self.dither()        
        self.remove(matrix)

        self.setup()
        everything = self.get_mobjects()
        self.play(*map(FadeIn, everything) + [Animation(matrix)])
        func = self.get_matrix_transformation([[1, 1], [-1, 0]])
        bases = VMobject(self.i_hat, self.j_hat)
        new_bases = VMobject(*[
            Vector(func(v.get_end()), color = v.get_color())
            for v in bases.split()
        ])
        self.play(
            ApplyPointwiseFunction(func, self.plane),
            Transform(bases, new_bases),
            Animation(matrix),
            run_time = 3
        )
        self.dither()
开发者ID:PythonJedi,项目名称:manim,代码行数:28,代码来源:chapter4.py


示例2: move_matrix_parentheses

    def move_matrix_parentheses(self, morty, matrices):
        m1, m2, m3 = matrices
        parens = TexMobject(["(", ")"])
        parens.scale_to_fit_height(1.2*m1.get_height())
        lp, rp = parens.split()
        state1 = VMobject(
            VectorizedPoint(m1.get_left()),
            m1, m2, 
            VectorizedPoint(m2.get_right()),
            m3
        )
        state2 = VMobject(*[
            m.copy() for m in lp, m1, m2, rp, m3
        ])
        state3 = VMobject(*[
            m.copy() for m in m1, lp, m2, m3, rp
        ])
        for state in state2, state3:
            state.arrange_submobjects(RIGHT, buff = 0.1)
        m1, lp, m2, m3, rp = state3.split()
        state3 = VMobject(lp, m1, m2, rp, m3)

        self.play(morty.change_mode, "angry")
        for state in state2, state3:
            self.play(Transform(state1, state))
            self.dither()
        self.play(morty.change_mode, "confused")
        self.dither()
开发者ID:PythonJedi,项目名称:manim,代码行数:28,代码来源:chapter4.py


示例3: record_basis_coordinates

    def record_basis_coordinates(self, vect_array, vect):
        i_label = vector_coordinate_label(self.i_hat)
        i_label.highlight(X_COLOR)
        j_label = vector_coordinate_label(self.j_hat)
        j_label.highlight(Y_COLOR)
        for mob in i_label, j_label:
            mob.scale_in_place(0.8)
            background = BackgroundRectangle(mob)
            self.play(ShowCreation(background), Write(mob))

        self.dither()
        x, y = vect_array.get_entries().split()
        pre_formula = VMobject(
            x, i_label, TexMobject("+"),
            y, j_label
        )
        post_formula = pre_formula.copy()
        pre_formula.split()[2].fade(1)
        post_formula.arrange_submobjects(buff = 0.1)
        post_formula.next_to(vect, DOWN)
        background = BackgroundRectangle(post_formula)
        everything = self.get_mobjects()
        everything.remove(vect)
        self.play(*[
            ApplyMethod(m.fade) for m in everything
        ] + [
            ShowCreation(background, run_time = 2, rate_func = squish_rate_func(smooth, 0.5, 1)),
            Transform(pre_formula.copy(), post_formula, run_time = 2),
            ApplyMethod(vect.set_stroke, width = 7)
        ])
        self.dither()
开发者ID:PythonJedi,项目名称:manim,代码行数:31,代码来源:chapter4.py


示例4: construct

    def construct(self):
        matrix = Matrix([
            [2, 0],
            [-1, 1],
            [-2, 1],
        ])
        matrix.highlight_columns(X_COLOR, Y_COLOR)

        brace = Brace(matrix)
        words = VMobject(
            TextMobject("Span", "of columns"),
            TexMobject("\\Updownarrow"),
            TextMobject("``Column space''")
        )
        words.arrange_submobjects(DOWN, buff = 0.1)
        words.next_to(brace, DOWN)
        words[0][0].highlight(PINK)
        words[2].highlight(TEAL)
        words[0].add_background_rectangle()
        words[2].add_background_rectangle()
        VMobject(matrix, brace, words).center()

        self.add(matrix)
        self.play(
            GrowFromCenter(brace),
            Write(words, run_time = 2)
        )
        self.dither()
开发者ID:PythonJedi,项目名称:manim,代码行数:28,代码来源:footnote2.py


示例5: add_braces

    def add_braces(self):
        a = self.i_hat.get_end()[0]*RIGHT
        b = self.j_hat.get_end()[0]*RIGHT
        c = self.i_hat.get_end()[1]*UP
        d = self.j_hat.get_end()[1]*UP

        quads = [
            (ORIGIN, a, DOWN, "a"),
            (a, a+b, DOWN, "b"),
            (a+b, a+b+c, RIGHT, "c"),
            (a+b+c, a+b+c+d, RIGHT, "d"),
            (a+b+c+d, a+c+d, UP, "a"),
            (a+c+d, d+c, UP, "b"),
            (d+c, d, LEFT, "c"),
            (d, ORIGIN, LEFT, "d"),
        ]
        everyone = VMobject()
        for p1, p2, direction, char in quads:
            line = Line(p1, p2)
            brace = Brace(line, direction, buff = 0)
            text = brace.get_text(char)
            text.add_background_rectangle()
            if char in ["a", "c"]:
                text.highlight(X_COLOR)
            else:
                text.highlight(Y_COLOR)
            everyone.add(brace, text)
        self.play(Write(everyone), run_time = 1)
开发者ID:xhrwang,项目名称:manim,代码行数:28,代码来源:chapter5.py


示例6: construct

    def construct(self):
        self.setup()
        self.add_unit_square()
        matrix = Matrix(np.array(self.t_matrix).transpose())
        matrix.next_to(ORIGIN, LEFT)
        matrix.to_edge(UP)
        matrix.highlight_columns(X_COLOR, Y_COLOR)

        det_text = get_det_text(
            matrix, determinant = np.linalg.det(self.t_matrix)
        )
        three = VMobject(*det_text.split()[-1].split()[1:])
        for mob in det_text.split():
            if isinstance(mob, TexMobject):
                mob.add_background_rectangle()
        matrix_background = BackgroundRectangle(matrix)
        self.play(
            ShowCreation(matrix_background),
            Write(matrix),
            Write(det_text),
        )
        self.add_foreground_mobject(matrix_background, matrix, det_text)
        self.dither()
        self.apply_transposed_matrix(self.t_matrix)

        self.play(three.copy().move_to, self.square)
        self.dither()
开发者ID:xhrwang,项目名称:manim,代码行数:27,代码来源:chapter5.py


示例7: describe_scalars

    def describe_scalars(self, v, plane):
        axes = plane.get_axes()
        long_v = Vector(2*v.get_end())
        long_minus_v = Vector(-2*v.get_end())
        original_v = v.copy()
        scaling_word = TextMobject("``Scaling''").to_corner(UP+LEFT)
        scaling_word.shift(2*RIGHT)
        scalars = VMobject(*map(TexMobject, [
            "2,", "\\dfrac{1}{3},", "-1.8,", "\\dots"
        ]))
        scalars.arrange_submobjects(RIGHT, buff = 0.4)
        scalars.next_to(scaling_word, DOWN, aligned_edge = LEFT)
        scalars_word = TextMobject("``Scalars''")
        scalars_word.next_to(scalars, DOWN, aligned_edge = LEFT)

        self.remove(plane)
        self.add(axes)
        self.play(
            Write(scaling_word),
            Transform(v, long_v),
            run_time = 1.5
        )
        self.play(Transform(v, long_minus_v, run_time = 3))
        self.play(Write(scalars))
        self.dither()
        self.play(Write(scalars_word))
        self.play(Transform(v, original_v), run_time = 3)
        self.dither(2)
开发者ID:namkam5,项目名称:manim,代码行数:28,代码来源:chapter1.py


示例8: construct

    def construct(self):
        physy = Physicist()
        mathy = Mathematician(mode = "pondering")        
        compy = ComputerScientist()
        creatures = [physy, compy, mathy]
        physy.title = TextMobject("Physics student").to_corner(DOWN+LEFT)
        compy.title = TextMobject("CS student").to_corner(DOWN+RIGHT)
        mathy.title = TextMobject("Mathematician").to_edge(DOWN)
        names = VMobject(physy.title, mathy.title, compy.title)
        names.arrange_submobjects(RIGHT, buff = 1)
        names.to_corner(DOWN+LEFT)
        for pi in creatures:
            pi.next_to(pi.title, UP)

        vector, symbol, coordinates = self.intro_vector()
        for pi in creatures:
            self.play(
                Write(pi.title),
                FadeIn(pi),
                run_time = 1
            )
        self.dither(2)
        self.remove(symbol, coordinates)
        self.physics_conception(creatures, vector)
        self.cs_conception(creatures)
        self.handle_mathy(creatures)
开发者ID:namkam5,项目名称:manim,代码行数:26,代码来源:chapter1.py


示例9: show_scaled_vectors

    def show_scaled_vectors(self, vect_array, vect_coords, i_label, j_label):
        x, y = vect_array.get_entries().split()
        scaled_i_label = VMobject(x.copy(), i_label.copy())
        scaled_j_label = VMobject(y.copy(), j_label.copy())
        scaled_i = self.i_hat.copy().scale(vect_coords[0])
        scaled_j = self.j_hat.copy().scale(vect_coords[1])
        for mob in scaled_i, scaled_j:
            mob.fade(0.3)
        scaled_i_label_target = scaled_i_label.copy()
        scaled_i_label_target.arrange_submobjects(buff = 0.1)
        scaled_i_label_target.next_to(scaled_i.get_center(), DOWN)
        scaled_j_label_target = scaled_j_label.copy()
        scaled_j_label_target.arrange_submobjects(buff = 0.1)
        scaled_j_label_target.next_to(scaled_j.get_center(), LEFT)

        self.play(
            Transform(self.i_hat.copy(), scaled_i),
            Transform(scaled_i_label, scaled_i_label_target)
        )
        scaled_i = self.get_mobjects_from_last_animation()[0]
        self.play(
            Transform(self.j_hat.copy(), scaled_j),
            Transform(scaled_j_label, scaled_j_label_target)
        )
        scaled_j = self.get_mobjects_from_last_animation()[0]
        self.play(*[
            ApplyMethod(mob.shift, scaled_i.get_end())
            for mob in scaled_j, scaled_j_label
        ])
        self.dither()
        self.play(*map(FadeOut, [
            scaled_i, scaled_j, scaled_i_label, scaled_j_label,
        ]))
开发者ID:PythonJedi,项目名称:manim,代码行数:33,代码来源:chapter4.py


示例10: add_polygons

    def add_polygons(self):
        a = self.i_hat.get_end()[0]*RIGHT
        b = self.j_hat.get_end()[0]*RIGHT
        c = self.i_hat.get_end()[1]*UP
        d = self.j_hat.get_end()[1]*UP

        shapes_colors_and_tex = [
            (Polygon(ORIGIN, a, a+c), TEAL, "bd/2"),
            (Polygon(ORIGIN, d+b, d), TEAL, "\\dfrac{bd}{2}"),
            (Polygon(a+c, a+b+c, a+b+c+d), MAROON, "\\dfrac{ac}{2}"),
            (Polygon(b+d, a+b+c+d, b+c+d), MAROON, "ac/2"),
            (Polygon(a, a+b, a+b+c, a+c), PINK, "bc"),
            (Polygon(d, d+b, d+b+c, d+c), PINK, "bc"),
        ]
        everyone = VMobject()
        for shape, color, tex in shapes_colors_and_tex:
            shape.set_stroke(width = 0)
            shape.set_fill(color = color, opacity = 0.7)
            tex_mob = TexMobject(tex)
            tex_mob.scale(0.7)
            tex_mob.move_to(shape.get_center_of_mass())
            everyone.add(shape, tex_mob)
        self.play(FadeIn(
            everyone, 
            submobject_mode = "lagged_start",
            run_time = 1
        ))
开发者ID:xhrwang,项目名称:manim,代码行数:27,代码来源:chapter5.py


示例11: get_matrix_multiplication_question

 def get_matrix_multiplication_question(self):
     why = TextMobject("Why?").highlight(BLUE) 
     mult = self.get_matrix_multiplication()
     why.next_to(mult, UP)
     result = VMobject(why, mult)
     result.get_center = lambda : mult.get_center()
     return result
开发者ID:PythonJedi,项目名称:manim,代码行数:7,代码来源:chapter0.py


示例12: show_dependencies

    def show_dependencies(self):
        linalg = TextMobject("Linear Algebra")
        subjects = map(TextMobject, [
            "Computer science",
            "Physics",
            "Electrical engineering",
            "Mechanical engineering",
            "Statistics",
            "\\vdots"
        ])
        prev = subjects[0]
        for subject in subjects[1:]:
            subject.next_to(prev, DOWN, aligned_edge = LEFT)
            prev = subject
        all_subs = VMobject(*subjects)
        linalg.to_edge(LEFT)
        all_subs.next_to(linalg, RIGHT, buff = 2)
        arrows = VMobject(*[
            Arrow(linalg, sub)
            for sub in subjects
        ])

        self.play(Write(linalg, run_time = 1))
        self.dither()
        self.play(
            ShowCreation(arrows, submobject_mode = "lagged_start"),
            FadeIn(all_subs),
            run_time = 2
        )
        self.dither()
        self.linalg = linalg
开发者ID:PythonJedi,项目名称:manim,代码行数:31,代码来源:chapter0.py


示例13: Arrow

class Arrow(Line):
    CONFIG = {
        "color"      : YELLOW_C,
        "tip_length" : 0.25,
        "tip_angle"  : np.pi/6,
        "buff"       : MED_SMALL_BUFF,
        "propogate_style_to_family" : False,
        "preserve_tip_size_when_scaling" : True,
    }
    def __init__(self, *args, **kwargs):
        points = map(self.pointify, args)
        if len(args) == 1:
            args = (points[0]+UP+LEFT, points[0])
        Line.__init__(self, *args, **kwargs)
        self.add_tip()

    def add_tip(self, add_at_end = True):
        vect = self.tip_length*RIGHT
        vect = rotate_vector(vect, self.get_angle()+np.pi)
        start, end = self.get_start_and_end()
        if not add_at_end:
            start, end = end, start
            vect = -vect
        tip_points = [
            end+rotate_vector(vect, u*self.tip_angle)
            for u in 1, -1
        ]
        self.tip = VMobject(
            close_new_points = True,
            mark_paths_closed = True,
            fill_color = self.color,
            fill_opacity = 1,
            stroke_color = self.color,
        )
        self.tip.set_anchor_points(
            [tip_points[0], end, tip_points[1]],
            mode = "corners"
        )
        self.set_points_as_corners(
            [start, center_of_mass(tip_points)]
        )
        self.add(self.tip)
        self.init_colors()

    def get_end(self):
        if hasattr(self, "tip"):
            return self.tip.get_anchors()[1]
        else:
            return Line.get_end(self)

    def get_tip(self):
        return self.tip

    def scale(self, scale_factor, **kwargs):
        Line.scale(self, scale_factor, **kwargs)
        if self.preserve_tip_size_when_scaling:
            self.remove(self.tip)
            self.add_tip()
        return self
开发者ID:crclayton,项目名称:manim,代码行数:59,代码来源:geometry.py


示例14: init_colors

 def init_colors(self):
     VMobject.init_colors(self)
     self.axes.set_stroke(self.axes_color, self.stroke_width)
     self.main_lines.set_stroke(self.color, self.stroke_width)
     self.secondary_lines.set_stroke(
         self.secondary_color, self.secondary_stroke_width
     )
     return self
开发者ID:PythonJedi,项目名称:manim,代码行数:8,代码来源:number_line.py


示例15: __init__

 def __init__(self, **kwargs):
     hand = SVGMobject("RightHandOutline")
     self.inlines = VMobject(*hand.split()[:-4])
     self.outline = VMobject(*hand.split()[-4:])
     self.outline.set_stroke(color = WHITE, width = 5)
     self.inlines.set_stroke(color = DARK_GREY, width = 3)
     VMobject.__init__(self, self.outline, self.inlines)
     self.center().scale_to_fit_height(3)
开发者ID:xhrwang,项目名称:manim,代码行数:8,代码来源:chapter5.py


示例16: construct

 def construct(self):
     mob = VMobject(
         TextMobject("Computer graphics"),
         TextMobject("Robotics")
     )
     mob.arrange_submobjects(DOWN, buff = 1)
     self.play(Write(mob, run_time = 1))
     self.dither()
开发者ID:PythonJedi,项目名称:manim,代码行数:8,代码来源:footnote.py


示例17: introduce_coordinate_plane

    def introduce_coordinate_plane(self):
        plane = NumberPlane()
        x_axis, y_axis = plane.get_axes().copy().split()
        x_label, y_label = plane.get_axis_labels().split()
        number_line = NumberLine(tick_frequency = 1)
        x_tick_marks = number_line.get_tick_marks()
        y_tick_marks = x_tick_marks.copy().rotate(np.pi/2)
        tick_marks = VMobject(x_tick_marks, y_tick_marks)
        tick_marks.highlight(WHITE)
        plane_lines = filter(
            lambda m : isinstance(m, Line),
            plane.submobject_family()
        )
        origin_words = TextMobject("Origin")
        origin_words.shift(2*UP+2*LEFT)
        dot = Dot(radius = 0.1).highlight(RED)
        line = Line(origin_words.get_bottom(), dot.get_corner(UP+LEFT))

        unit_brace = Brace(Line(RIGHT, 2*RIGHT))
        one = TexMobject("1").next_to(unit_brace, DOWN)

        self.add(x_axis, x_label)
        self.dither()
        self.play(ShowCreation(y_axis))
        self.play(Write(y_label, run_time = 1))
        self.dither(2)
        self.play(
            Write(origin_words),
            GrowFromCenter(dot),
            ShowCreation(line),
            run_time = 1
        )
        self.dither(2)
        self.play(
            FadeOut(VMobject(origin_words, dot, line))
        )
        self.remove(origin_words, dot, line)
        self.dither()
        self.play(
            ShowCreation(tick_marks, submobject_mode = "one_at_a_time")
        )
        self.play(
            GrowFromCenter(unit_brace),
            Write(one, run_time = 1)            
        )
        self.dither(2)
        self.remove(unit_brace, one)
        self.play(
            *map(GrowFromCenter, plane_lines) + [
            Animation(x_axis), Animation(y_axis)
        ])
        self.dither()
        self.play(
            FadeOut(plane),
            Animation(VMobject(x_axis, y_axis, tick_marks))
        )
        self.remove(plane)
        self.add(tick_marks)
开发者ID:namkam5,项目名称:manim,代码行数:58,代码来源:chapter1.py


示例18: construct

 def construct(self):
     arrow = Vector(2*UP+RIGHT)
     vs = TextMobject("vs.")
     array = Matrix([1, 2])
     array.highlight(TEAL)
     everyone = VMobject(arrow, vs, array)
     everyone.arrange_submobjects(RIGHT, buff = 0.5)
     everyone.scale_to_fit_height(4)
     self.add(everyone)
开发者ID:scottopell,项目名称:manim,代码行数:9,代码来源:thumbnails.py


示例19: add_symbols

 def add_symbols(self):
     v = matrix_to_mobject(self.v_coords).highlight(self.v_color)
     w = matrix_to_mobject(self.w_coords).highlight(self.w_color)
     v.add_background_rectangle()
     w.add_background_rectangle()
     dot = TexMobject("\\cdot")
     eq = VMobject(v, dot, w)
     eq.arrange_submobjects(RIGHT, buff = SMALL_BUFF)
     eq.to_corner(UP+LEFT)
     self.play(Write(eq), run_time = 1)
开发者ID:PythonJedi,项目名称:manim,代码行数:10,代码来源:footnote2.py


示例20: get_cross_product_question

 def get_cross_product_question(self):
     cross = TexMobject("\\vec{v} \\times \\vec{w}")
     left_right_arrow = DoubleArrow(Point(LEFT), Point(RIGHT))
     det = TextMobject("Det")
     q_mark = TextMobject("?")
     left_right_arrow.next_to(cross)
     det.next_to(left_right_arrow)
     q_mark.next_to(left_right_arrow, UP)
     cross_question = VMobject(cross, left_right_arrow, q_mark, det)
     cross_question.get_center = lambda : left_right_arrow.get_center()
     return cross_question
开发者ID:PythonJedi,项目名称:manim,代码行数:11,代码来源:chapter0.py



注:本文中的mobject.vectorized_mobject.VMobject类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python exceptions.mcdp_dev_warning函数代码示例发布时间:2022-05-27
下一篇:
Python vectorized_mobject.VGroup类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap