https://docs.manim.community/en/stable/guides/using_text.html
The simplest way to add text to your animations is to use the Text class. It uses the Pango library to render text. With Pango, you can also render non-English alphabets like 你好 or こんにちは or 안녕하세요 or مرحبا بالعالم.
You can also use MarkupText which allows the use of PangoMarkup (see the documentation of MarkupText for details) to render text.
MarkupText is similar to Text, the only difference between them is that this accepts and processes PangoMarkup (which is similar to html), instead of just rendering plain text.
Consult the documentation of MarkupText for more details and further references about PangoMarkup.
The font used must be installed in your system, and Pango should know about it. You can get a list of fonts using manimpango.list_fonts().
import manimpango
manimpango.list_fonts()
['Agency FB', 'Algerian', 'Arial', 'Arial Rounded MT', 'Arial Unicode MS', 'Bahnschrift', 'Baskerville Old Face', 'Bauhaus 93', 'Bell MT', 'Berlin Sans FB', 'Bernard MT', 'Blackadder ITC', 'Bodoni MT', 'Bodoni MT Poster', 'Book Antiqua', 'Bookman Old Style', 'Bradley Hand ITC', 'Britannic', 'Broadway', 'Brush Script MT', 'Calibri', 'Californian FB', 'Calisto MT', 'Cambria', 'Cambria Math', 'Candara', 'Cascadia Code', 'Cascadia Mono', 'Castellar', 'Centaur', 'Century', 'Century Gothic', 'Century Schoolbook', 'Chiller', 'Colonna MT', 'Comic Sans MS', 'Consolas', 'Constantia', 'Cooper', 'Copperplate Gothic', 'Corbel', 'Courier New', 'Curlz MT', 'Cursive', 'DejaVu Sans', 'DejaVu Sans Display', 'DejaVu Sans Mono', 'DejaVu Serif', 'DejaVu Serif Display', 'DengXian', 'Dubai', 'Ebrima', 'Edwardian Script ITC', 'Elephant', 'Engravers MT', 'Eras ITC', 'FZShuTi', 'FZYaoTi', 'FangSong', 'Fantasy', 'Felix Titling', 'Footlight MT', 'Forte', 'Franklin Gothic', 'Franklin Gothic Book', 'Freestyle Script', 'French Script MT', 'Gabriola', 'Gadugi', 'Garamond', 'Georgia', 'Gigi', 'Gill Sans', 'Gill Sans MT', 'Gloucester MT', 'Goudy Old Style', 'Goudy Stout', 'HP Simplified', 'HP Simplified Hans', 'HP Simplified Jpan', 'Haettenschweiler', 'Harlow Solid', 'Harrington', 'High Tower Text', 'Impact', 'Imprint MT Shadow', 'Informal Roman', 'Ink Free', 'Javanese Text', 'Jokerman', 'Juice ITC', 'KaiTi', 'Kristen ITC', 'Kunstler Script', 'Leelawadee', 'Leelawadee UI', 'LiSu', 'Lucida Bright', 'Lucida Calligraphy', 'Lucida Console', 'Lucida Fax', 'Lucida Handwriting', 'Lucida Sans', 'Lucida Sans Typewriter', 'Lucida Sans Unicode', 'MS Gothic', 'MS PGothic', 'MS Reference Sans Serif', 'MS UI Gothic', 'MV Boli', 'Magneto', 'Maiandra GD', 'Malgun Gothic', 'Matura MT Script Capitals', 'Meiryo', 'Meiryo UI', 'Microsoft Himalaya', 'Microsoft JhengHei', 'Microsoft JhengHei UI', 'Microsoft New Tai Lue', 'Microsoft PhagsPa', 'Microsoft Sans Serif', 'Microsoft Tai Le', 'Microsoft Uighur', 'Microsoft YaHei', 'Microsoft YaHei UI', 'Microsoft Yi Baiti', 'MingLiU-ExtB', 'MingLiU_HKSCS-ExtB', 'MingLiU_MSCS-ExtB', 'Mistral', 'Modern No. 20', 'Mongolian Baiti', 'Monospace', 'Monotype Corsiva', 'Myanmar Text', 'NSimSun', 'Niagara Engraved', 'Niagara Solid', 'Nirmala Text', 'Nirmala UI', 'Noto Sans SC', 'Noto Serif SC', 'OCR A', 'Old English Text MT', 'Onyx', 'PMingLiU-ExtB', 'Palace Script MT', 'Palatino Linotype', 'Papyrus', 'Parchment', 'Perpetua', 'Perpetua Titling MT', 'Playbill', 'Poor Richard', 'Pristina', 'Rage', 'Ravie', 'Rockwell', 'STCaiyun', 'STFangsong', 'STHupo', 'STIXGeneral', 'STIXNonUnicode', 'STIXSizeFiveSym', 'STIXSizeFourSym', 'STIXSizeOneSym', 'STIXSizeThreeSym', 'STIXSizeTwoSym', 'STKaiti', 'STLiti', 'STSong', 'STXihei', 'STXingkai', 'STXinwei', 'STZhongsong', 'Sans', 'Sans Serif Collection', 'Sans-Serif', 'Script MT', 'Segoe Print', 'Segoe Script', 'Segoe UI', 'Segoe UI Emoji', 'Segoe UI Historic', 'Segoe UI Symbol', 'Segoe UI Variable Display', 'Segoe UI Variable Small', 'Segoe UI Variable Text', 'Serif', 'Showcard Gothic', 'SimHei', 'SimSun', 'SimSun-ExtB', 'SimSun-ExtG', 'Sitka Banner', 'Sitka Display', 'Sitka Heading', 'Sitka Small', 'Sitka Subheading', 'Sitka Text', 'Snap ITC', 'Stencil', 'Sylfaen', 'System-ui', 'Tahoma', 'Tempus Sans ITC', 'Times New Roman', 'Trebuchet MS', 'Tw Cen MT', 'Ubuntu Mono', 'Verdana', 'Viner Hand ITC', 'Vivaldi', 'Vladimir Script', 'Wide Latin', 'YouYuan', 'Yu Gothic', 'Yu Gothic UI', 'cmb10', 'cmex10', 'cmmi10', 'cmr10', 'cmss10', 'cmsy10', 'cmtt10']
Weight specifies the boldness of a font. You can see a list of weights in manimpango.Weight.
class DifferentWeight(Scene): def construct(self): import manimpango g = VGroup() weight_list = dict( sorted( { weight: manimpango.Weight(weight).value for weight in manimpango.Weight }.items(), key=lambda x: x[1], ) ) for weight in weight_list: g += Text(weight.name, weight=weight.name, font="Sans") self.add(g.arrange(DOWN).scale(0.5))

