본문 바로가기

Programming/Manim code

[48]always_redraw

반응형
class AlwaysRedraw(Scene):
    def construct(self):
        self.draw_tangent()

    def draw_tangent(self):
        x_axis = NumberLine(x_min=-5,x_max=5)

        def sine_func(x):
            return 1.5 * np.sin(x * PI)

        graph = FunctionGraph(sine_func, x_min=-4, x_max=4)

        tracker = ValueTracker(-4)

        def get_tangent_line():
            line = Line(
                ORIGIN, 2 * RIGHT,
                color=RED,
                stroke_width=5,
            )
            dx = 0.0001

            x = tracker.get_value()
            p0 = np.array([x-dx,sine_func(x-dx),0])
            p1 = np.array([x, sine_func(x), 0])
            p2 = np.array([x + dx, sine_func(x + dx), 0])

            angle = angle_of_vector(p2 - p1)
            line.rotate(angle)
            line.move_to(p0)
            return line

        line = always_redraw(get_tangent_line)

        self.add(x_axis,graph,line)
        self.play(tracker.set_value, 4, rate_func=smooth, run_time=8)
        self.wait()

 

 

 

반응형

'Programming > Manim code' 카테고리의 다른 글

Sine-curve by rotating dot around the circle  (0) 2020.09.19
[49] Update Animation class  (0) 2020.05.29
[47] add_updater  (0) 2020.05.29
[46]Mobject moving/coloring Animation  (0) 2020.05.29
[45]Special Effects  (0) 2020.05.29