이 글에서는 Manim 에서 여러가지 방법을 이용하여 텍스트를 화면에 출력하는 코드 (또는 함수) 몇 가지를 소개하려고 한다. 아래의 코드를 적절히 활용하여 인트로 또는 아웃트로 영상 제작에 응용할 수도 있다.
Write / Unwrite
Manim 에서 가장 기본적인 텍스트 출력 함수는 Write 이다. 그리고 당연히 Unwrite 함수는 Write 함수의 정반대 기능을 한다. 코드 내용부터 살펴보면 아래와 같다.
from manim import *
class HelloWorld(Scene):
def construct(self):
text_en = Text("Hello World!")
self.play(Write(text_en))
self.wait()
self.play(Unwrite(text_en))
self.wait()
지난 글에서도 설명한 바와 같이, 위 코드를 실행하기 위해서는 터미널에서 "manim -pqm text.py HelloWorld" 라는 명령어를 입력하여 실행해야 한다. 여기에서 text.py 는 위 코드가 포함된 파이썬 코드 파일명이고, HelloWorld 는 위 코드의 클래스 이름이다.
Write / Unwrite 함수를 실행한 결과, 생성되는 영상은 다음과 같다.
쓰기 방향 바꾸기 (Reverse)
Write 함수는 기본적인 쓰기 방향이 좌에서 우이며, Unwrite 는 우에서 좌가 기본이다. 이 방향을 반대로 바꾸려면 아래와 같이 reverse 옵션을 추가로 작성해야 한다.
from manim import *
class HelloWorld(Scene):
def construct(self):
text_en = Text("Hello World!")
self.play(Write(text_en), reverse=True)
self.wait()
self.play(Unwrite(text_en), reverse=False)
self.wait()
결과 영상은 아래와 같다.
안녕하세요! (글꼴, 크기 및 두께 설정)
영문 대신 한글 "안녕하세요!" 를 출력하는 Manim 코드는 아래에서 보는 바와 같다. 추가로 글꼴은 Pretendard, 크기는 108, 두껍게로 변경해보았다.
from manim import *
class HelloWorld(Scene):
def construct(self):
text_en = Text("Hello World!")
text_kr = Text("안녕하세요!", font="Pretendard", font_size=108, weight=BOLD)
self.play(Write(text_kr))
self.wait()
결과 영상은 다음과 같다.
FadeIn / FadeOut
페이드 인 (FadeIn) 함수는 검은 화면에서 서서히 밝하지며 개체가 드러나는 기능을 가지며, 페이드 아웃 (FadeOut) 은 페이드 인의 반대 기능을 가진다. 페이드 인/아웃 코드 예제는 아래에서 보는 것과 같다.
from manim import *
class HelloWorld(Scene):
def construct(self):
text_en = Text("Hello World!")
self.play(FadeIn(text_en))
self.wait()
self.play(FadeOut(text_en))
self.wait()
결과 영상은 다음과 같다.
AddTextLetterByLetter / RemoveTextLetterByLetter
AddTextLetterByLetter 코드 또는 함수는 그 이름처럼 텍스트를 화면에 한 글자씩 출력하는 기능을 가진다. RemoveTextLetterByLetter 는 당연히 정반대의 기능을 가지는 코드 또는 함수이다. 아래 코드 예제를 확인하자.
from manim import *
class HelloWorld(Scene):
def construct(self):
text_en = Text("Hello World!")
self.play(AddTextLetterByLetter(text_en))
self.wait()
self.play(RemoveTextLetterByLetter(text_en))
self.wait()
결과 영상은 다음과 같다.
TypeWithCursor / UntypeWithCursor
TypeWithCursor 는 앞에서 소개한 AddTextLetterByLetter 와 뒤에 소개할 Blink 를 응용한 버전이라고 보면 된다. 당연히 UntypeWithCursor 는 TypeWithCursor 의 정반대 기능을 가진다. 예제 코드는 아래와 같다.
from manim import *
class HelloWorld(Scene):
def construct(self):
text_en = Text("Hello World!")
cursor = Rectangle(
color = GREY_A,
fill_color = GREY_A,
fill_opacity = 1.0,
height = 0.7,
width = 0.3,
).move_to(text_en[0]) # Position the cursor
self.play(TypeWithCursor(text_en, cursor))
self.play(Blink(cursor, blinks=2))
self.play(UntypeWithCursor(text_en, cursor))
self.play(Blink(cursor, blinks=2))
결과 영상은 다음과 같다.
ApplyWave
ApplyWave 코드 또는 함수는 텍스트에 파도가 출렁이는 효과를 준다. 아래 코드에서는 총 3가지의 서로 다른 효과가 적용되었다.
from manim import *
class HelloWorld(Scene):
def construct(self):
text_en = Text("Hello World!")
self.play(ApplyWave(text_en))
self.wait()
self.play(ApplyWave(text_en, direction=RIGHT, time_width=0.5, amplitude=0.3))
self.wait()
self.play(ApplyWave(text_en, rate_func=linear, ripples=4))
self.wait()
결과 영상은 다음과 같다.
Blink
Blink 코드 또는 함수는 깜빡이는 효과를 준다. 아래 코드에서는 3번 깜빡이는 옵션을 설정했다.
from manim import *
class HelloWorld(Scene):
def construct(self):
text_en = Text("Hello World!")
self.add(text_en)
self.play(Blink(text_en, blinks=3))
결과 영상은 다음과 같다.
Indicate
Indicate 코드 또는 함수는 강조하고 싶은 텍스트에 사용하면 좋다. 아래 코드 예제를 확인하자.
from manim import *
class HelloWorld(Scene):
def construct(self):
text_en = Text("Hello World!")
self.play(Indicate(text_en))
self.wait()
결과 영상은 다음과 같다.
Wiggle
마지막으로 Wiggle 코드 또는 함수는 "씰룩씰룩 움직이는" 효과를 준다. 아래 코드 예제를 확인하자.
from manim import *
class HelloWorld(Scene):
def construct(self):
text_en = Text("Hello World!")
self.play(Wiggle(text_en))
self.wait()
결과 영상은 다음과 같다.
댓글 (Comments)