コード例 #1
0
ファイル: curves.py プロジェクト: GodotMisogi/manim
 def __init__(self, **kwargs):
     digest_config(self, kwargs)
     def func(t):
         t = (6*np.pi/2)*(t-0.5)
         return (t/2-np.sin(t))*RIGHT + \
                (np.cos(t)+(t**2)/10)*UP
     ParametricFunction.__init__(self, func, **kwargs)
コード例 #2
0
ファイル: graph_scene.py プロジェクト: snowdj/manim
    def graph_function(
        self,
        func,
        color=BLUE,
        animate=False,
        is_main_graph=True,
    ):
        def parameterized_function(alpha):
            x = interpolate(self.x_min, self.x_max, alpha)
            return self.coords_to_point(x, func(x))

        graph = ParametricFunction(
            parameterized_function,
            color=color,
            num_anchor_points=self.num_graph_anchor_points,
        )
        graph.underlying_function = func

        if is_main_graph:
            self.graph = graph
            self.func = func
        if animate:
            self.play(ShowCreation(graph))
        self.add(graph)
        return graph
コード例 #3
0
    def construct(self):
        t_axis = NumberLine()
        theta_axis = NumberLine().rotate(np.pi / 2)
        theta_mob = TexMobject("\\theta(t)")
        t_mob = TexMobject("t")
        theta_mob.next_to(theta_axis, RIGHT)
        theta_mob.to_edge(UP)
        t_mob.next_to(t_axis, UP)
        t_mob.to_edge(RIGHT)
        graph = ParametricFunction(
            lambda t: 4 * t * RIGHT + 2 * smooth(t) * UP)
        line = Line(graph.points[0], graph.points[-1], color=WHITE)
        q_mark = TextMobject("?")
        q_mark.next_to(Point(graph.get_center()), LEFT)
        stars = Stars(color=BLACK)
        stars.scale(0.1).shift(q_mark.get_center())

        squiggle = ParametricFunction(lambda t: t * RIGHT + 0.2 * t * (5 - t) *
                                      (np.sin(t)**2) * UP,
                                      start=0,
                                      end=5)

        self.play(ShowCreation(t_axis), ShowCreation(theta_axis),
                  ShimmerIn(theta_mob), ShimmerIn(t_mob))
        self.play(ShimmerIn(q_mark), ShowCreation(graph))
        self.wait()
        self.play(Transform(q_mark, stars), Transform(graph, line))
        self.wait()
        self.play(Transform(graph, squiggle))
        self.wait()
コード例 #4
0
ファイル: section2.py プロジェクト: zhujianing/manim
    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_submobjects()
        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)]
コード例 #5
0
ファイル: graph_scene.py プロジェクト: crclayton/manim
    def get_graph(
        self, func, 
        color = None,
        x_min = None,
        x_max = None,
        ):
        if color is None:
            color = self.default_graph_colors_cycle.next()
        if x_min is None:
            x_min = self.x_min
        if x_max is None:
            x_max = self.x_max

        def parameterized_function(alpha):
            x = interpolate(x_min, x_max, alpha)
            y = func(x)
            if not np.isfinite(y):
                y = self.y_max
            return self.coords_to_point(x, y)

        graph = ParametricFunction(
            parameterized_function, 
            color = color,
            num_anchor_points = self.num_graph_anchor_points,
        )
        graph.underlying_function = func
        return graph
コード例 #6
0
 def __init__(self, **kwargs):
     digest_config(self, kwargs)
     def func(t):
         t = (6*np.pi/2)*(t-0.5)
         return (t/2-np.sin(t))*RIGHT + \
                (np.cos(t)+(t**2)/10)*UP
     ParametricFunction.__init__(self, func, **kwargs)
コード例 #7
0
ファイル: graph_scene.py プロジェクト: liuliuy/manim
    def get_graph(
        self, func, 
        color = None,
        x_min = None,
        x_max = None,
        ):
        if color is None:
            color = self.default_graph_colors_cycle.next()
        if x_min is None:
            x_min = self.x_min
        if x_max is None:
            x_max = self.x_max

        def parameterized_function(alpha):
            x = interpolate(x_min, x_max, alpha)
            y = func(x)
            if not np.isfinite(y):
                y = self.y_max
            return self.coords_to_point(x, y)

        graph = ParametricFunction(
            parameterized_function, 
            color = color,
            num_anchor_points = self.num_graph_anchor_points,
        )
        graph.underlying_function = func
        return graph
コード例 #8
0
ファイル: number_line.py プロジェクト: ravi19ved/manim
 def get_graph(self, function, num_graph_points=None, **kwargs):
     kwargs["fill_opacity"] = kwargs.get("fill_opacity", 0)
     kwargs["num_anchor_points"] = \
         num_graph_points or self.default_num_graph_points
     graph = ParametricFunction(
         lambda t: self.coords_to_point(t, function(t)),
         t_min=self.x_min,
         t_max=self.x_max,
         **kwargs)
     graph.underlying_function = function
     return graph
