manim边学边做--Title

Title比较简单,是Mobjects分类中专门用来标题的一个class

其实Title主要就是文字和线两部分,自己封装也不难。

不过,直接用Title可以省去调整位置的麻烦,它会确保标题显示在视频的顶端。

Titlemanim各个模块中的位置如上图中所示。

主要参数

Title的目的很简单,就是为了显示标题,主要参数有:

参数名称 类型 说明
text_parts list 标题的内容,支持latex格式
include_underline bool 是否包含下划线
match_underline_width_to_text bool 下划线长度是否与文字匹配
underline_buff float 下划线与文字的间隔

其中最重要的是text_parts参数,它是设置标题内容的部分。

使用示例

下面通过示例看看Title如何使用的。

文字标题

Title类的text_parts参数可以传入一个或多个字符串,也可以用变量。

python 复制代码
# 一个字符串
t = Title("how to learn manim?")

# 两个字符串,其中一个是当前时间
now = datetime.now().strftime("%H:%M:%S")
t = Title("now: ", now)

标题中带公式

除了文字和变量,标题中也可以带有数学公式。

python 复制代码
t = Title("$x^2 + y^2 = z^2$")
t = Title("$\int_a^b f'(x) dx = f(b)- f(a)$")

标题和线

Title类中除了text_parts参数之外,其他几个参数都是用来调节文字和下划线之间的关系的。

python 复制代码
# 不显示下划线
t = Title("without underline", include_underline=False)

# 下划线长度匹配文字长度
t = Title("short title", match_underline_width_to_text=True)
t = Title("longlonglonglong title", match_underline_width_to_text=True)

# 下划线和文字之间的间隔
t = Title("large buffer from underline", underline_buff=1)

附件

文中完整的代码放在网盘中了(title.py),

下载地址: 示例代码 (访问密码: 6872)

相关推荐
free-elcmacom7 小时前
深度学习<4>高效模型架构与优化器的“效率革命”
人工智能·python·深度学习·机器学习·架构
liliangcsdn7 小时前
python模拟beam search优化LLM输出过程
人工智能·python
王琦03188 小时前
Python 函数详解
开发语言·python
胡伯来了8 小时前
13. Python打包工具- setuptools
开发语言·python
小鸡吃米…8 小时前
Python 中的多层继承
开发语言·python
中國移动丶移不动9 小时前
Python MySQL 数据库操作完整示例
数据库·python·mysql
落叶,听雪9 小时前
AI建站推荐
大数据·人工智能·python
ZAz_9 小时前
DAY 45 预训练模型
python
呆萌很9 小时前
python 项目迁移
python
清水白石0089 小时前
《requests vs httpx:Python 网络请求库的全面对比与实战指南》
网络·python·httpx