draw¶
champalimaud.draw
¶
Small manim helpers that draw stills.
render_still turns mobjects into a PNG.
The other helpers build the mobjects a network diagram needs.
No data and no network.
Importing this module sets where manim writes its files.
arrow(src, dst, color, *, slot=(0, 1), dashed=False)
¶
Make an arrow from the rim of one node to the rim of another.
Arrows that end on one node take different slots, so their heads land at different heights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
VGroup
|
Nodes, as |
required |
dst
|
VGroup
|
Nodes, as |
required |
color
|
str
|
Color of the arrow. |
required |
slot
|
tuple of int
|
|
(0, 1)
|
dashed
|
bool
|
Draw a dashed line, to mark a connection that is set aside. |
False
|
Returns:
| Type | Description |
|---|---|
Arrow or DashedLine
|
The arrow, or a dashed line with the same head. |
Examples:
>>> import manim as mn
>>> a = mn.VGroup(mn.Circle(radius=0.4)).move_to([-3, 0, 0])
>>> b = mn.VGroup(mn.Circle(radius=0.4)).move_to([3, 0, 0])
>>> round(float(arrow(a, b, "#000000").get_end()[0]), 2)
2.6
Source code in champalimaud/draw.py
bracket(x, top, bottom, color)
¶
Make a thin bracket, open to the right, to mark a group of nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Horizontal position of the bracket's spine. |
required |
top
|
float
|
Vertical extent. |
required |
bottom
|
float
|
Vertical extent. |
required |
color
|
str
|
Color of the stroke. |
required |
Returns:
| Type | Description |
|---|---|
VMobject
|
The bracket. |
Examples:
Source code in champalimaud/draw.py
fade(mobject, opacity=0.4)
¶
Dim the strokes and fills of a mobject.
Shapes without a fill stay without one; set_opacity would fill
an arc and turn it into a D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mobject
|
Mobject
|
What to dim; changed in place. |
required |
opacity
|
float
|
Opacity of the strokes and of the fills that exist. |
0.4
|
Returns:
| Type | Description |
|---|---|
Mobject
|
|
Examples:
>>> import manim as mn
>>> circle = fade(mn.Circle(), 0.25)
>>> round(float(circle.get_stroke_opacity()), 2)
0.25
>>> float(circle.get_fill_opacity())
0.0
Source code in champalimaud/draw.py
label_on(line, text, color, *, at=0.3, shift=(0, 0))
¶
Place a LaTeX label on a white patch along a straight line.
The patch keeps lines that cross the label from running through the text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
Mobject
|
A straight line or arrow. |
required |
text
|
str
|
LaTeX for the label. |
required |
color
|
str
|
Color of the text. |
required |
at
|
float
|
Fraction of the way along the line. |
0.3
|
shift
|
tuple of float
|
Offset of the label, as |
(0, 0)
|
Returns:
| Type | Description |
|---|---|
VGroup
|
The patch at index 0 and the label at index 1. |
Source code in champalimaud/draw.py
node(label, at, color, *, radius=0.3, ring=None)
¶
Make a circle with a LaTeX label.
The circle is solid in color with white text or, given a ring
width, a paper circle with a ring of color.
The text scales with the circle, so a label always fits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
LaTeX for the text. |
required |
at
|
tuple of float
|
Center, as |
required |
color
|
str
|
Fill, or ring color. |
required |
radius
|
float
|
Radius of the circle. |
0.3
|
ring
|
float
|
Stroke width of the ring; |
None
|
Returns:
| Type | Description |
|---|---|
VGroup
|
The circle at index 0 and the label at index 1. |
Source code in champalimaud/draw.py
render_still(*mobjects, width=9.0, height=7.0, per_unit=150)
¶
Render mobjects as a PNG on a white frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*mobjects
|
Mobject
|
What to draw. |
()
|
width
|
float
|
Size of the frame, in manim units. |
9.0 and 7.0
|
height
|
float
|
Size of the frame, in manim units. |
9.0 and 7.0
|
per_unit
|
int
|
Pixels per unit. |
150
|
Returns:
| Type | Description |
|---|---|
bytes
|
The PNG file. |