コード例 #9
0
    def construct(self):
        point_a, point_b = 3 * LEFT, 3 * RIGHT
        dots = []
        for point, char in [(point_a, "A"), (point_b, "B")]:
            dot = Dot(point)
            letter = TexMobject(char)
            letter.next_to(dot, UP + LEFT)
            dot.add(letter)
            dots.append(dot)

        path = ParametricFunction(lambda t:
                                  (t / 2 + np.cos(t)) * RIGHT + np.sin(t) * UP,
                                  start=-2 * np.pi,
                                  end=2 * np.pi)
        path.scale(6 / (2 * np.pi))
        path.shift(point_a - path.points[0])
        path.highlight(RED)
        line = Line(point_a, point_b)
        words = TextMobject("Shortest path from $A$ to $B$")
        words.to_edge(UP)

        self.play(ShimmerIn(words), *map(GrowFromCenter, dots))
        self.play(ShowCreation(path))
        self.play(Transform(path, line, path_func=path_along_arc(np.pi)))
        self.wait()
コード例 #10
0
ファイル: misc.py プロジェクト: GodotMisogi/manim
    def construct(self):
        point_a, point_b = 3*LEFT, 3*RIGHT
        dots = []
        for point, char in [(point_a, "A"), (point_b, "B")]:
            dot = Dot(point)
            letter = TexMobject(char)
            letter.next_to(dot, UP+LEFT)
            dot.add(letter)
            dots.append(dot)

        path = ParametricFunction(
            lambda t : (t/2 + np.cos(t))*RIGHT + np.sin(t)*UP,
            start = -2*np.pi,
            end = 2*np.pi
        )
        path.scale(6/(2*np.pi))
        path.shift(point_a - path.points[0])
        path.highlight(RED)
        line = Line(point_a, point_b)
        words = TextMobject("Shortest path from $A$ to $B$")
        words.to_edge(UP)

        self.play(
            ShimmerIn(words),
            *map(GrowFromCenter, dots)
        )
        self.play(ShowCreation(path))
        self.play(Transform(
            path, line,
            path_func = path_along_arc(np.pi)
        ))
        self.dither()
コード例 #11
0
ファイル: misc.py プロジェクト: GodotMisogi/manim
    def construct(self):
        t_axis = NumberLine()
        theta_axis = NumberLine().rotate(np.pi/2)
        theta_mob = TexMobject("\\theta(t)")
        t_mob = TexMobject("t")
        theta_mob.next_to(theta_axis, RIGHT)
        theta_mob.to_edge(UP)
        t_mob.next_to(t_axis, UP)
        t_mob.to_edge(RIGHT)
        graph = ParametricFunction(
            lambda t : 4*t*RIGHT + 2*smooth(t)*UP
        )
        line = Line(graph.points[0], graph.points[-1], color = WHITE)
        q_mark = TextMobject("?")
        q_mark.next_to(Point(graph.get_center()), LEFT)
        stars = Stars(color = BLACK)
        stars.scale(0.1).shift(q_mark.get_center())


        squiggle = ParametricFunction(
            lambda t : t*RIGHT + 0.2*t*(5-t)*(np.sin(t)**2)*UP,
            start = 0,
            end = 5
        )

        self.play(
            ShowCreation(t_axis),
            ShowCreation(theta_axis),
            ShimmerIn(theta_mob),
            ShimmerIn(t_mob)
        )
        self.play(
            ShimmerIn(q_mark),
            ShowCreation(graph)
        )
        self.dither()
        self.play(
            Transform(q_mark, stars),
            Transform(graph, line)
        )
        self.dither()
        self.play(Transform(graph, squiggle))
        self.dither()
コード例 #12
0
    def graph_function(
        self,
        func,
        color=BLUE,
        animate=True,
        is_main_graph=True,
    ):
        def parameterized_graph(alpha):
            x = interpolate(self.x_min, self.x_max, alpha)
            return self.coords_to_point(x, func(x))

        graph = ParametricFunction(parameterized_graph, color=color)

        if is_main_graph:
            self.graph = graph
            self.func = func
        if animate:
            self.play(ShowCreation(graph))
        self.add(graph)
        return graph
コード例 #13
0
ファイル: curves.py プロジェクト: GodotMisogi/manim
 def __init__(self, **kwargs):
     digest_config(self, kwargs)
     ParametricFunction.__init__(self, self.pos_func, **kwargs)
コード例 #14
0
 def get_path(self):
     return ParametricFunction(lambda t: t * RIGHT +
                               (np.exp(-(t + 2)**2) - 0.2 * np.exp(t - 2)),
                               start=-4,
                               end=4)
コード例 #15
0
 def get_path(self):
     return ParametricFunction(lambda t: t * RIGHT +
                               (-0.2 * t - np.sin(2 * np.pi * t / 6)) * UP,
                               start=-7,
                               end=10)
コード例 #16
0
 def __init__(self, **kwargs):
     digest_config(self, kwargs)
     ParametricFunction.__init__(self, self.pos_func, **kwargs)