Mobject 움직이기
manim에서 Object들을 특별히 Mobject라고 그들의 Community에서 명칭 하고 있다.
이전 Tutorial에서 Moject들을 생성하는 것을 배웠는데 이번에는 생성된 Mobject들을 움직이는(animate) 하는 방법을 배워보자
방법은
1. Mobejct의 뒤에 .animate 를 붙이고
2. 적당한 method를 붙여 self.play() 안에 넣으면 된다.
※ 또는 그에 준하는 함수들 ( ex. ReplacementTransform 같은 )을 넣으면 된다.
예를 들어 code를 예시로 들면
circle = Circle() # circle이라는 객체를 생성한다.
self.play(Create(square)) # circle 객체를 생성한다. (여기까지가 Tutorial 2 과정)
self.play(square.animate.rotate(PI / 4)) # 객체를 animate.rotate를 붙여 회전 , 그것을 self.play 에 넣어 실행 시킨다.
Code 예시
init 부분에서 사각형을 형성해놓고 construct 부분에서 생성 / 변형을 이루는 구조이다.
from manim import *
import math
class Tutorial3_Ex1( Scene ):
def __init__(self ):
super().__init__() # 필수적으로 필요하다
self.A = Square()
def construct(self):
self.play(Create(self.A))
self.play(self.A.animate.rotate(PI / 4))
self.wait()
두 가지 Mobject를 동시에 생성 및 변형하는 방법은 self.play 에 comma로 이어서 써주면 된다.
class Tutorial3_Ex1( Scene ):
def __init__(self ):
super().__init__() # 필수적으로 필요하다
self.A = Square()
self.B = Triangle()
self.B.next_to(self.A,RIGHT)
def construct(self):
self.play(Create(self.A),
Create(self.B)
)
self.play(self.A.animate.rotate(PI / 4) ,
self.B.animate.rotate(PI / 4)
)
self.wait()
반응형
'Manim > Tutorial' 카테고리의 다른 글
[manim] Function and Method (0) | 2022.05.29 |
---|---|
[Manim] Tutorial 2 - Object 생성 (0) | 2022.05.25 |
[Manim] Tutorial 1 - manim의 동작 방식 (0) | 2022.05.23 |
Manim 설치 방법 (0) | 2022.04.13 |