승상의 코딩 블로그
[Manim] 기본 구조 파악하고 텍스트 애니메이션 적용하기 본문
2025.01.30 - [Python (파이썬)/Manim] - Manim 으로 수학 애니메이션 만들기 - 설치
Manim 으로 수학 애니메이션 만들기 - 설치
https://www.youtube.com/@3blue1brown 3Blue1BrownMy name is Grant Sanderson. Videos here cover a variety of topics in math, or adjacent fields like physics and CS, all with an emphasis on visualizing the core ideas. The goal is to use animation to help elu
seungsang.tistory.com
설치랑 실행방법은 위 포스팅에서 보고 오길바란다.
기본 구조
from manim import * | |
class HelloWorldScene(Scene): | |
def construct(self): | |
hello_world_text = Text("Hello World",font_size=72) | |
self.add(hello_world_text) |
manim 안의 Scene 을 상속한 클래스는 하나의 장면으로 실행될 수 있다.
Scene 을 상속받아 construct 를 구현하게 되면, construct 안의 내용이 실질적으로 수행된다.
self.add (Scene에서 상속받은 함수) 를 통해 화면에 글자를 그릴수 있다.
조금 더 자세히 알아보자
글자 추가
글자 속성

from manim import * | |
class HelloWorldScene(Scene): | |
def construct(self): | |
hello_world_text = Text("Hello World",font_size=72) # 폰트크기: 72 | |
hello_world_text_red = Text("Hello World",font_size=72, color=RED) # 폰트크기: 72, 색상: 빨강 | |
hello_world_text_red.next_to(hello_world_text,DOWN) # 위치 조정 | |
hello_world_text_each_red = Text("Hello World",font_size=72, t2c={"[:2]":"#FF0000"}) | |
# 폰트크기: 72, t2c : 글자의 색상정의. 키로 배열표기로 원하는 글자선택, 값으로 색상값 정의 | |
hello_world_text_each_red.next_to(hello_world_text_red,DOWN) # 위치 조정 | |
self.add(hello_world_text,hello_world_text_red,hello_world_text_each_red) |
next_to를 사용하면 원하는 객체를 특정 객체의 상대적인 위치로 이동시킬수 있다.
self.add vs self.play

from manim import * | |
class HelloWorldScene(Scene): | |
def construct(self): | |
hello_world_text_static = Text("Hello World Static",font_size=72) | |
hello_world_text_dynamic = Text("Hello World Dynamic",font_size=72) | |
hello_world_text_dynamic.next_to(hello_world_text_static,DOWN) # 위치 조정 | |
self.add(hello_world_text_static) # 정적인 텍스트 | |
self.play(Create(hello_world_text_dynamic)) # 동적인 텍스트 |
self.play 를 통해 텍스트에 애니메이션을 넣을 수 있다.
원하는 애니메이션 객체에 텍스트를 주입하면 된다.
Transform
위에서 사용한 Create 를 Transform 으로 변경하면 다른 애니메이션 효과를 줄 수 있다.
하나의 글자를 다른 글자로 변경할 수 있다.

from manim import * | |
class HelloWorldScene(Scene): | |
def construct(self): | |
hello_world_text_static = Text("Hello World Static",font_size=72) | |
hello_world_text_dynamic = Text("Hello World Dynamic",font_size=72) | |
hello_world_text_dynamic.next_to(hello_world_text_static,DOWN) # 위치 조정 | |
self.add(hello_world_text_static) # 정적인 텍스트 | |
self.play(Transform(hello_world_text_static,hello_world_text_dynamic)) # 텍스트 간 변환 |
참고.
추가로. VGroup 을 사용하면 여러 객체를 하나의 객체처럼 다룰 수 있다.
(위 포스팅엔 간단히 할려고 next_to 를 사용했는데, 중심이 약간 아래로 내려와 있다.)

from manim import * | |
class HelloWorldScene(Scene): | |
def construct(self): | |
hello_world_text = Text("Hello World",font_size=72) # 폰트크기: 72 | |
hello_world_text_red = Text("Hello World",font_size=72, color=RED) # 폰트크기: 72, 색상: 빨강 | |
hello_world_text_each_red = Text("Hello World",font_size=72, t2c={"[:2]":"#FF0000"}) | |
# 폰트크기: 72, t2c : 글자의 색상정의. 키로 배열표기로 원하는 글자선택, 값으로 색상값 정의 | |
group = VGroup(hello_world_text,hello_world_text_red,hello_world_text_each_red) | |
# 글자를 그룹핑 | |
group.arrange(DOWN) # 그룹된 객체를 아래방향으로 정렬 | |
self.add(group) |
'Python (파이썬) > Manim' 카테고리의 다른 글
[Manim] VGroup으로 Manim 애니메이션을 더 쉽게 만들기 (0) | 2025.02.01 |
---|---|
[Manim] 도형이동하면서 애니메이션 효과주기 (0) | 2025.02.01 |
[Manim] 좌표 이해하고 도형 생성 & 이동시키기 (0) | 2025.01.30 |
Manim 으로 수학 애니메이션 만들기 - 설치 (0) | 2025.01.30 |