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


Python mobject.Mobject类代码示例

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


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

示例1: get_circles_and_points

    def get_circles_and_points(self, min_input, max_input):
        input_left, input_right = [
            self.interval.number_to_point(num)
            for num in min_input, max_input
        ]
        input_circle = Circle(
            radius = np.linalg.norm(input_left-input_right)/2,
            color = WHITE
        )
        input_circle.shift((input_left+input_right)/2)

        input_points = Line(
            input_left, input_right, 
            color = self.input_color
        )
        output_points = Mobject(color = self.output_color)
        n = self.output.get_num_points()
        output_points.add_points(
            self.output.points[int(min_input*n):int(max_input*n)]
        )
        output_center = output_points.points[int(0.5*output_points.get_num_points())]
        max_distance = np.linalg.norm(output_center-output_points.points[-1])
        output_circle = Circle(
            radius = max_distance, 
            color = WHITE
        )
        output_circle.shift(output_center)
        return (
            input_circle, 
            input_points, 
            output_circle, 
            output_points
        )
开发者ID:Rubixdarcy,项目名称:manim,代码行数:33,代码来源:section2.py

示例2: construct

    def construct(self):
        curve = HilbertCurve(order = 6)
        curve.highlight(WHITE)
        colored_curve = curve.copy()
        colored_curve.thin_out(3)
        lion = ImageMobject("lion", invert = False)
        lion.replace(curve, stretch = True)
        sparce_lion = lion.copy()
        sparce_lion.thin_out(100)
        distance_matrix = cdist(colored_curve.points, sparce_lion.points)
        closest_point_indices = np.apply_along_axis(
            np.argmin, 1, distance_matrix
        )
        colored_curve.rgbs = sparce_lion.rgbs[closest_point_indices]
        line = Line(5*LEFT, 5*RIGHT)
        Mobject.align_data(line, colored_curve)
        line.rgbs = colored_curve.rgbs

        self.add(lion)
        self.play(ShowCreation(curve, run_time = 3))
        self.play(
            FadeOut(lion),
            Transform(curve, colored_curve),
            run_time = 3
        )
        self.dither()
        self.play(Transform(curve, line, run_time = 5))
        self.dither()
开发者ID:Rubixdarcy,项目名称:manim,代码行数:28,代码来源:section2.py

示例3: setup

    def setup(self):
        self.input_color = YELLOW_C
        self.output_color = RED
        def spiril(t):
            theta = 2*np.pi*t
            return t*np.cos(theta)*RIGHT+t*np.sin(theta)*UP

        self.spiril1 = ParametricFunction(
            lambda t : 1.5*RIGHT + DOWN + 2*spiril(t),
            density = 5*DEFAULT_POINT_DENSITY_1D,
        )
        self.spiril2 = ParametricFunction(
            lambda t : 5.5*RIGHT + UP - 2*spiril(1-t),
            density = 5*DEFAULT_POINT_DENSITY_1D,
        )
        Mobject.align_data(self.spiril1, self.spiril2)
        self.output = Mobject(self.spiril1, self.spiril2)
        self.output.ingest_sub_mobjects()
        self.output.highlight(GREEN_A)

        self.interval = UnitInterval()
        self.interval.scale_to_fit_width(SPACE_WIDTH-1)
        self.interval.to_edge(LEFT)

        self.input_dot = Dot(color = self.input_color)
        self.output_dot = self.input_dot.copy().highlight(self.output_color)
        left, right = self.interval.get_left(), self.interval.get_right()
        self.input_homotopy = lambda (x, y, z, t) : (x, y, t) + interpolate(left, right, t)
        output_size = self.output.get_num_points()-1
        output_points = self.output.points        
        self.output_homotopy = lambda (x, y, z, t) : (x, y, z) + output_points[int(t*output_size)]
开发者ID:Rubixdarcy,项目名称:manim,代码行数:31,代码来源:section2.py

示例4: __init__

    def __init__(self, **kwargs):
        x_axis = NumberLine(**kwargs)
        y_axis = NumberLine(**kwargs).rotate(np.pi/2, OUT)
        Mobject.__init__(self, x_axis, y_axis)


        
开发者ID:mherkazandjian,项目名称:manim,代码行数:4,代码来源:functions.py

示例5: __init__

 def __init__(self, *args, **kwargs):
     Mobject.__init__(self, *args, **kwargs)
     complex_power = 0.9
     radius = self.INITIAL_WIDTH/2
     circle = Circle(density = radius*DEFAULT_POINT_DENSITY_1D)
     circle.apply_complex_function(lambda z : z**complex_power)
     circle.scale(radius)
     boundary_point_as_complex = radius*complex(-1)**complex_power
     boundary_points = [
         [
             boundary_point_as_complex.real,
             unit*boundary_point_as_complex.imag,
             0
         ]
         for unit in -1, 1
     ]
     tip = radius*(1.5*LEFT+UP)
     self.add(
         circle,
         Line(boundary_points[0], tip),
         Line(boundary_points[1], tip)
     )
     self.highlight("white")
     self.rotate(np.pi/2)
     self.points[:,1] *= float(self.INITIAL_HEIGHT)/self.INITIAL_WIDTH
     Bubble.__init__(self, direction = LEFT)
