manim-mcp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -0
- package/dist/demo.mp4 +0 -0
- package/dist/index.js +65 -0
- package/dist/mcp-app.html +142 -0
- package/dist/server.js +1492 -0
- package/package.json +67 -0
- package/references/composer/SKILL.md +154 -0
- package/references/composer/references/3b1b-series-patterns.md +217 -0
- package/references/composer/references/domain-planning-guides/calculus-planning.md +188 -0
- package/references/composer/references/domain-planning-guides/linear-algebra-planning.md +169 -0
- package/references/composer/references/domain-planning-guides/ml-planning.md +286 -0
- package/references/composer/references/domain-planning-guides/number-theory-planning.md +187 -0
- package/references/composer/references/domain-planning-guides/physics-planning.md +249 -0
- package/references/composer/references/domain-planning-guides/probability-planning.md +200 -0
- package/references/composer/references/mathematical-storytelling.md +359 -0
- package/references/composer/references/narrative-patterns.md +221 -0
- package/references/composer/references/opening-patterns.md +284 -0
- package/references/composer/references/pacing-guide.md +289 -0
- package/references/composer/references/scene-archetypes.md +534 -0
- package/references/composer/references/scene-examples.md +379 -0
- package/references/composer/references/visual-techniques.md +480 -0
- package/references/composer/templates/scenes-template.md +147 -0
- package/references/manimce/SKILL.md +166 -0
- package/references/manimce/examples/3d_visualization.py +373 -0
- package/references/manimce/examples/basic_animations.py +212 -0
- package/references/manimce/examples/graph_plotting.py +401 -0
- package/references/manimce/examples/lorenz_attractor.py +172 -0
- package/references/manimce/examples/math_visualization.py +315 -0
- package/references/manimce/examples/updater_patterns.py +369 -0
- package/references/manimce/rules/3b1b-translation.md +594 -0
- package/references/manimce/rules/3d.md +254 -0
- package/references/manimce/rules/advanced-animations.md +594 -0
- package/references/manimce/rules/animation-groups.md +212 -0
- package/references/manimce/rules/animations.md +128 -0
- package/references/manimce/rules/api-pitfalls.md +89 -0
- package/references/manimce/rules/axes.md +214 -0
- package/references/manimce/rules/camera.md +208 -0
- package/references/manimce/rules/cli.md +232 -0
- package/references/manimce/rules/color-conventions.md +444 -0
- package/references/manimce/rules/colors.md +199 -0
- package/references/manimce/rules/config.md +264 -0
- package/references/manimce/rules/creation-animations.md +158 -0
- package/references/manimce/rules/graphing.md +233 -0
- package/references/manimce/rules/grouping.md +220 -0
- package/references/manimce/rules/latex.md +202 -0
- package/references/manimce/rules/lines.md +241 -0
- package/references/manimce/rules/long-form-video.md +552 -0
- package/references/manimce/rules/mathematical-domains.md +689 -0
- package/references/manimce/rules/mobjects.md +116 -0
- package/references/manimce/rules/multi-scene-composition.md +112 -0
- package/references/manimce/rules/pedagogy.md +532 -0
- package/references/manimce/rules/physics-simulations.md +610 -0
- package/references/manimce/rules/positioning.md +211 -0
- package/references/manimce/rules/scenes.md +121 -0
- package/references/manimce/rules/shapes.md +300 -0
- package/references/manimce/rules/styling.md +177 -0
- package/references/manimce/rules/text-animations.md +222 -0
- package/references/manimce/rules/text.md +189 -0
- package/references/manimce/rules/timing.md +227 -0
- package/references/manimce/rules/transform-animations.md +157 -0
- package/references/manimce/rules/updaters.md +226 -0
- package/references/manimce/templates/basic_scene.py +64 -0
- package/references/manimce/templates/camera_scene.py +100 -0
- package/references/manimce/templates/threed_scene.py +138 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: grouping
|
|
3
|
+
description: VGroup, Group, arrange, and layout patterns
|
|
4
|
+
metadata:
|
|
5
|
+
tags: vgroup, group, arrange, layout, grid, submobjects
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Grouping Mobjects
|
|
9
|
+
|
|
10
|
+
Organize multiple mobjects into groups for collective manipulation.
|
|
11
|
+
|
|
12
|
+
## VGroup
|
|
13
|
+
|
|
14
|
+
VGroup (Vectorized Group) is for grouping VMobjects. Most commonly used.
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
from manim import *
|
|
18
|
+
|
|
19
|
+
class VGroupExample(Scene):
|
|
20
|
+
def construct(self):
|
|
21
|
+
# Create a group
|
|
22
|
+
group = VGroup(
|
|
23
|
+
Circle(),
|
|
24
|
+
Square(),
|
|
25
|
+
Triangle()
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
# Operations apply to all members
|
|
29
|
+
group.set_color(RED)
|
|
30
|
+
group.shift(UP)
|
|
31
|
+
|
|
32
|
+
self.add(group)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Group
|
|
36
|
+
|
|
37
|
+
Group is for mixing different mobject types (VMobjects, ImageMobjects, etc.).
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
class GroupExample(Scene):
|
|
41
|
+
def construct(self):
|
|
42
|
+
# Mix different types
|
|
43
|
+
text = Text("Hello")
|
|
44
|
+
group = Group(
|
|
45
|
+
Circle(),
|
|
46
|
+
text
|
|
47
|
+
)
|
|
48
|
+
self.add(group)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Creating Groups
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
# From individual mobjects
|
|
55
|
+
group = VGroup(circle, square, triangle)
|
|
56
|
+
|
|
57
|
+
# From a list
|
|
58
|
+
shapes = [Circle(), Square(), Triangle()]
|
|
59
|
+
group = VGroup(*shapes)
|
|
60
|
+
|
|
61
|
+
# Using list comprehension
|
|
62
|
+
group = VGroup(*[Circle() for _ in range(5)])
|
|
63
|
+
|
|
64
|
+
# Empty group, add later
|
|
65
|
+
group = VGroup()
|
|
66
|
+
group.add(Circle())
|
|
67
|
+
group.add(Square())
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## arrange
|
|
71
|
+
|
|
72
|
+
Arrange mobjects in a line.
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
class ArrangeExample(Scene):
|
|
76
|
+
def construct(self):
|
|
77
|
+
# Horizontal arrangement (default)
|
|
78
|
+
row = VGroup(*[Circle().scale(0.3) for _ in range(5)])
|
|
79
|
+
row.arrange(RIGHT, buff=0.5).shift(UP * 2)
|
|
80
|
+
|
|
81
|
+
# Vertical arrangement
|
|
82
|
+
column = VGroup(*[Square().scale(0.3) for _ in range(4)])
|
|
83
|
+
column.arrange(DOWN, buff=0.5).shift(LEFT * 2)
|
|
84
|
+
|
|
85
|
+
# With custom buffer
|
|
86
|
+
spaced = VGroup(*[Triangle().scale(0.3) for _ in range(3)])
|
|
87
|
+
spaced.arrange(RIGHT, buff=1).shift(DOWN * 2)
|
|
88
|
+
|
|
89
|
+
self.add(row, column, spaced)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Direction Options
|
|
93
|
+
```python
|
|
94
|
+
group.arrange(RIGHT) # Left to right
|
|
95
|
+
group.arrange(LEFT) # Right to left
|
|
96
|
+
group.arrange(UP) # Bottom to top
|
|
97
|
+
group.arrange(DOWN) # Top to bottom
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## arrange_in_grid
|
|
101
|
+
|
|
102
|
+
Arrange in a grid pattern.
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
class GridExample(Scene):
|
|
106
|
+
def construct(self):
|
|
107
|
+
# Auto grid
|
|
108
|
+
grid = VGroup(*[Square().scale(0.3) for _ in range(20)])
|
|
109
|
+
grid.arrange_in_grid()
|
|
110
|
+
|
|
111
|
+
# Specify rows and columns
|
|
112
|
+
grid = VGroup(*[Circle().scale(0.2) for _ in range(12)])
|
|
113
|
+
grid.arrange_in_grid(rows=3, cols=4)
|
|
114
|
+
|
|
115
|
+
# With spacing
|
|
116
|
+
grid.arrange_in_grid(rows=3, cols=4, buff=0.5)
|
|
117
|
+
|
|
118
|
+
self.add(grid)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Accessing Group Members
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
group = VGroup(Circle(), Square(), Triangle())
|
|
125
|
+
|
|
126
|
+
# By index
|
|
127
|
+
first = group[0] # Circle
|
|
128
|
+
second = group[1] # Square
|
|
129
|
+
last = group[-1] # Triangle
|
|
130
|
+
|
|
131
|
+
# Slicing
|
|
132
|
+
first_two = group[0:2] # VGroup with Circle and Square
|
|
133
|
+
|
|
134
|
+
# Iteration
|
|
135
|
+
for mob in group:
|
|
136
|
+
mob.set_color(random_color())
|
|
137
|
+
|
|
138
|
+
# Length
|
|
139
|
+
num_items = len(group)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Modifying Groups
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
group = VGroup(Circle(), Square())
|
|
146
|
+
|
|
147
|
+
# Add mobjects
|
|
148
|
+
group.add(Triangle())
|
|
149
|
+
group.add(Star(), Pentagon())
|
|
150
|
+
|
|
151
|
+
# Remove mobjects
|
|
152
|
+
group.remove(circle)
|
|
153
|
+
|
|
154
|
+
# Insert at position
|
|
155
|
+
group.insert(0, new_mobject)
|
|
156
|
+
|
|
157
|
+
# Submobjects list
|
|
158
|
+
group.submobjects # List of all children
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Group Transformations
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
group = VGroup(Circle(), Square(), Triangle()).arrange(RIGHT)
|
|
165
|
+
|
|
166
|
+
# All transformations apply to entire group
|
|
167
|
+
group.shift(UP * 2)
|
|
168
|
+
group.scale(0.5)
|
|
169
|
+
group.rotate(PI / 4)
|
|
170
|
+
group.set_color(BLUE)
|
|
171
|
+
|
|
172
|
+
# But can target individuals
|
|
173
|
+
group[0].set_color(RED) # Just the circle
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Nested Groups
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
class NestedGroups(Scene):
|
|
180
|
+
def construct(self):
|
|
181
|
+
# Create sub-groups
|
|
182
|
+
row1 = VGroup(*[Circle() for _ in range(3)]).arrange(RIGHT)
|
|
183
|
+
row2 = VGroup(*[Square() for _ in range(3)]).arrange(RIGHT)
|
|
184
|
+
row3 = VGroup(*[Triangle() for _ in range(3)]).arrange(RIGHT)
|
|
185
|
+
|
|
186
|
+
# Group of groups
|
|
187
|
+
all_rows = VGroup(row1, row2, row3).arrange(DOWN)
|
|
188
|
+
|
|
189
|
+
self.add(all_rows)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Useful Group Methods
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
group = VGroup(Circle(), Square(), Triangle())
|
|
196
|
+
|
|
197
|
+
# Get bounding box info
|
|
198
|
+
group.get_center()
|
|
199
|
+
group.get_width()
|
|
200
|
+
group.get_height()
|
|
201
|
+
|
|
202
|
+
# Set position for whole group
|
|
203
|
+
group.move_to(ORIGIN)
|
|
204
|
+
group.to_edge(LEFT)
|
|
205
|
+
|
|
206
|
+
# Copy entire group
|
|
207
|
+
group_copy = group.copy()
|
|
208
|
+
|
|
209
|
+
# Match layout of another group
|
|
210
|
+
group1.match_height(group2)
|
|
211
|
+
group1.match_width(group2)
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Best Practices
|
|
215
|
+
|
|
216
|
+
1. **Use VGroup for VMobjects** - Better performance and compatibility
|
|
217
|
+
2. **Use arrange after creating** - Don't position individually then group
|
|
218
|
+
3. **Name your groups semantically** - `equation_parts` not `group1`
|
|
219
|
+
4. **Use nested groups for structure** - Rows within columns, etc.
|
|
220
|
+
5. **Copy groups when needed** - Avoid unintended modifications
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: latex
|
|
3
|
+
description: MathTex, Tex, LaTeX rendering and equation styling in Manim
|
|
4
|
+
metadata:
|
|
5
|
+
tags: latex, mathtex, tex, equation, formula, math
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# LaTeX in Manim
|
|
9
|
+
|
|
10
|
+
Manim uses LaTeX to render mathematical expressions and formatted text.
|
|
11
|
+
|
|
12
|
+
## MathTex vs Tex
|
|
13
|
+
|
|
14
|
+
- **MathTex**: Automatically wraps content in math mode (`align*` environment)
|
|
15
|
+
- **Tex**: Raw LaTeX - you control the mode
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from manim import *
|
|
19
|
+
|
|
20
|
+
class LaTeXComparison(Scene):
|
|
21
|
+
def construct(self):
|
|
22
|
+
# MathTex - auto math mode
|
|
23
|
+
math = MathTex(r"E = mc^2")
|
|
24
|
+
|
|
25
|
+
# Tex - need explicit math delimiters
|
|
26
|
+
tex = Tex(r"$E = mc^2$")
|
|
27
|
+
|
|
28
|
+
# Both render the same
|
|
29
|
+
VGroup(math, tex).arrange(DOWN)
|
|
30
|
+
self.add(math, tex)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Basic MathTex
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
class MathTexExample(Scene):
|
|
37
|
+
def construct(self):
|
|
38
|
+
# Simple equation
|
|
39
|
+
eq1 = MathTex(r"x^2 + y^2 = z^2")
|
|
40
|
+
|
|
41
|
+
# Fractions
|
|
42
|
+
eq2 = MathTex(r"\frac{a}{b}")
|
|
43
|
+
|
|
44
|
+
# Square roots
|
|
45
|
+
eq3 = MathTex(r"\sqrt{2}")
|
|
46
|
+
|
|
47
|
+
# Greek letters
|
|
48
|
+
eq4 = MathTex(r"\alpha + \beta = \gamma")
|
|
49
|
+
|
|
50
|
+
# Integrals
|
|
51
|
+
eq5 = MathTex(r"\int_0^\infty e^{-x} dx")
|
|
52
|
+
|
|
53
|
+
# Summations
|
|
54
|
+
eq6 = MathTex(r"\sum_{n=1}^{\infty} \frac{1}{n^2}")
|
|
55
|
+
|
|
56
|
+
equations = VGroup(eq1, eq2, eq3, eq4, eq5, eq6).arrange_in_grid(2, 3)
|
|
57
|
+
self.add(equations)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Coloring Parts of Equations
|
|
61
|
+
|
|
62
|
+
### Using set_color_by_tex
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
class ColoredEquation(Scene):
|
|
66
|
+
def construct(self):
|
|
67
|
+
eq = MathTex(r"e^{i\pi} + 1 = 0")
|
|
68
|
+
eq.set_color_by_tex("e", RED)
|
|
69
|
+
eq.set_color_by_tex(r"\pi", BLUE)
|
|
70
|
+
eq.set_color_by_tex("i", GREEN)
|
|
71
|
+
self.add(eq)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Using substrings_to_isolate
|
|
75
|
+
|
|
76
|
+
For precise coloring, isolate substrings first:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
class IsolatedColoring(Scene):
|
|
80
|
+
def construct(self):
|
|
81
|
+
eq = MathTex(
|
|
82
|
+
r"e^x = x^0 + x^1 + \frac{1}{2}x^2 + \cdots",
|
|
83
|
+
substrings_to_isolate=["x"]
|
|
84
|
+
)
|
|
85
|
+
eq.set_color_by_tex("x", YELLOW)
|
|
86
|
+
self.add(eq)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Using index_labels for debugging
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
class DebugLabels(Scene):
|
|
93
|
+
def construct(self):
|
|
94
|
+
eq = MathTex(r"\frac{a}{b}")
|
|
95
|
+
# Add index labels to see which index is which part
|
|
96
|
+
self.add(index_labels(eq[0]))
|
|
97
|
+
self.add(eq)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Direct indexing
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
eq = MathTex(r"a + b = c")
|
|
104
|
+
eq[0][0].set_color(RED) # 'a'
|
|
105
|
+
eq[0][2].set_color(BLUE) # 'b'
|
|
106
|
+
eq[0][4].set_color(GREEN) # 'c'
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Multi-part Equations
|
|
110
|
+
|
|
111
|
+
Split equations into parts for individual control:
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
class MultiPartEquation(Scene):
|
|
115
|
+
def construct(self):
|
|
116
|
+
eq = MathTex("a", "^2", "+", "b", "^2", "=", "c", "^2")
|
|
117
|
+
|
|
118
|
+
eq[0].set_color(RED) # a
|
|
119
|
+
eq[3].set_color(BLUE) # b
|
|
120
|
+
eq[6].set_color(GREEN) # c
|
|
121
|
+
|
|
122
|
+
self.play(Write(eq))
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Text with Math (Tex)
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
class MixedContent(Scene):
|
|
129
|
+
def construct(self):
|
|
130
|
+
# Mix text and math
|
|
131
|
+
tex = Tex(r"The area is $A = \pi r^2$")
|
|
132
|
+
self.play(Write(tex))
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Custom LaTeX Packages
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
class CustomPackage(Scene):
|
|
139
|
+
def construct(self):
|
|
140
|
+
template = TexTemplate()
|
|
141
|
+
template.add_to_preamble(r"\usepackage{mathrsfs}")
|
|
142
|
+
|
|
143
|
+
eq = Tex(
|
|
144
|
+
r"$\mathscr{L}$",
|
|
145
|
+
tex_template=template
|
|
146
|
+
)
|
|
147
|
+
self.add(eq)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Equation Alignment
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
class AlignedEquations(Scene):
|
|
154
|
+
def construct(self):
|
|
155
|
+
eqs = MathTex(
|
|
156
|
+
r"a &= b + c \\",
|
|
157
|
+
r"d &= e + f + g \\",
|
|
158
|
+
r"h &= i"
|
|
159
|
+
)
|
|
160
|
+
self.add(eqs)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Common LaTeX Symbols
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
# Greek letters
|
|
167
|
+
MathTex(r"\alpha \beta \gamma \delta \epsilon")
|
|
168
|
+
MathTex(r"\Gamma \Delta \Theta \Lambda \Pi")
|
|
169
|
+
|
|
170
|
+
# Operators
|
|
171
|
+
MathTex(r"\times \div \pm \mp \cdot")
|
|
172
|
+
|
|
173
|
+
# Relations
|
|
174
|
+
MathTex(r"\leq \geq \neq \approx \equiv")
|
|
175
|
+
|
|
176
|
+
# Arrows
|
|
177
|
+
MathTex(r"\rightarrow \leftarrow \Rightarrow \Leftrightarrow")
|
|
178
|
+
|
|
179
|
+
# Sets
|
|
180
|
+
MathTex(r"\in \notin \subset \supset \cup \cap")
|
|
181
|
+
|
|
182
|
+
# Calculus
|
|
183
|
+
MathTex(r"\int \iint \oint \partial \nabla")
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Font Size
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
# Using font_size parameter
|
|
190
|
+
eq = MathTex(r"E = mc^2", font_size=72)
|
|
191
|
+
|
|
192
|
+
# Using scale
|
|
193
|
+
eq = MathTex(r"E = mc^2").scale(2)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Best Practices
|
|
197
|
+
|
|
198
|
+
1. **Use raw strings** - Always use `r"..."` for LaTeX
|
|
199
|
+
2. **Use MathTex for pure math** - Simpler than adding `$...$`
|
|
200
|
+
3. **Use Tex for mixed content** - When combining text and math
|
|
201
|
+
4. **Split for animation control** - Separate parts you'll animate differently
|
|
202
|
+
5. **Use substrings_to_isolate** - For reliable coloring of repeated elements
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: lines
|
|
3
|
+
description: Line, Arrow, Vector, DashedLine and connectors
|
|
4
|
+
metadata:
|
|
5
|
+
tags: line, arrow, vector, dashedline, brace, connector
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Lines and Arrows
|
|
9
|
+
|
|
10
|
+
Connect points and show relationships with lines and arrows.
|
|
11
|
+
|
|
12
|
+
## Line
|
|
13
|
+
|
|
14
|
+
Basic line between two points.
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
from manim import *
|
|
18
|
+
|
|
19
|
+
class LineExample(Scene):
|
|
20
|
+
def construct(self):
|
|
21
|
+
# Line from two points
|
|
22
|
+
line = Line(LEFT * 2, RIGHT * 2)
|
|
23
|
+
|
|
24
|
+
# With styling
|
|
25
|
+
styled_line = Line(
|
|
26
|
+
UP * 2, DOWN * 2,
|
|
27
|
+
color=BLUE,
|
|
28
|
+
stroke_width=4
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
self.add(line, styled_line)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Line Properties
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
line = Line(LEFT, RIGHT)
|
|
38
|
+
|
|
39
|
+
# Get points
|
|
40
|
+
line.get_start()
|
|
41
|
+
line.get_end()
|
|
42
|
+
line.get_center()
|
|
43
|
+
line.get_length()
|
|
44
|
+
line.get_angle()
|
|
45
|
+
|
|
46
|
+
# Modify
|
|
47
|
+
line.put_start_and_end_on(new_start, new_end)
|
|
48
|
+
line.set_length(3) # Keep direction, change length
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Arrow
|
|
52
|
+
|
|
53
|
+
Line with an arrowhead.
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
class ArrowExample(Scene):
|
|
57
|
+
def construct(self):
|
|
58
|
+
# Basic arrow
|
|
59
|
+
arrow = Arrow(LEFT * 2, RIGHT * 2)
|
|
60
|
+
|
|
61
|
+
# Styled arrow
|
|
62
|
+
styled = Arrow(
|
|
63
|
+
start=UP,
|
|
64
|
+
end=DOWN,
|
|
65
|
+
color=RED,
|
|
66
|
+
stroke_width=6,
|
|
67
|
+
tip_length=0.4,
|
|
68
|
+
max_tip_length_to_length_ratio=0.5
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
self.add(arrow, styled)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Arrow Variations
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
# Double-headed arrow
|
|
78
|
+
double = DoubleArrow(LEFT * 2, RIGHT * 2)
|
|
79
|
+
|
|
80
|
+
# Arrow with custom tip
|
|
81
|
+
arrow = Arrow(LEFT, RIGHT)
|
|
82
|
+
arrow.tip # Access the tip mobject
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Vector
|
|
86
|
+
|
|
87
|
+
Arrow starting from origin (useful for physics/math).
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
class VectorExample(Scene):
|
|
91
|
+
def construct(self):
|
|
92
|
+
# Vector from origin
|
|
93
|
+
v1 = Vector([2, 1, 0], color=YELLOW)
|
|
94
|
+
v2 = Vector([-1, 2, 0], color=GREEN)
|
|
95
|
+
|
|
96
|
+
self.add(v1, v2)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## DashedLine
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
class DashedLineExample(Scene):
|
|
103
|
+
def construct(self):
|
|
104
|
+
dashed = DashedLine(
|
|
105
|
+
LEFT * 2, RIGHT * 2,
|
|
106
|
+
dash_length=0.2,
|
|
107
|
+
dashed_ratio=0.5, # Ratio of dash to gap
|
|
108
|
+
color=WHITE
|
|
109
|
+
)
|
|
110
|
+
self.add(dashed)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## TangentLine
|
|
114
|
+
|
|
115
|
+
Line tangent to a curve at a point.
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
class TangentLineExample(Scene):
|
|
119
|
+
def construct(self):
|
|
120
|
+
circle = Circle(radius=2)
|
|
121
|
+
|
|
122
|
+
# Tangent at specific point (t parameter 0-1 along curve)
|
|
123
|
+
tangent = TangentLine(circle, alpha=0.25, length=3, color=YELLOW)
|
|
124
|
+
|
|
125
|
+
self.add(circle, tangent)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Brace
|
|
129
|
+
|
|
130
|
+
Curly brace for highlighting.
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
class BraceExample(Scene):
|
|
134
|
+
def construct(self):
|
|
135
|
+
rect = Rectangle(width=4, height=1)
|
|
136
|
+
|
|
137
|
+
# Brace under the rectangle
|
|
138
|
+
brace = Brace(rect, DOWN)
|
|
139
|
+
|
|
140
|
+
# With label
|
|
141
|
+
brace_text = brace.get_text("Width")
|
|
142
|
+
|
|
143
|
+
# Alternative: BraceLabel
|
|
144
|
+
brace_label = BraceLabel(rect, "Width", DOWN)
|
|
145
|
+
|
|
146
|
+
self.add(rect, brace, brace_text)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Brace Directions
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
brace_down = Brace(mobject, DOWN)
|
|
153
|
+
brace_up = Brace(mobject, UP)
|
|
154
|
+
brace_left = Brace(mobject, LEFT)
|
|
155
|
+
brace_right = Brace(mobject, RIGHT)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## CurvedArrow
|
|
159
|
+
|
|
160
|
+
Curved arrow between points.
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
class CurvedArrowExample(Scene):
|
|
164
|
+
def construct(self):
|
|
165
|
+
curved = CurvedArrow(
|
|
166
|
+
start_point=LEFT * 2,
|
|
167
|
+
end_point=RIGHT * 2,
|
|
168
|
+
angle=PI/2 # Curvature
|
|
169
|
+
)
|
|
170
|
+
self.add(curved)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Elbow
|
|
174
|
+
|
|
175
|
+
Right-angle connector.
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
class ElbowExample(Scene):
|
|
179
|
+
def construct(self):
|
|
180
|
+
elbow = Elbow(width=2, angle=PI/2)
|
|
181
|
+
self.add(elbow)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## NumberLine Ticks
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
class TicksExample(Scene):
|
|
188
|
+
def construct(self):
|
|
189
|
+
line = NumberLine(x_range=[-3, 3, 1])
|
|
190
|
+
self.add(line)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Connecting Mobjects
|
|
194
|
+
|
|
195
|
+
### Line Between Mobjects
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
class ConnectMobjects(Scene):
|
|
199
|
+
def construct(self):
|
|
200
|
+
c1 = Circle().shift(LEFT * 2)
|
|
201
|
+
c2 = Circle().shift(RIGHT * 2)
|
|
202
|
+
|
|
203
|
+
# Line connecting centers
|
|
204
|
+
line = Line(c1.get_center(), c2.get_center())
|
|
205
|
+
|
|
206
|
+
# Arrow between edges
|
|
207
|
+
arrow = Arrow(
|
|
208
|
+
c1.get_right(), # Right edge of c1
|
|
209
|
+
c2.get_left(), # Left edge of c2
|
|
210
|
+
buff=0.1 # Small gap from edges
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
self.add(c1, c2, line, arrow)
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Dynamic Connections with Updaters
|
|
217
|
+
|
|
218
|
+
```python
|
|
219
|
+
class DynamicLine(Scene):
|
|
220
|
+
def construct(self):
|
|
221
|
+
dot1 = Dot(LEFT * 2)
|
|
222
|
+
dot2 = Dot(RIGHT * 2)
|
|
223
|
+
|
|
224
|
+
# Line that follows dots
|
|
225
|
+
line = always_redraw(lambda: Line(
|
|
226
|
+
dot1.get_center(),
|
|
227
|
+
dot2.get_center(),
|
|
228
|
+
color=YELLOW
|
|
229
|
+
))
|
|
230
|
+
|
|
231
|
+
self.add(dot1, dot2, line)
|
|
232
|
+
self.play(dot1.animate.shift(UP * 2), run_time=2)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Best Practices
|
|
236
|
+
|
|
237
|
+
1. **Use Arrow for direction** - Clearer than plain lines
|
|
238
|
+
2. **Use Vector for physics/math** - Semantically meaningful
|
|
239
|
+
3. **Use Brace for labeling dimensions** - Professional look
|
|
240
|
+
4. **Use DashedLine for auxiliary lines** - Distinguishes from main content
|
|
241
|
+
5. **Use always_redraw for dynamic lines** - Updates with moving endpoints
|