manim边学边做--点

几何图形是manim中最重要的一类模块,manim内置了丰富的各类几何图形,

本篇从最简单的 开始,逐个介绍manim中的几何模块。

manim中点相关的模块主要有3个:

  1. Dot:通用的点
  2. LabeledDot:在点的中间可以加一些说明文字
  3. AnnotationDot:使用在注释场景中的点


Dot系列在manim各个模块中的位置大致如上图中所示。

1. 主要参数

比较简单,所以参数不多,主要就是控制点的大小,颜色,透明度等等属性。
Dot对象:

参数名称 类型 说明
point float,float,float 点的坐标
radius float 点的半径
stroke_width float 边框厚度
fill_opacity float 透明度
color str 颜色

LabeledDot对象,继承自Dot对象,包含Dot的属性,此外还有:

参数名称 类型 说明
label str 点中的文本内容

AnnotationDot对象,继承自Dot对象,包含Dot的属性,此外还有:

参数名称 类型 说明
stroke_color str 外框颜色
fill_color str 内部的颜色

2. 使用示例

这三种 对象中,使用最多的Dot对象,下面通过一些示例演示点的使用。

2.1. 大小

调节 的大小主要就是调节点的半径radius

python 复制代码
d1 = Dot(radius=0.04)
d2 = Dot() # 默认点半径
d3 = Dot(radius=0.24)
d4 = Dot(radius=0.32)
d5 = Dot(radius=0.64)

2.2. 颜色

color属性可以设置颜色。

python 复制代码
d1 = Dot(color=RED)
d2 = Dot(color=GREEN)
d3 = Dot(color=BLUE)
d4 = Dot(color=YELLOW)
d5 = Dot(color=PURPLE)

2.3. 标签

中带标签,需要使用LabeledDot对象,它的label属性除了可以显示字母和数字之外,

还可以显示中文和数学公式。

python 复制代码
d1 = LabeledDot(
    label=Text("中文", font_size=20),
)
d2 = LabeledDot(label="a^2")
d3 = LabeledDot(label="32")
d4 = LabeledDot(label="V_i")


label属性不能直接输入中文,需要通过Text对象来输入中文;

输入公式的话,只要输入Latex格式的字符串即可,输出时会被渲染成公式。

2.4. 边框和内部

AnnotationDot对象是用来在视频中加注释和标注的,它将点分为边框内部 两部分,

边框可以设置粗细,而且这两部分还可以分别设置不同的颜色。

python 复制代码
d1 = AnnotationDot(
    stroke_width=2,
    stroke_color=RED,
    fill_color=GREEN,
)
d2 = AnnotationDot(
    stroke_width=10,
    stroke_color=BLUE,
    fill_color=YELLOW,
)
d3 = AnnotationDot(
    stroke_width=20,
    stroke_color=YELLOW,
    fill_color=RED,
)
d4 = AnnotationDot(
    stroke_width=40,
    stroke_color=GREEN,
    fill_color=PURPLE,
)


stroke_width属性设置外框 的粗细,stroke_color属性设置外框的颜色,fill_color设置内部的颜色。

3. 附件

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

下载地址: 完整代码 (访问密码: 6872)

相关推荐
Python私教11 小时前
Django 6.1 RC1 实测:FETCH_PEERS 两条 SQL 解决 N+1,select_related 还需要吗?
后端·python·django
玉鸯12 小时前
Agent 的任务编排:从 System Prompt 到 Hierarchical Multi-Agent
python·llm·agent
Python私教12 小时前
Django 6.0 自带 Tasks 到底能不能替代 Celery?跑完 3 组后台任务后我有答案了
后端·python·django
我的xiaodoujiao12 小时前
快速学习Python基础知识详细图文教程14--模块
开发语言·python·学习·测试工具
残影飞雪12 小时前
Ollama对话脚本
python
jerryinwuhan12 小时前
数据预处理技术 2026-2027-1 开篇-课程介绍
大数据·python
看昭奚恤哭12 小时前
ontainer App】Container App无法从Container Registries 拉取镜像 - 报错 Forbidden
后端·python·flask
05664612 小时前
Python康复训练——数据结构
数据结构·windows·python
Tinyfacture12 小时前
接口自动化之添加商品(pytest)
python·测试工具·自动化·pytest
听雨入夜13 小时前
“同声传译”还是“全文翻译”?为何HotSpot虚拟机仍要保留解释器?
开发语言·python