开发者ID:nachinius,项目名称:animations,代码行数:26,代码来源:simple_mobjects.py

示例6: snells_law_at_every_point

 def snells_law_at_every_point(self, cycloid, chopped_cycloid):
     square = Square(side_length = 0.2, color = WHITE)
     words = TextMobject(["Snell's law ", "everywhere"])
     snells, rest = words.split()
     colon = TextMobject(":")
     words.next_to(square)
     words.shift(0.3*UP)
     combo = Mobject(square, words)
     combo.get_center = lambda : square.get_center()
     new_snells = snells.copy().center().to_edge(UP, buff = 1.5)
     colon.next_to(new_snells)
     colon.shift(0.05*DOWN)
         
     self.play(MoveAlongPath(
         combo, cycloid,
         run_time = 5
     ))
     self.play(MoveAlongPath(
         combo, chopped_cycloid,
         run_time = 4
     ))
     dot = Dot(combo.get_center())
     self.play(Transform(square, dot))
     self.play(
         Transform(snells, new_snells),
         Transform(rest, colon)
     )
     self.dither()
     return colon
开发者ID:GodotMisogi,项目名称:manim,代码行数:29,代码来源:multilayered.py

示例7: show_sin_thetas

    def show_sin_thetas(self):
        pc = Line(self.p_point, self.c_point)
        mob = Mobject(self.theta, self.d_mob).copy()
        mob.ingest_submobjects()
        triplets = [
            (pc, "D\\sin(\\theta)", 0.5),
            (self.y_line, "D\\sin^2(\\theta)", 0.7),
        ]
        for line, tex, scale in triplets:
            trig_mob = TexMobject(tex)
            trig_mob.scale_to_fit_width(
                scale*line.get_length()
            )
            trig_mob.shift(-1.2*trig_mob.get_top())
            trig_mob.rotate(line.get_angle())
            trig_mob.shift(line.get_center())
            if line is self.y_line:
                trig_mob.shift(0.1*UP) 

            self.play(Transform(mob, trig_mob))
            self.add(trig_mob)
            self.dither()

        self.remove(mob)
        self.d_sin_squared_theta = trig_mob
开发者ID:GodotMisogi,项目名称:manim,代码行数:25,代码来源:cycloid.py

示例8: Flash

class Flash(Animation):
    CONFIG = {
        "color" : "white",
        "slow_factor" : 0.01,
        "run_time" : 0.1,
        "rate_func" : None,
    }
    def __init__(self, mobject, **kwargs):
        self.intermediate = Mobject(color = self.color)
        self.intermediate.add_points([
            point + (x, y, 0)
            for point in self.mobject.points
            for x in [-1, 1]
            for y in [-1, 1]
        ])
        Animation.__init__(self, mobject, **kwargs)        

    def update_mobject(self, alpha):
        #Makes alpha go from 0 to slow_factor to 0 instead of 0 to 1
        alpha = self.slow_factor * (1.0 - 4 * (alpha - 0.5)**2)
        self.mobject.interpolate(
            self.starting_mobject, 
            self.intermediate, 
            alpha
        )
开发者ID:GodotMisogi,项目名称:manim,代码行数:25,代码来源:simple_animations.py

示例9: __init__

    def __init__(self, mobject1, mobject2, 
                 run_time = DEFAULT_TRANSFORM_RUN_TIME,
                 interpolation_function = straight_path,
                 black_out_extra_points = False,
                 *args, **kwargs):
        self.interpolation_function = interpolation_function
        count1, count2 = mobject1.get_num_points(), mobject2.get_num_points()
        if count2 == 0:
            mobject2 = Point((SPACE_WIDTH, SPACE_HEIGHT, 0))
            count2 = mobject2.get_num_points()
        Mobject.align_data(mobject1, mobject2)
        Animation.__init__(self, mobject1, run_time = run_time, *args, **kwargs)
        self.ending_mobject = mobject2
        self.mobject.SHOULD_BUFF_POINTS = \
            mobject1.SHOULD_BUFF_POINTS and mobject2.SHOULD_BUFF_POINTS
        self.reference_mobjects.append(mobject2)
        self.name += "To" + str(mobject2)

        if black_out_extra_points and count2 < count1:
            #Ensure redundant pixels fade to black
            indices = np.arange(
                0, count1-1, float(count1) / count2
            ).astype('int')
            temp = np.zeros(mobject2.points.shape)
            temp[indices] = mobject2.rgbs[indices]
            mobject2.rgbs = temp
            self.non_redundant_m2_indices = indices
开发者ID:nachinius,项目名称:animations,代码行数:27,代码来源:transform.py

