본문 바로가기
html5

manim ValueTracker class example

by peach1227 2024. 5. 28.

 

%%manim -qm -v WARNING TangentLineExample

class TangentLineExample(Scene):
    def construct(self):
        self.camera.background_color=WHITE

        number_plane = NumberPlane(
            x_range=[-20,20],y_range=[-5,5],
            x_length=18,y_length=5,
            background_line_style={
                "stroke_color": TEAL,
                "stroke_width": 4,
                "stroke_opacity": 0.6
            }
        ).shift(2*RIGHT)
        circle = Circle(radius=2)
        ellipse = Ellipse(width=4,height=3,color=YELLOW)
        
        line_1 = TangentLine(circle, alpha=0.0, length=4, color=BLUE_D) # right
        line_2 = TangentLine(circle, alpha=0.4, length=4, color=GREEN) # top left
        
        axes= Axes()
        graph=axes.plot(lambda x: np.sin(x),x_range=[0,TAU])
        graph.set_color(BLUE).shift(2*RIGHT)
        
        c=ValueTracker(0)
        line_3=always_redraw(lambda:TangentLine(circle, alpha=c.get_value(), length=4, color=MAROON))
        line_4=always_redraw(lambda:TangentLine(ellipse, alpha=c.get_value(), length=4, color=MAROON))
        line_5=always_redraw(lambda:TangentLine(graph, alpha=c.get_value(), length=4, color=MAROON))

        group=VGroup(number_plane, circle, ellipse, line_1, line_2, line_3, line_4,axes,graph,line_5).shift(2*LEFT)
        self.add(group)
        self.play(c.animate.set_value(1),run_time=4)

반응형

'html5' 카테고리의 다른 글

manim Homotopy  (0) 2024.05.30
manim graph plot :  (0) 2024.05.29
manim linearTransform example  (0) 2024.05.26
manim boolean operation  (0) 2024.05.19
manim TracedPath  (0) 2024.05.19