当前位置: 首页>>代码示例>>Python>>正文


Python Mobject.add方法代码示例

本文整理汇总了Python中mobject.Mobject.add方法的典型用法代码示例。如果您正苦于以下问题:Python Mobject.add方法的具体用法?Python Mobject.add怎么用?Python Mobject.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mobject.Mobject的用法示例。


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

示例1: construct

# 需要导入模块: from mobject import Mobject [as 别名]
# 或者: from mobject.Mobject import add [as 别名]
    def construct(self, order):
        start_color, end_color = RED, GREEN
        curve = HilbertCurve(order = order)
        line = Line(5*LEFT, 5*RIGHT)
        for mob in curve, line:
            mob.gradient_highlight(start_color, end_color)
        freq_line = get_freq_line()
        freq_line.replace(line, stretch = True)

        unit = 6./(2**order) #sidelength of pixel
        up = unit*UP
        right = unit*RIGHT
        lower_left = 3*(LEFT+DOWN)
        squares = Mobject(*[
            Square(
                side_length = unit, 
                color = WHITE
            ).shift(x*right+y*up)
            for x, y in it.product(range(2**order), range(2**order))
        ])
        squares.center()
        targets = Mobject()
        for square in squares.submobjects:
            center = square.get_center()
            distances = np.apply_along_axis(
                lambda p : np.linalg.norm(p-center),
                1,
                curve.points
            )
            index_along_curve = np.argmin(distances)
            fraction_along_curve = index_along_curve/float(curve.get_num_points())
            target = square.copy().center().scale(0.8/(2**order))
            line_index = int(fraction_along_curve*line.get_num_points())
            target.shift(line.points[line_index])
            targets.add(target)


        self.add(squares)
        self.play(ShowCreation(
            curve,
            run_time = 5, 
            rate_func = None
        ))
        self.dither()
        self.play(
            Transform(curve, line),
            Transform(squares, targets),
            run_time = 3
        )
        self.dither()
        self.play(ShowCreation(freq_line))
        self.dither()
开发者ID:GodotMisogi,项目名称:manim,代码行数:54,代码来源:section1.py

示例2: construct

# 需要导入模块: from mobject import Mobject [as 别名]
# 或者: from mobject.Mobject import add [as 别名]
    def construct(self):
        glass = Region(lambda x, y : y < 0, color = BLUE_E)
        self.generate_start_and_end_points()
        left = self.start_point[0]*RIGHT
        right = self.end_point[0]*RIGHT
        start_x = interpolate(left, right, 0.2)
        end_x = interpolate(left, right, 1.0)
        left_line = Line(self.start_point, left, color = RED_D)
        right_line = Line(self.end_point, right, color = RED_D)
        h_1, h_2 = map(TexMobject, ["h_1", "h_2"])
        h_1.next_to(left_line, LEFT)
        h_2.next_to(right_line, RIGHT)
        point_a = Dot(self.start_point)
        point_b = Dot(self.end_point)
        A = TextMobject("A").next_to(point_a, UP)
        B = TextMobject("B").next_to(point_b, DOWN)

        x = start_x
        left_brace = Brace(Mobject(Point(left), Point(x)))
        right_brace = Brace(Mobject(Point(x), Point(right)), UP)
        x_mob = TexMobject("x")
        x_mob.next_to(left_brace, DOWN)
        w_minus_x = TexMobject("w-x")
        w_minus_x.next_to(right_brace, UP)
        top_line = Line(self.start_point, x)
        bottom_line = Line(x, self.end_point)
        top_dist = TexMobject("\\sqrt{h_1^2+x^2}")
        top_dist.scale(0.5)
        a = 0.3
        n = top_line.get_num_points()
        point = top_line.points[int(a*n)]
        top_dist.next_to(Point(point), RIGHT, buff = 0.3)
        bottom_dist = TexMobject("\\sqrt{h_2^2+(w-x)^2}")
        bottom_dist.scale(0.5)
        n = bottom_line.get_num_points()
        point = bottom_line.points[int((1-a)*n)]
        bottom_dist.next_to(Point(point), LEFT, buff = 1)

        end_top_line = Line(self.start_point, end_x)
        end_bottom_line = Line(end_x, self.end_point)
        end_brace = Brace(Mobject(Point(left), Point(end_x)))
        end_x_mob = TexMobject("x").next_to(end_brace, DOWN)

        axes = Mobject(
            NumberLine(),
            NumberLine().rotate(np.pi/2).shift(7*LEFT)
        )
        graph = FunctionGraph(
            lambda x : 0.4*(x+1)*(x-3)+4,
            x_min = -2,
            x_max = 4
        )
        graph.highlight(YELLOW)
        Mobject(axes, graph).scale(0.2).to_corner(UP+RIGHT, buff = 1)
        axes.add(TexMobject("x", size = "\\small").next_to(axes, RIGHT))
        axes.add(TextMobject("Travel time", size = "\\small").next_to(
            axes, UP
        ))
        new_graph = graph.copy()
        midpoint = new_graph.points[new_graph.get_num_points()/2]
        new_graph.filter_out(lambda p : p[0] < midpoint[0])
        new_graph.reverse_points()
        pairs_for_end_transform = [
            (mob, mob.copy())
            for mob in top_line, bottom_line, left_brace, x_mob
        ]

        self.add(glass, point_a, point_b, A, B)
        line = Mobject(top_line, bottom_line).ingest_submobjects()
        self.play(ShowCreation(line))
        self.dither()
        self.play(
            GrowFromCenter(left_brace), 
            GrowFromCenter(x_mob)
        )
        self.play(
            GrowFromCenter(right_brace), 
            GrowFromCenter(w_minus_x)
        )
        self.play(ShowCreation(left_line), ShimmerIn(h_1))
        self.play(ShowCreation(right_line), GrowFromCenter(h_2))
        self.play(ShimmerIn(top_dist))
        self.play(GrowFromCenter(bottom_dist))
        self.dither(3)
        self.clear()
        self.add(glass, point_a, point_b, A, B, 
                 top_line, bottom_line, left_brace, x_mob)
        self.play(ShowCreation(axes))
        kwargs = {
            "run_time" : 4,
        }
        self.play(*[
            Transform(*pair, **kwargs)
            for pair in [
                (top_line, end_top_line),
                (bottom_line, end_bottom_line),
                (left_brace, end_brace),
                (x_mob, end_x_mob)
            ]
        ]+[ShowCreation(graph, **kwargs)])
#.........这里部分代码省略.........
开发者ID:PythonJedi,项目名称:manim,代码行数:103,代码来源:light.py


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