티스토리 뷰

1일 1마님 시리즈는 마님 documentation에 존재하는 예제 코드를 하루에 하나씩 따라하면서 마님 라이브러리 사용에 익숙해지기 위해 만든 시리즈입니다! 많은 시간을 들이기엔 주인장도 대학원생인지라 부담이 돼서 1일 1마님 시리즈는 간단하게 코드 + 코드 리뷰 + 실행 결과만 작성합니다!

class GraphingMovement(Scene): # Scene class 상속
    def construct(self):
        # Axes class를 이용해서 좌표계 형성
        # axis_config 옵션을 이용해서 다양한 옵션 설정 가능
        axes = Axes(x_range=[0,5,1], y_range=[0,3,1],
                    x_length=5, y_length=3,
                    axis_config={"include_tip":True}).add_coordinates()
        axes.to_edge(UR)
        
        # 좌표계의 x축과 y축에 labeling
        axis_label = axes.get_axis_labels(x_label = 'x', y_label= 'f(x)')
        
        # 좌표계에 그릴 graph 생성 (.plot)
        graph = axes.plot(lambda x : x **0.5, x_range=[0,4], color=YELLOW)
        Graphing_stuff = VGroup(axes, axis_label, graph)

        self.play(DrawBorderThenFill(axes), Write(axis_label))
        self.play(Create(graph))
        self.wait(2)

        self.play(Graphing_stuff.animate.shift(DOWN*4))
        self.play(axes.animate.shift(LEFT*3), run_time=3)
        self.wait(3)
  • Axes class를 불러와서 좌표계를 형성, 다양한 옵션 줄 수 있음 옵션은 다음 참고
  • https://docs.manim.community/en/stable/reference/manim.mobject.graphing.coordinate_systems.Axes.html?highlight=axes
  • 좌표축에 get_axis_labels를 이용해 labeling 가능
  • 형성된 좌표계 위에 그래프를 그리려면 좌표계를 저장한 변수(axes)에 .plot 함수를 이용함
  • 그릴 함수는 lambda 기능을 이용해서 만들어주면 됨
  • VGroup은 만들어진 Mobjects들을 하나의 Group으로 묶어주는 역할
  • 묶었다고 반드시 함께 움직여야 하는 것은 아니고 함께 움직일 수도 있고, 따로 움직일수도 있음
  • 특정 My_mobject를 따로 animate할때는 My_mobject.animate 기능을 이용하면 됨 아래 참고
  • https://docs.manim.community/en/stable/reference/manim.mobject.mobject.Mobject.html#manim.mobject.mobject.Mobject.animate

실행 결과

댓글