WHITE = ManimColor("#FFFFFF") GRAY_A = ManimColor("#DDDDDD") GREY_A = ManimColor("#DDDDDD") GRAY_B = ManimColor("#BBBBBB") GREY_B = ManimColor("#BBBBBB") GRAY_C = ManimColor("#888888") GREY_C = ManimColor("#888888") GRAY_D = ManimColor("#444444") GREY_D = ManimColor("#444444") GRAY_E = ManimColor("#222222") GREY_E = ManimColor("#222222") BLACK = ManimColor("#000000") LIGHTER_GRAY = ManimColor("#DDDDDD") LIGHTER_GREY = ManimColor("#DDDDDD") LIGHT_GRAY = ManimColor("#BBBBBB") LIGHT_GREY = ManimColor("#BBBBBB") GRAY = ManimColor("#888888") GREY = ManimColor("#888888") DARK_GRAY = ManimColor("#444444") DARK_GREY = ManimColor("#444444") DARKER_GRAY = ManimColor("#222222") DARKER_GREY = ManimColor("#222222") PURE_RED = ManimColor("#FF0000") PURE_GREEN = ManimColor("#00FF00") PURE_BLUE = ManimColor("#0000FF") PURE_CYAN = ManimColor("#00FFFF") PURE_MAGENTA = ManimColor("#FF00FF") PURE_YELLOW = ManimColor("#FFFF00") BLUE_A = ManimColor("#C7E9F1") BLUE_B = ManimColor("#9CDCEB") BLUE_C = ManimColor("#58C4DD") BLUE_D = ManimColor("#29ABCA") BLUE_E = ManimColor("#236B8E") BLUE = ManimColor("#58C4DD") DARK_BLUE = ManimColor("#236B8E") TEAL_A = ManimColor("#ACEAD7") TEAL_B = ManimColor("#76DDC0") TEAL_C = ManimColor("#5CD0B3") TEAL_D = ManimColor("#55C1A7") TEAL_E = ManimColor("#49A88F") TEAL = ManimColor("#5CD0B3") GREEN_A = ManimColor("#C9E2AE") GREEN_B = ManimColor("#A6CF8C") GREEN_C = ManimColor("#83C167") GREEN_D = ManimColor("#77B05D") GREEN_E = ManimColor("#699C52") GREEN = ManimColor("#83C167") YELLOW_A = ManimColor("#FFF1B6") YELLOW_B = ManimColor("#FFEA94") YELLOW_C = ManimColor("#F7D96F") YELLOW_D = ManimColor("#F4D345") YELLOW_E = ManimColor("#E8C11C") YELLOW = ManimColor("#F7D96F") GOLD_A = ManimColor("#F7C797") GOLD_B = ManimColor("#F9B775") GOLD_C = ManimColor("#F0AC5F") GOLD_D = ManimColor("#E1A158") GOLD_E = ManimColor("#C78D46") GOLD = ManimColor("#F0AC5F") RED_A = ManimColor("#F7A1A3") RED_B = ManimColor("#FF8080") RED_C = ManimColor("#FC6255") RED_D = ManimColor("#E65A4C") RED_E = ManimColor("#CF5044") RED = ManimColor("#FC6255") MAROON_A = ManimColor("#ECABC1") MAROON_B = ManimColor("#EC92AB") MAROON_C = ManimColor("#C55F73") MAROON_D = ManimColor("#A24D61") MAROON_E = ManimColor("#94424F") MAROON = ManimColor("#C55F73") PURPLE_A = ManimColor("#CAA3E8") PURPLE_B = ManimColor("#B189C6") PURPLE_C = ManimColor("#9A72AC") PURPLE_D = ManimColor("#715582") PURPLE_E = ManimColor("#644172") PURPLE = ManimColor("#9A72AC") PINK = ManimColor("#D147BD") LIGHT_PINK = ManimColor("#DC75CD") ORANGE = ManimColor("#FF862F") LIGHT_BROWN = ManimColor("#CD853F") DARK_BROWN = ManimColor("#8B4513") GRAY_BROWN = ManimColor("#736357") GREY_BROWN = ManimColor("#736357") # Colors used for Manim Community's logo and banner LOGO_WHITE = ManimColor("#ECE7E2") LOGO_GREEN = ManimColor("#87C2A5") LOGO_BLUE = ManimColor("#525893") LOGO_RED = ManimColor("#E07A5F") LOGO_BLACK = ManimColor("#343434")
You can use utilities like t2c for coloring specific characters. This may be problematic if your text contains ligatures as explained in Iterating Text.
t2c accepts two types of dictionaries,
-
The keys can contain indices like
[2:-1]or[4:8], this works similar to how slicing works in Python. The values should be the color of the Text fromColor. -
The keys contain words or characters which should be colored separately and the values should be the color from
Color:

class Textt2cExample(Scene): def construct(self): t2cindices = Text('Hello', t2c={'[1:-1]': BLUE}).move_to(LEFT) t2cwords = Text('World',t2c={'rl':RED}).next_to(t2cindices, RIGHT) self.add(t2cindices, t2cwords)
You can add a gradient using gradient. The value must be an iterable of any length:

class GradientExample(Scene): def construct(self): t = Text("Hello", gradient=(RED, BLUE, GREEN), font_size=96) self.add(t)
You can also use t2g for gradients with specific characters of the text. It shares a similar syntax to the interface for colors:

class t2gExample(Scene): def construct(self): t2gindices = Text( 'Hello', t2g={ '[1:-1]': (RED,GREEN), }, ).move_to(LEFT) t2gwords = Text( 'World', t2g={ 'World':(RED,BLUE), }, ).next_to(t2gindices, RIGHT) self.add(t2gindices, t2gwords)

浙公网安备 33010602011771号