Coverage for src/manimgx/constants.py: 100%
132 statements
« prev ^ index » next coverage.py v7.16.1, created at 2026-10-26 05:52 +0000
« prev ^ index » next coverage.py v7.16.1, created at 2026-10-26 05:52 +0000
1"""Directions, buffers, math constants and style enums (values identical to Manim CE 0.21)."""
3from enum import Enum
4from typing import Literal
6import numpy as np
7import numpy.typing as npt
9from manimgx.typing import Vector3D
11__all__ = [
12 "BOLD",
13 "BOOK",
14 "DEFAULT_ARROW_TIP_LENGTH",
15 "DEFAULT_DASH_LENGTH",
16 "DEFAULT_DOT_RADIUS",
17 "DEFAULT_FONT_SIZE",
18 "DEFAULT_MOBJECT_TO_EDGE_BUFFER",
19 "DEFAULT_MOBJECT_TO_MOBJECT_BUFFER",
20 "DEFAULT_POINTWISE_FUNCTION_RUN_TIME",
21 "DEFAULT_POINT_DENSITY_1D",
22 "DEFAULT_POINT_DENSITY_2D",
23 "DEFAULT_SMALL_DOT_RADIUS",
24 "DEFAULT_STROKE_WIDTH",
25 "DEFAULT_WAIT_TIME",
26 "DEGREES",
27 "DL",
28 "DOWN",
29 "DR",
30 "HEAVY",
31 "IN",
32 "ITALIC",
33 "LARGE_BUFF",
34 "LEFT",
35 "LIGHT",
36 "MEDIUM",
37 "MED_LARGE_BUFF",
38 "MED_SMALL_BUFF",
39 "NORMAL",
40 "OBLIQUE",
41 "ORIGIN",
42 "OUT",
43 "PI",
44 "RESAMPLING_ALGORITHMS",
45 "RIGHT",
46 "SCALE_FACTOR_PER_FONT_POINT",
47 "SEMIBOLD",
48 "SEMILIGHT",
49 "SMALL_BUFF",
50 "START_X",
51 "START_Y",
52 "TAU",
53 "THIN",
54 "UL",
55 "ULTRABOLD",
56 "ULTRAHEAVY",
57 "ULTRALIGHT",
58 "UP",
59 "UR",
60 "X_AXIS",
61 "Y_AXIS",
62 "Z_AXIS",
63 "CapStyleType",
64 "LineJointType",
65]
68def _constant(value: npt.ArrayLike) -> Vector3D:
69 """A direction as a constant: read-only, so that a mobject that keeps it (an arc's
70 center, a number's edge) can't change it for everything made after."""
71 array = np.array(value, dtype=float)
72 array.flags.writeable = False
73 return array
76ORIGIN: Vector3D = _constant((0.0, 0.0, 0.0))
77"""The center of the scene: (0, 0, 0)."""
78UP: Vector3D = _constant((0.0, 1.0, 0.0))
79"""One unit up: (0, 1, 0)."""
80DOWN: Vector3D = _constant((0.0, -1.0, 0.0))
81"""One unit down: (0, −1, 0)."""
82RIGHT: Vector3D = _constant((1.0, 0.0, 0.0))
83"""One unit right: (1, 0, 0)."""
84LEFT: Vector3D = _constant((-1.0, 0.0, 0.0))
85"""One unit left: (−1, 0, 0)."""
86IN: Vector3D = _constant((0.0, 0.0, -1.0))
87"""One unit into the screen, away from the viewer: (0, 0, −1)."""
88OUT: Vector3D = _constant((0.0, 0.0, 1.0))
89"""One unit out of the screen, toward the viewer: (0, 0, 1)."""
90X_AXIS: Vector3D = _constant((1.0, 0.0, 0.0))
91"""The direction of the x axis: (1, 0, 0)."""
92Y_AXIS: Vector3D = _constant((0.0, 1.0, 0.0))
93"""The direction of the y axis: (0, 1, 0)."""
94Z_AXIS: Vector3D = _constant((0.0, 0.0, 1.0))
95"""The direction of the z axis, out of the screen: (0, 0, 1)."""
96UL: Vector3D = _constant(UP + LEFT)
97"""Up and left, toward the upper left corner: (−1, 1, 0)."""
98UR: Vector3D = _constant(UP + RIGHT)
99"""Up and right, toward the upper right corner: (1, 1, 0)."""
100DL: Vector3D = _constant(DOWN + LEFT)
101"""Down and left, toward the lower left corner: (−1, −1, 0)."""
102DR: Vector3D = _constant(DOWN + RIGHT)
103"""Down and right, toward the lower right corner: (1, −1, 0)."""
105PI = np.pi
106"""π: half a turn, in radians."""
107TAU = 2 * PI
108"""τ = 2π: a whole turn, in radians."""
109DEGREES = TAU / 360
110"""One degree, in radians: `30 * DEGREES` is a twelfth of a turn."""
112SMALL_BUFF = 0.1
113"""A small gap, in scene units: 0.1."""
114MED_SMALL_BUFF = 0.25
115"""A medium-small gap, in scene units: 0.25, the default between mobjects
116placed next to each other."""
117MED_LARGE_BUFF = 0.5
118"""A medium-large gap, in scene units: 0.5, the default between a mobject and the
119frame's edge."""
120LARGE_BUFF = 1
121"""A large gap, in scene units: 1."""
122DEFAULT_MOBJECT_TO_EDGE_BUFFER = MED_LARGE_BUFF
123"""The gap a mobject keeps from the frame's edge by default, in scene units: 0.5
124(`to_edge`, `to_corner`)."""
125DEFAULT_MOBJECT_TO_MOBJECT_BUFFER = MED_SMALL_BUFF
126"""The gap between mobjects placed next to each other by default, in scene units:
1270.25 (`next_to`, `arrange`)."""
128DEFAULT_DOT_RADIUS = 0.08
129"""A dot's radius by default, in scene units."""
130DEFAULT_SMALL_DOT_RADIUS = 0.04
131"""A small dot's radius, in scene units: half the default."""
132DEFAULT_DASH_LENGTH = 0.05
133"""A dashed line's dash length by default, in scene units."""
134DEFAULT_ARROW_TIP_LENGTH = 0.35
135"""An arrow tip's length by default, in scene units."""
136DEFAULT_STROKE_WIDTH = 4
137"""A stroke's width by default, in hundredths of a scene unit."""
138DEFAULT_FONT_SIZE = 48
139"""Text's font size by default."""
140DEFAULT_WAIT_TIME = 1.0
141"""How long a wait lasts by default, in seconds."""
142DEFAULT_POINTWISE_FUNCTION_RUN_TIME = 3.0
143"""How long [ApplyPointwiseFunction][manimgx.ApplyPointwiseFunction], which moves every
144point through a function, and the animations built on it run by default, in seconds."""
145SCALE_FACTOR_PER_FONT_POINT = 1 / 960
146"""The scale of typeset text per unit of font size: Typst and LaTeX, typeset in 10-point
147type, are scaled so a point is `font_size` / 960 scene units and an em `font_size` / 96
148(0.5 at the default, 48). A [Text][manimgx.Text] is sized by its capitals instead."""
151class LineJointType(Enum):
152 """How a stroke is joined where its path turns (`joint_type`): round, beveled or
153 mitered.
155 The default, `AUTO`, is mitered. A two-dimensional scene draws the joints, of a
156 stroke and of its background stroke alike; a three-dimensional scene miters every
157 stroke.
159 Examples:
160 ```python
161 import manimgx as m
164 class LineJointTypeExample(m.Scene):
165 def construct(self) -> None:
166 corners = [[-1, -1.5, 0], [0, 1.5, 0], [1, -1.5, 0]]
167 paths = m.VGroup()
168 for joint in m.LineJointType:
169 path = m.VMobject(color=m.YELLOW, stroke_width=40, joint_type=joint)
170 path.set_points_as_corners(corners)
171 label = m.Text(joint.name, font_size=36).next_to(path, m.DOWN, 0.6)
172 paths.add(m.VGroup(path, label))
173 self.add(paths.arrange(buff=1))
174 ```
175 """
177 AUTO = 0
178 """The default: mitered, as `MITER`."""
179 ROUND = 1
180 """Round corners."""
181 BEVEL = 2
182 """Corners cut straight across."""
183 MITER = 3
184 """Pointed corners, where the stroke's edges meet; cut straight across where the
185 point would lie more than five stroke widths from the path's corner."""
188class CapStyleType(Enum):
189 """How a stroke ends (`cap_style`): round, butt or square.
191 Every end a stroke shows is capped: the ends of an open path, the moving end of a
192 reveal ([Create][manimgx.Create], [Write][manimgx.Write], …) and both ends of every
193 dash. A closed path shown whole has no ends, and a stroke of no length (a path that
194 stays at one point) shows as a dot with round caps, a square with square ones. The
195 default, `AUTO`, is butt. A two-dimensional scene draws the caps, of a stroke and of
196 its background stroke alike; a three-dimensional scene ends every stroke flat.
198 Examples:
199 ```python
200 import manimgx as m
203 class CapStyleTypeExample(m.Scene):
204 def construct(self) -> None:
205 arcs = m.VGroup()
206 for cap in m.CapStyleType:
207 arc = m.Arc(radius=2, color=m.GREEN, stroke_width=40)
208 arc.set_cap_style(cap)
209 label = m.Text(cap.name, font_size=36).next_to(arc, m.DOWN, 0.6)
210 arcs.add(m.VGroup(arc, label))
211 self.add(arcs.arrange(buff=1))
212 ```
213 """
215 AUTO = 0
216 """The default: flat at the end, as `BUTT`."""
217 ROUND = 1
218 """A half disk past the end."""
219 BUTT = 2
220 """Flat, at the end."""
221 SQUARE = 3
222 """Flat, half the stroke's width past the end."""
225NORMAL = "NORMAL"
226"""Text's normal slant, upright, and its normal weight (400)."""
227ITALIC = "ITALIC"
228"""An italic slant of text."""
229OBLIQUE = "OBLIQUE"
230"""An oblique slant of text: its upright letters, slanted."""
231BOLD = "BOLD"
232"""A weight of text: bold (700)."""
233THIN = "THIN"
234"""A weight of text: thin (100)."""
235ULTRALIGHT = "ULTRALIGHT"
236"""A weight of text: ultralight (200)."""
237LIGHT = "LIGHT"
238"""A weight of text: light (300)."""
239SEMILIGHT = "SEMILIGHT"
240"""A weight of text: semilight (350)."""
241BOOK = "BOOK"
242"""A weight of text: book (380)."""
243MEDIUM = "MEDIUM"
244"""A weight of text: medium (500)."""
245SEMIBOLD = "SEMIBOLD"
246"""A weight of text: semibold (600)."""
247ULTRABOLD = "ULTRABOLD"
248"""A weight of text: ultrabold (800)."""
249HEAVY = "HEAVY"
250"""A weight of text: heavy (900)."""
251ULTRAHEAVY = "ULTRAHEAVY"
252"""A weight of text: ultraheavy (950)."""
253DEFAULT_POINT_DENSITY_1D = 10
254"""How many points a point cloud's line gets per scene unit by default."""
255DEFAULT_POINT_DENSITY_2D = 25
256"""Kept for Manim compatibility; unused."""
257START_X = 30
258"""Kept for Manim compatibility; unused."""
259START_Y = 20
260"""Kept for Manim compatibility; unused."""
262type Resampling = Literal[0, 2, 3]
263"""How an image is reconstructed from its pixels where it is drawn larger than they are
264(drawn smaller, it shows their mean, whatever the algorithm), numbered as the Pillow
265library numbers its filters: 0, nearest (each pixel a square of its color); 2, linear;
2663, cubic (Keys' cubic convolution with a = −1/2, Pillow's BICUBIC: smooth, and through
267every pixel)."""
268RESAMPLING_ALGORITHMS: dict[str, Resampling] = {
269 "nearest": 0,
270 "none": 0,
271 "bilinear": 2,
272 "linear": 2,
273 "bicubic": 3,
274 "cubic": 3,
275}
276"""The filters an image can be reconstructed with, by name, each with its number (see
277[Resampling][manimgx.constants.Resampling]): "nearest" or "none", "bilinear" or
278"linear", "bicubic" or "cubic"."""