示例10: __init__

 def __init__(self, **kwargs):
     Mobject.__init__(self, **kwargs)
     for part_name in self.PART_NAMES:
         mob = ImageMobject(
             part_name_to_directory(part_name),
             should_center = False
         )
         if part_name not in self.WHITE_PART_NAMES:
             mob.highlight(self.color)
         setattr(self, part_name, mob)
     self.eyes = Mobject(self.left_eye, self.right_eye)
     self.legs = Mobject(self.left_leg, self.right_leg)
     mouth_center = self.get_mouth_center()
     self.mouth.center()
     self.smile = self.mouth
     self.frown = self.mouth.copy().rotate(np.pi, RIGHT)
     self.straight_mouth = TexMobject("-").scale(0.7)
     for mouth in self.smile, self.frown, self.straight_mouth:
         mouth.sort_points(lambda p : p[0])
         mouth.highlight(self.color) ##to blend into background
         mouth.shift(mouth_center)
     self.digest_mobject_attrs()
     self.give_smile()
     self.add(self.mouth)
     self.scale(PI_CREATURE_SCALE_VAL)
开发者ID:Rubixdarcy,项目名称:manim,代码行数:25,代码来源:characters.py

示例11: play

    def play(self, *animations, **kwargs):
        self.num_animations += 1
        if "run_time" in kwargs:
            run_time = kwargs["run_time"]
        else:
            run_time = animations[0].run_time
        for animation in animations:
            animation.set_run_time(run_time)
        moving_mobjects = [mobject for anim in animations for mobject in anim.mobject.submobject_family()]

        bundle = Mobject(*self.mobjects)
        static_mobjects = filter(lambda m: m not in moving_mobjects, bundle.submobject_family())
        background = disp.paint_mobjects(static_mobjects, self.background, include_sub_mobjects=False)

        times = np.arange(0, run_time, self.frame_duration)
        time_progression = ProgressDisplay(times)
        time_progression.set_description(
            "Animation %d: " % self.num_animations + str(animations[0]) + (", etc." if len(animations) > 1 else "")
        )
        for t in time_progression:
            for animation in animations:
                animation.update(t / animation.run_time)
            new_frame = disp.paint_mobjects([anim.mobject for anim in animations], background)
            self.frames.append(new_frame)
        for animation in animations:
            animation.clean_up()
        self.add(*[anim.mobject for anim in animations])
        self.repaint_mojects()
        return self
开发者ID:Rubixdarcy,项目名称:manim,代码行数:29,代码来源:scene.py

示例12: __init__

 def __init__(self, expression, **kwargs):
     if "size" not in kwargs:
         #Todo, make this more sophisticated.
         if len("".join(expression)) < MAX_LEN_FOR_HUGE_TEX_FONT:
             size = "\\Huge"
         else:
             size = "\\large"
     digest_locals(self)
     Mobject.__init__(self, **kwargs)
开发者ID:Rubixdarcy,项目名称:manim,代码行数:9,代码来源:tex_mobject.py

示例13: __init__

 def __init__(self, condition = (lambda x, y : True), **kwargs):
     """
     Condition must be a function which takes in two real
     arrays (representing x and y values of space respectively)
     and return a boolean array.  This can essentially look like
     a function from R^2 to {True, False}, but & and | must be
     used in place of "and" and "or"
     """
     Mobject.__init__(self, **kwargs)
     self.condition = condition
开发者ID:GodotMisogi,项目名称:manim,代码行数:10,代码来源:region.py

示例14: construct

    def construct(self):
        words, s = TextMobject(["Pseudo-Hilbert Curve", "s"]).split()
        pre_words = TextMobject("Order 1")
        pre_words.next_to(words, LEFT, buff = 0.5)
        s.next_to(words, RIGHT, buff = 0.05, aligned_edge = DOWN)
        cluster = Mobject(pre_words, words, s)
        cluster.center()
        cluster.scale(0.7)
        cluster.to_edge(UP, buff = 0.3)
        cluster.highlight(GREEN)
        grid1 = Grid(1, 1)
        grid2 = Grid(2, 2)
        curve = HilbertCurve(order = 1)

        self.add(words, s)
        self.dither()
        self.play(Transform(
            s, pre_words, 
            path_func = path_along_arc(-np.pi/3)
        ))
        self.dither()
        self.play(ShowCreation(grid1))
        self.dither()
        self.play(ShowCreation(grid2))
        self.dither()
        kwargs = {
            "run_time" : 5,
            "rate_func" : None
        }
        self.play(ShowCreation(curve, **kwargs))
        self.dither()
开发者ID:GodotMisogi,项目名称:manim,代码行数:31,代码来源:section1.py

示例15: play

 def play(self, *args, **kwargs):
     if not self.has_started:
         self.has_started = True
         everything = Mobject(*self.mobjects)
         vect = 2*SPACE_WIDTH*RIGHT
         everything.shift(vect)
         self.play(ApplyMethod(
             everything.shift, -vect,
             rate_func = rush_from
         ))
     Scene.play(self, *args, **kwargs)
开发者ID:PythonJedi,项目名称:manim,代码行数:11,代码来源:light.py


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