0
# Mathematical Objects
1
2
Extensive library of mathematical objects including 2D geometry, 3D shapes, text rendering, graphs, and coordinate systems with precise mathematical properties. Mobjects (Mathematical Objects) are the visual building blocks of Manim animations, representing everything from basic shapes to complex mathematical constructs.
3
4
## Capabilities
5
6
### Base Mobject Classes
7
8
Fundamental classes that provide the core functionality for all mathematical objects in Manim.
9
10
```python { .api }
11
class Mobject:
12
"""
13
Base class for all mathematical objects that can be displayed and animated.
14
15
Provides fundamental positioning, transformation, and animation capabilities
16
that all visual elements inherit from.
17
"""
18
19
def __init__(
20
color: str = WHITE,
21
name: str = None,
22
dim: int = 3,
23
target: Mobject = None
24
) -> None:
25
"""
26
Parameters:
27
- color: Default color for the mobject
28
- name: Optional name for debugging
29
- dim: Dimensionality (2 or 3)
30
- target: Target mobject for transformations
31
"""
32
33
# Position and transformation methods
34
def shift(vector: np.ndarray) -> Self:
35
"""Move mobject by the given vector offset."""
36
37
def move_to(
38
point_or_mobject: np.ndarray | Mobject,
39
aligned_edge: np.ndarray = ORIGIN,
40
coor_mask: np.ndarray = np.array([1, 1, 1])
41
) -> Self:
42
"""Move mobject so point_or_mobject is at its center or aligned edge."""
43
44
def rotate(
45
angle: float,
46
axis: np.ndarray = OUT,
47
about_point: np.ndarray = None,
48
**kwargs
49
) -> Self:
50
"""Rotate mobject by angle around axis through about_point."""
51
52
def scale(
53
scale_factor: float,
54
**kwargs
55
) -> Self:
56
"""Scale mobject by scale_factor around its center or specified point."""
57
58
def stretch(
59
factor: float,
60
dim: int,
61
**kwargs
62
) -> Self:
63
"""Stretch mobject by factor along specified dimension (0=x, 1=y, 2=z)."""
64
65
def flip(axis: np.ndarray = RIGHT, **kwargs) -> Self:
66
"""Flip mobject across the given axis."""
67
68
# Position query methods
69
def get_center() -> np.ndarray:
70
"""Get center point of mobject."""
71
72
def get_corner(direction: np.ndarray) -> np.ndarray:
73
"""Get corner of mobject in given direction."""
74
75
def get_edge_center(direction: np.ndarray) -> np.ndarray:
76
"""Get center of edge in given direction."""
77
78
def get_boundary_point(direction: np.ndarray) -> np.ndarray:
79
"""Get point on boundary in given direction."""
80
81
# Relative positioning methods
82
def next_to(
83
mobject_or_point: Mobject | np.ndarray,
84
direction: np.ndarray = RIGHT,
85
buff: float = DEFAULT_MOBJECT_TO_MOBJECT_BUFFER,
86
aligned_edge: np.ndarray = ORIGIN,
87
submobject_to_align: Mobject = None,
88
index_of_submobject_to_align: int = None,
89
coor_mask: np.ndarray = np.array([1, 1, 1])
90
) -> Self:
91
"""
92
Position this mobject next to another mobject or point.
93
94
Parameters:
95
- mobject_or_point: Reference object or point
96
- direction: Direction to place mobject (UP, DOWN, LEFT, RIGHT, etc.)
97
- buff: Buffer distance between objects
98
- aligned_edge: Which edge to align with reference
99
- submobject_to_align: Specific submobject to use for alignment
100
- index_of_submobject_to_align: Index of submobject to align
101
- coor_mask: Mask for which coordinates to consider
102
"""
103
104
def to_corner(corner: np.ndarray = DL, buff: float = DEFAULT_MOBJECT_TO_EDGE_BUFFER) -> Self:
105
"""Move mobject to specified corner of the frame."""
106
107
def to_edge(edge: np.ndarray = LEFT, buff: float = DEFAULT_MOBJECT_TO_EDGE_BUFFER) -> Self:
108
"""Move mobject to specified edge of the frame."""
109
110
# Submobject management
111
def add(*mobjects: Mobject) -> Self:
112
"""Add mobjects as submobjects of this mobject."""
113
114
def remove(*mobjects: Mobject) -> Self:
115
"""Remove mobjects from this mobject's submobjects."""
116
117
def get_submobjects() -> list[Mobject]:
118
"""Get list of direct submobjects."""
119
120
def get_family() -> list[Mobject]:
121
"""Get this mobject and all its descendants."""
122
123
# Animation and updater methods
124
def add_updater(
125
update_function: Callable,
126
index: int = None,
127
call_updater: bool = True
128
) -> Self:
129
"""
130
Add function to be called every frame to update this mobject.
131
132
Parameters:
133
- update_function: Function taking mobject and optionally dt as parameters
134
- index: Position to insert updater in list
135
- call_updater: Whether to call updater immediately
136
"""
137
138
def remove_updater(update_function: Callable) -> Self:
139
"""Remove updater function."""
140
141
def suspend_updating(recursive: bool = True) -> Self:
142
"""Temporarily stop calling updaters."""
143
144
def resume_updating(recursive: bool = True) -> Self:
145
"""Resume calling updaters."""
146
147
# State management
148
def save_state(use_deepcopy: bool = False) -> Self:
149
"""Save current state for later restoration."""
150
151
def restore() -> Self:
152
"""Restore to previously saved state."""
153
154
# Animation property access
155
@property
156
def animate() -> _AnimationBuilder:
157
"""Access to animation builder for fluent animation syntax."""
158
159
def copy() -> Self:
160
"""Create a deep copy of this mobject."""
161
162
class VMobject(Mobject):
163
"""
164
Vector-based mobject using Bézier curves for smooth, scalable graphics.
165
166
The primary mobject type for 2D graphics, providing stroke, fill,
167
and path-based rendering with mathematical precision.
168
"""
169
170
def __init__(
171
fill_color: str = None,
172
fill_opacity: float = 0.0,
173
stroke_color: str = None,
174
stroke_opacity: float = 1.0,
175
stroke_width: float = DEFAULT_STROKE_WIDTH,
176
background_stroke_color: str = BLACK,
177
background_stroke_opacity: float = 1.0,
178
background_stroke_width: float = 0,
179
sheen_factor: float = 0.0,
180
sheen_direction: np.ndarray = UL,
181
close_new_points: bool = False,
182
pre_function_handle_to_anchor_scale_factor: float = 0.01,
183
make_smooth_after_applying_functions: bool = False,
184
**kwargs
185
) -> None:
186
"""
187
Parameters:
188
- fill_color: Interior color
189
- fill_opacity: Interior opacity (0=transparent, 1=opaque)
190
- stroke_color: Outline color
191
- stroke_opacity: Outline opacity
192
- stroke_width: Outline thickness
193
- background_stroke_color: Background outline color
194
- background_stroke_opacity: Background outline opacity
195
- background_stroke_width: Background outline thickness
196
- sheen_factor: Glossy reflection amount
197
- sheen_direction: Direction of glossy reflection
198
- close_new_points: Whether to close paths automatically
199
- pre_function_handle_to_anchor_scale_factor: Bézier handle scaling
200
- make_smooth_after_applying_functions: Auto-smooth after transformations
201
"""
202
203
# Style methods
204
def set_color(color: str) -> Self:
205
"""Set both fill and stroke color."""
206
207
def set_fill(
208
color: str = None,
209
opacity: float = None,
210
family: bool = True
211
) -> Self:
212
"""
213
Set fill properties.
214
215
Parameters:
216
- color: Fill color
217
- opacity: Fill opacity
218
- family: Whether to apply to submobjects
219
"""
220
221
def set_stroke(
222
color: str = None,
223
width: float = None,
224
opacity: float = None,
225
background: bool = False,
226
family: bool = True
227
) -> Self:
228
"""
229
Set stroke properties.
230
231
Parameters:
232
- color: Stroke color
233
- width: Stroke width
234
- opacity: Stroke opacity
235
- background: Whether to set background stroke
236
- family: Whether to apply to submobjects
237
"""
238
239
def set_style(
240
fill_color: str = None,
241
fill_opacity: float = None,
242
stroke_color: str = None,
243
stroke_width: float = None,
244
stroke_opacity: float = None,
245
family: bool = True
246
) -> Self:
247
"""Set multiple style properties at once."""
248
249
def get_fill_color() -> str:
250
"""Get current fill color."""
251
252
def get_stroke_color() -> str:
253
"""Get current stroke color."""
254
255
def get_stroke_width() -> float:
256
"""Get current stroke width."""
257
258
# Path manipulation methods
259
def set_points(points: np.ndarray) -> Self:
260
"""Set the path points directly."""
261
262
def set_points_as_corners(points: np.ndarray) -> Self:
263
"""Set points as corners with straight line segments."""
264
265
def set_points_smoothly(points: np.ndarray) -> Self:
266
"""Set points with smooth Bézier curve interpolation."""
267
268
def add_line_to(point: np.ndarray) -> Self:
269
"""Add straight line to specified point."""
270
271
def add_smooth_curve_to(*points: np.ndarray) -> Self:
272
"""Add smooth curve through specified points."""
273
274
def close_path() -> Self:
275
"""Close the current path by connecting end to start."""
276
277
def get_points() -> np.ndarray:
278
"""Get array of all path points."""
279
280
def get_start() -> np.ndarray:
281
"""Get starting point of path."""
282
283
def get_end() -> np.ndarray:
284
"""Get ending point of path."""
285
286
def get_anchors() -> np.ndarray:
287
"""Get anchor points (excluding Bézier control points)."""
288
289
class Group(Mobject):
290
"""
291
Container for grouping multiple mobjects together.
292
293
Provides collective operations on multiple objects while maintaining
294
their individual properties and behaviors.
295
"""
296
297
def __init__(*mobjects: Mobject, **kwargs) -> None:
298
"""
299
Parameters:
300
- *mobjects: Mobjects to include in the group
301
"""
302
303
def arrange(
304
direction: np.ndarray = RIGHT,
305
buff: float = DEFAULT_MOBJECT_TO_MOBJECT_BUFFER,
306
center: bool = True,
307
**kwargs
308
) -> Self:
309
"""
310
Arrange submobjects in a line.
311
312
Parameters:
313
- direction: Direction to arrange along
314
- buff: Buffer space between objects
315
- center: Whether to center the arrangement
316
"""
317
318
def arrange_in_grid(
319
rows: int = None,
320
cols: int = None,
321
buff: float = MED_SMALL_BUFF,
322
cell_alignment: np.ndarray = ORIGIN,
323
row_alignments: str = "c",
324
col_alignments: str = "c",
325
row_heights: list[float] = None,
326
col_widths: list[float] = None,
327
flow_order: str = "rd",
328
**kwargs
329
) -> Self:
330
"""
331
Arrange submobjects in a grid layout.
332
333
Parameters:
334
- rows: Number of rows (auto-calculated if None)
335
- cols: Number of columns (auto-calculated if None)
336
- buff: Buffer space between objects
337
- cell_alignment: Alignment within each cell
338
- row_alignments: Alignment for each row ("c", "l", "r")
339
- col_alignments: Alignment for each column
340
- row_heights: Height of each row
341
- col_widths: Width of each column
342
- flow_order: Fill order ("rd"=right-down, "dr"=down-right)
343
"""
344
345
class VGroup(VMobject, Group):
346
"""
347
Group of VMobjects that can be styled collectively.
348
349
Combines the grouping functionality of Group with the styling
350
capabilities of VMobject.
351
"""
352
353
def __init__(*vmobjects: VMobject, **kwargs) -> None:
354
"""
355
Parameters:
356
- *vmobjects: VMobjects to include in the group
357
"""
358
```
359
360
### 2D Geometry
361
362
Core 2D geometric shapes and constructs with precise mathematical definitions and customizable visual properties.
363
364
```python { .api }
365
# Circles and Arcs
366
def Circle(
367
radius: float = 1.0,
368
color: str = RED,
369
**kwargs
370
) -> Circle:
371
"""
372
Perfect circle with specified radius.
373
374
Parameters:
375
- radius: Circle radius
376
- color: Circle color
377
"""
378
379
def Arc(
380
radius: float = 1.0,
381
start_angle: float = 0,
382
angle: float = TAU / 4,
383
arc_center: np.ndarray = ORIGIN,
384
**kwargs
385
) -> Arc:
386
"""
387
Circular arc segment.
388
389
Parameters:
390
- radius: Arc radius
391
- start_angle: Starting angle in radians
392
- angle: Arc span in radians
393
- arc_center: Center point of arc
394
"""
395
396
def Dot(
397
point: np.ndarray = ORIGIN,
398
radius: float = DEFAULT_DOT_RADIUS,
399
stroke_width: float = 0,
400
fill_opacity: float = 1.0,
401
color: str = WHITE,
402
**kwargs
403
) -> Dot:
404
"""
405
Small filled circle, typically used as a point indicator.
406
407
Parameters:
408
- point: Position of the dot
409
- radius: Dot radius
410
- stroke_width: Outline width (0 for no outline)
411
- fill_opacity: Fill opacity
412
- color: Dot color
413
"""
414
415
def Ellipse(
416
width: float = 2,
417
height: float = 1,
418
**kwargs
419
) -> Ellipse:
420
"""
421
Elliptical shape with specified width and height.
422
423
Parameters:
424
- width: Ellipse width
425
- height: Ellipse height
426
"""
427
428
def Annulus(
429
inner_radius: float = 1,
430
outer_radius: float = 2,
431
**kwargs
432
) -> Annulus:
433
"""
434
Ring shape (annulus) between two concentric circles.
435
436
Parameters:
437
- inner_radius: Inner circle radius
438
- outer_radius: Outer circle radius
439
"""
440
441
def Sector(
442
outer_radius: float = 1,
443
inner_radius: float = 0,
444
angle: float = TAU / 4,
445
start_angle: float = 0,
446
arc_center: np.ndarray = ORIGIN,
447
**kwargs
448
) -> Sector:
449
"""
450
Circular sector (pie slice) shape.
451
452
Parameters:
453
- outer_radius: Outer radius
454
- inner_radius: Inner radius (0 for full sector)
455
- angle: Sector angle in radians
456
- start_angle: Starting angle in radians
457
- arc_center: Center point
458
"""
459
460
# Lines and Polygons
461
def Line(
462
start: np.ndarray = LEFT,
463
end: np.ndarray = RIGHT,
464
buff: float = 0,
465
path_arc: float = None,
466
**kwargs
467
) -> Line:
468
"""
469
Straight line segment between two points.
470
471
Parameters:
472
- start: Starting point
473
- end: Ending point
474
- buff: Buffer distance from endpoints
475
- path_arc: Arc curvature (None for straight line)
476
"""
477
478
def DashedLine(
479
*args,
480
dash_length: float = DEFAULT_DASH_LENGTH,
481
dashed_ratio: float = 0.5,
482
**kwargs
483
) -> DashedLine:
484
"""
485
Dashed line with customizable dash pattern.
486
487
Parameters:
488
- dash_length: Length of each dash
489
- dashed_ratio: Ratio of dash to gap (0.5 = equal dash and gap)
490
"""
491
492
def Arrow(
493
start: np.ndarray = LEFT,
494
end: np.ndarray = RIGHT,
495
buff: float = MED_SMALL_BUFF,
496
stroke_width: float = 6,
497
tip_length: float = 0.35,
498
max_stroke_width_to_length_ratio: float = 5,
499
max_tip_length_to_length_ratio: float = 0.5,
500
**kwargs
501
) -> Arrow:
502
"""
503
Arrow with customizable arrowhead.
504
505
Parameters:
506
- start: Arrow start point
507
- end: Arrow end point
508
- buff: Buffer from start/end points
509
- stroke_width: Arrow shaft thickness
510
- tip_length: Arrowhead length
511
- max_stroke_width_to_length_ratio: Max stroke width ratio
512
- max_tip_length_to_length_ratio: Max tip length ratio
513
"""
514
515
def Vector(
516
direction: np.ndarray = RIGHT,
517
buff: float = 0,
518
**kwargs
519
) -> Vector:
520
"""
521
Vector arrow starting from origin.
522
523
Parameters:
524
- direction: Vector direction and magnitude
525
- buff: Buffer from origin
526
"""
527
528
def DoubleArrow(
529
*args,
530
**kwargs
531
) -> DoubleArrow:
532
"""Arrow with arrowheads on both ends."""
533
534
# Polygons
535
def Rectangle(
536
height: float = 2.0,
537
width: float = 4.0,
538
**kwargs
539
) -> Rectangle:
540
"""
541
Rectangular shape.
542
543
Parameters:
544
- height: Rectangle height
545
- width: Rectangle width
546
"""
547
548
def Square(
549
side_length: float = 2.0,
550
**kwargs
551
) -> Square:
552
"""
553
Square with equal sides.
554
555
Parameters:
556
- side_length: Length of each side
557
"""
558
559
def RoundedRectangle(
560
height: float = 2.0,
561
width: float = 4.0,
562
corner_radius: float = 0.5,
563
**kwargs
564
) -> RoundedRectangle:
565
"""
566
Rectangle with rounded corners.
567
568
Parameters:
569
- height: Rectangle height
570
- width: Rectangle width
571
- corner_radius: Radius of rounded corners
572
"""
573
574
def Triangle(
575
**kwargs
576
) -> Triangle:
577
"""Equilateral triangle."""
578
579
def Polygon(
580
*vertices: np.ndarray,
581
**kwargs
582
) -> Polygon:
583
"""
584
Polygon defined by vertex coordinates.
585
586
Parameters:
587
- *vertices: Vertex coordinates as numpy arrays
588
"""
589
590
def RegularPolygon(
591
n: int = 6,
592
radius: float = 1,
593
start_angle: float = 0,
594
**kwargs
595
) -> RegularPolygon:
596
"""
597
Regular polygon with n sides.
598
599
Parameters:
600
- n: Number of sides
601
- radius: Circumscribed circle radius
602
- start_angle: Rotation of first vertex
603
"""
604
605
# Curves
606
def CubicBezier(
607
start_anchor: np.ndarray,
608
start_handle: np.ndarray,
609
end_handle: np.ndarray,
610
end_anchor: np.ndarray,
611
**kwargs
612
) -> CubicBezier:
613
"""
614
Cubic Bézier curve with control points.
615
616
Parameters:
617
- start_anchor: Starting point
618
- start_handle: Starting control point
619
- end_handle: Ending control point
620
- end_anchor: Ending point
621
"""
622
623
def CurvedArrow(
624
start_point: np.ndarray,
625
end_point: np.ndarray,
626
radius: float = -2.0,
627
**kwargs
628
) -> CurvedArrow:
629
"""
630
Curved arrow along circular arc.
631
632
Parameters:
633
- start_point: Arrow start
634
- end_point: Arrow end
635
- radius: Curvature radius (negative for clockwise)
636
"""
637
```
638
639
### Text and LaTeX
640
641
Text rendering system supporting both regular fonts and mathematical LaTeX typesetting with full Unicode support.
642
643
```python { .api }
644
def Text(
645
text: str,
646
fill_opacity: float = 1.0,
647
stroke_width: float = 0,
648
font_size: float = 48,
649
line_spacing: float = -1,
650
font: str = '',
651
slant: str = "NORMAL",
652
weight: str = "NORMAL",
653
t2c: dict = None,
654
t2f: dict = None,
655
t2g: dict = None,
656
t2s: dict = None,
657
t2w: dict = None,
658
gradient: tuple = None,
659
tab_width: int = 4,
660
height: float = None,
661
width: float = None,
662
should_center: bool = True,
663
unpack_groups: bool = True,
664
disable_ligatures: bool = False,
665
warn_missing_font: bool = True,
666
**kwargs
667
) -> Text:
668
"""
669
Text rendered using system fonts with Pango library.
670
671
Supports international characters, font styling, and per-character formatting.
672
673
Parameters:
674
- text: Text string to render
675
- fill_opacity: Text opacity
676
- stroke_width: Text outline width
677
- font_size: Font size in points
678
- line_spacing: Line spacing multiplier (-1 for auto)
679
- font: Font family name
680
- slant: Font slant ("NORMAL", "ITALIC", "OBLIQUE")
681
- weight: Font weight ("NORMAL", "BOLD", etc.)
682
- t2c: Text-to-color mapping dict
683
- t2f: Text-to-font mapping dict
684
- t2g: Text-to-gradient mapping dict
685
- t2s: Text-to-slant mapping dict
686
- t2w: Text-to-weight mapping dict
687
- gradient: Color gradient tuple
688
- tab_width: Tab character width
689
- height: Target height (auto-scales font)
690
- width: Target width (auto-scales font)
691
- should_center: Whether to center text
692
- unpack_groups: Whether to unpack character groups
693
- disable_ligatures: Whether to disable font ligatures
694
- warn_missing_font: Whether to warn about missing fonts
695
"""
696
697
def MarkupText(
698
text: str,
699
**kwargs
700
) -> MarkupText:
701
"""
702
Text with Pango markup formatting support.
703
704
Supports HTML-like markup for rich text formatting within a single string.
705
706
Parameters:
707
- text: Text with Pango markup tags
708
"""
709
710
def Paragraph(
711
*text: str,
712
line_spacing: float = -1,
713
alignment: str = "left",
714
**kwargs
715
) -> Paragraph:
716
"""
717
Multi-line text with paragraph formatting.
718
719
Parameters:
720
- *text: Text lines
721
- line_spacing: Spacing between lines
722
- alignment: Text alignment ("left", "center", "right")
723
"""
724
725
def MathTex(
726
*tex_strings: str,
727
arg_separator: str = " ",
728
substrings_to_isolate: list[str] = None,
729
tex_to_color_map: dict[str, str] = None,
730
tex_template: TexTemplate = None,
731
**kwargs
732
) -> MathTex:
733
"""
734
Mathematical expressions rendered with LaTeX in math mode.
735
736
Automatically wraps content in math delimiters and processes with LaTeX
737
for high-quality mathematical typesetting.
738
739
Parameters:
740
- *tex_strings: LaTeX math expressions
741
- arg_separator: Separator between tex_strings
742
- substrings_to_isolate: Substrings to treat as separate objects
743
- tex_to_color_map: Color mapping for specific LaTeX substrings
744
- tex_template: Custom LaTeX template
745
"""
746
747
def Tex(
748
*tex_strings: str,
749
arg_separator: str = "",
750
substrings_to_isolate: list[str] = None,
751
tex_to_color_map: dict[str, str] = None,
752
tex_template: TexTemplate = None,
753
**kwargs
754
) -> Tex:
755
"""
756
General LaTeX text rendering for text mode content.
757
758
Renders LaTeX content in text mode, supporting complex formatting,
759
symbols, and layout commands.
760
761
Parameters:
762
- *tex_strings: LaTeX text content
763
- arg_separator: Separator between tex_strings
764
- substrings_to_isolate: Substrings to treat as separate objects
765
- tex_to_color_map: Color mapping for specific LaTeX substrings
766
- tex_template: Custom LaTeX template
767
"""
768
769
def Title(
770
*text_parts: str,
771
include_underline: bool = True,
772
match_underline_width_to_text: bool = False,
773
underline_buff: float = MED_SMALL_BUFF,
774
**kwargs
775
) -> Title:
776
"""
777
Title text with optional underline.
778
779
Parameters:
780
- *text_parts: Text content for title
781
- include_underline: Whether to add underline
782
- match_underline_width_to_text: Whether underline matches text width
783
- underline_buff: Space between text and underline
784
"""
785
786
def BulletedList(
787
*items: str,
788
bullet_style: str = "-",
789
**kwargs
790
) -> BulletedList:
791
"""
792
Bulleted list using LaTeX formatting.
793
794
Parameters:
795
- *items: List items
796
- bullet_style: Bullet character or LaTeX symbol
797
"""
798
799
# Mathematical number display
800
def DecimalNumber(
801
number: float = 0,
802
num_decimal_places: int = 2,
803
include_sign: bool = False,
804
group_with_commas: bool = True,
805
digit_buff_per_font_unit: float = 0.001,
806
show_ellipsis: bool = False,
807
unit: str = None,
808
include_background_rectangle: bool = False,
809
edge_to_fix: np.ndarray = LEFT,
810
**kwargs
811
) -> DecimalNumber:
812
"""
813
Decimal number with customizable formatting.
814
815
Parameters:
816
- number: Numeric value to display
817
- num_decimal_places: Number of decimal places
818
- include_sign: Whether to show + sign for positive numbers
819
- group_with_commas: Whether to use comma thousands separators
820
- digit_buff_per_font_unit: Spacing between digits
821
- show_ellipsis: Whether to show ellipsis for truncated numbers
822
- unit: Unit string to append
823
- include_background_rectangle: Whether to add background
824
- edge_to_fix: Which edge to keep fixed during updates
825
"""
826
827
def Integer(
828
number: int = 0,
829
**kwargs
830
) -> Integer:
831
"""
832
Integer number display.
833
834
Parameters:
835
- number: Integer value to display
836
"""
837
838
def Variable(
839
var: float | complex,
840
label: str | Tex | MathTex,
841
var_type: type = DecimalNumber,
842
**kwargs
843
) -> Variable:
844
"""
845
Variable display with label and updating value.
846
847
Parameters:
848
- var: Initial variable value
849
- label: Variable label text
850
- var_type: Class for displaying the value
851
"""
852
```
853
854
### 3D Objects
855
856
Three-dimensional shapes and constructs for 3D scene visualization with proper depth, shading, and perspective rendering.
857
858
```python { .api }
859
def Sphere(
860
center: np.ndarray = ORIGIN,
861
radius: float = 1,
862
resolution: tuple[int, int] = (101, 51),
863
u_range: tuple[float, float] = (0, TAU),
864
v_range: tuple[float, float] = (0, PI),
865
**kwargs
866
) -> Sphere:
867
"""
868
Three-dimensional sphere.
869
870
Parameters:
871
- center: Sphere center point
872
- radius: Sphere radius
873
- resolution: Surface mesh resolution (u, v)
874
- u_range: Azimuthal angle range
875
- v_range: Polar angle range
876
"""
877
878
def Cube(
879
side_length: float = 2,
880
fill_opacity: float = 0.75,
881
fill_color: str = BLUE,
882
stroke_width: float = 0,
883
**kwargs
884
) -> Cube:
885
"""
886
Three-dimensional cube.
887
888
Parameters:
889
- side_length: Length of each edge
890
- fill_opacity: Face opacity
891
- fill_color: Face color
892
- stroke_width: Edge line width
893
"""
894
895
def Prism(
896
dimensions: tuple[float, float, float] = (3, 2, 1),
897
**kwargs
898
) -> Prism:
899
"""
900
Rectangular prism (box) with specified dimensions.
901
902
Parameters:
903
- dimensions: Width, height, depth
904
"""
905
906
def Cylinder(
907
radius: float = 1,
908
height: float = 2,
909
direction: np.ndarray = Z_AXIS,
910
v_range: tuple[float, float] = (0, TAU),
911
show_ends: bool = True,
912
resolution: tuple[int, int] = (24, 24),
913
**kwargs
914
) -> Cylinder:
915
"""
916
Three-dimensional cylinder.
917
918
Parameters:
919
- radius: Cylinder radius
920
- height: Cylinder height
921
- direction: Cylinder axis direction
922
- v_range: Angular range for partial cylinders
923
- show_ends: Whether to show end caps
924
- resolution: Surface mesh resolution
925
"""
926
927
def Cone(
928
base_radius: float = 1,
929
height: float = 2,
930
direction: np.ndarray = Z_AXIS,
931
show_base: bool = True,
932
v_range: tuple[float, float] = (0, TAU),
933
resolution: tuple[int, int] = (24, 24),
934
**kwargs
935
) -> Cone:
936
"""
937
Three-dimensional cone.
938
939
Parameters:
940
- base_radius: Base circle radius
941
- height: Cone height
942
- direction: Cone axis direction
943
- show_base: Whether to show base circle
944
- v_range: Angular range for partial cones
945
- resolution: Surface mesh resolution
946
"""
947
948
def Dot3D(
949
point: np.ndarray = ORIGIN,
950
radius: float = DEFAULT_DOT_RADIUS,
951
color: str = WHITE,
952
resolution: tuple[int, int] = (8, 8),
953
**kwargs
954
) -> Dot3D:
955
"""
956
Three-dimensional dot (small sphere).
957
958
Parameters:
959
- point: Position of the dot
960
- radius: Dot radius
961
- color: Dot color
962
- resolution: Sphere mesh resolution
963
"""
964
965
def Line3D(
966
start: np.ndarray = LEFT,
967
end: np.ndarray = RIGHT,
968
thickness: float = 0.02,
969
color: str = WHITE,
970
**kwargs
971
) -> Line3D:
972
"""
973
Three-dimensional line (cylindrical).
974
975
Parameters:
976
- start: Line start point
977
- end: Line end point
978
- thickness: Line thickness
979
- color: Line color
980
"""
981
982
def Arrow3D(
983
start: np.ndarray = ORIGIN,
984
end: np.ndarray = RIGHT + UP + OUT,
985
thickness: float = 0.02,
986
height: float = 0.3,
987
base_radius: float = 0.08,
988
color: str = WHITE,
989
**kwargs
990
) -> Arrow3D:
991
"""
992
Three-dimensional arrow.
993
994
Parameters:
995
- start: Arrow start point
996
- end: Arrow end point
997
- thickness: Shaft thickness
998
- height: Arrowhead height
999
- base_radius: Arrowhead base radius
1000
- color: Arrow color
1001
"""
1002
1003
def Surface(
1004
func: Callable[[float, float], np.ndarray],
1005
u_range: tuple[float, float] = (-1, 1),
1006
v_range: tuple[float, float] = (-1, 1),
1007
resolution: int | tuple[int, int] = 32,
1008
fill_color: str = BLUE_D,
1009
fill_opacity: float = 1.0,
1010
checkerboard_colors: list[str] = None,
1011
stroke_color: str = LIGHT_GREY,
1012
stroke_width: float = 0.5,
1013
should_make_jagged: bool = False,
1014
**kwargs
1015
) -> Surface:
1016
"""
1017
Parametric surface defined by function.
1018
1019
Creates 3D surface by evaluating function over parameter grid.
1020
1021
Parameters:
1022
- func: Function (u,v) -> [x,y,z] defining surface
1023
- u_range: Parameter u range (u_min, u_max)
1024
- v_range: Parameter v range (v_min, v_max)
1025
- resolution: Surface mesh resolution
1026
- fill_color: Surface color
1027
- fill_opacity: Surface opacity
1028
- checkerboard_colors: Alternating face colors
1029
- stroke_color: Edge line color
1030
- stroke_width: Edge line width
1031
- should_make_jagged: Whether to use sharp edges
1032
"""
1033
1034
# Polyhedra
1035
def Tetrahedron(
1036
edge_length: float = 2,
1037
**kwargs
1038
) -> Tetrahedron:
1039
"""Regular tetrahedron (4 triangular faces)."""
1040
1041
def Octahedron(
1042
edge_length: float = 2,
1043
**kwargs
1044
) -> Octahedron:
1045
"""Regular octahedron (8 triangular faces)."""
1046
1047
def Icosahedron(
1048
edge_length: float = 2,
1049
**kwargs
1050
) -> Icosahedron:
1051
"""Regular icosahedron (20 triangular faces)."""
1052
1053
def Dodecahedron(
1054
edge_length: float = 2,
1055
**kwargs
1056
) -> Dodecahedron:
1057
"""Regular dodecahedron (12 pentagonal faces)."""
1058
```
1059
1060
### Boolean Operations
1061
1062
Boolean operations for combining, intersecting, and manipulating geometric shapes with mathematical precision.
1063
1064
```python { .api }
1065
def Union(
1066
*vmobjects: VMobject,
1067
**kwargs
1068
) -> VMobject:
1069
"""
1070
Boolean union of multiple VMobjects.
1071
1072
Combines shapes to create a single shape containing all areas
1073
covered by any of the input shapes.
1074
1075
Parameters:
1076
- *vmobjects: VMobjects to unite
1077
"""
1078
1079
def Intersection(
1080
*vmobjects: VMobject,
1081
**kwargs
1082
) -> VMobject:
1083
"""
1084
Boolean intersection of multiple VMobjects.
1085
1086
Creates shape containing only areas covered by all input shapes.
1087
1088
Parameters:
1089
- *vmobjects: VMobjects to intersect
1090
"""
1091
1092
def Difference(
1093
subject: VMobject,
1094
clip: VMobject,
1095
**kwargs
1096
) -> VMobject:
1097
"""
1098
Boolean difference operation (subject minus clip).
1099
1100
Removes the clip shape from the subject shape.
1101
1102
Parameters:
1103
- subject: Base shape to subtract from
1104
- clip: Shape to subtract
1105
"""
1106
1107
def Exclusion(
1108
*vmobjects: VMobject,
1109
**kwargs
1110
) -> VMobject:
1111
"""
1112
Boolean exclusive or of VMobjects.
1113
1114
Creates shape containing areas covered by exactly one input shape
1115
(removes overlapping regions).
1116
1117
Parameters:
1118
- *vmobjects: VMobjects for exclusive or operation
1119
"""
1120
```
1121
1122
### Shape Matchers and Decorations
1123
1124
Utility shapes that automatically size and position themselves relative to other mobjects.
1125
1126
```python { .api }
1127
def SurroundingRectangle(
1128
mobject: Mobject,
1129
color: str = YELLOW,
1130
buff: float = SMALL_BUFF,
1131
corner_radius: float = 0,
1132
**kwargs
1133
) -> Rectangle:
1134
"""
1135
Rectangle that surrounds another mobject.
1136
1137
Automatically sizes to encompass the target mobject with buffer spacing,
1138
useful for highlighting and emphasis.
1139
1140
Parameters:
1141
- mobject: Mobject to surround
1142
- color: Rectangle outline color
1143
- buff: Buffer distance around mobject
1144
- corner_radius: Radius for rounded corners
1145
"""
1146
1147
def BackgroundRectangle(
1148
mobject: Mobject,
1149
color: str = BLACK,
1150
stroke_width: float = 0,
1151
stroke_color: str = BLACK,
1152
fill_opacity: float = 0.75,
1153
buff: float = 0,
1154
**kwargs
1155
) -> Rectangle:
1156
"""
1157
Background rectangle for text or objects.
1158
1159
Creates opaque background behind mobject to improve visibility
1160
over complex backgrounds.
1161
1162
Parameters:
1163
- mobject: Mobject to create background for
1164
- color: Background fill color
1165
- stroke_width: Outline thickness
1166
- stroke_color: Outline color
1167
- fill_opacity: Background opacity
1168
- buff: Buffer around mobject
1169
"""
1170
1171
def Cross(
1172
size: float = 0.5,
1173
stroke_width: float = 6,
1174
stroke_color: str = RED,
1175
**kwargs
1176
) -> VGroup:
1177
"""
1178
Cross or X mark symbol.
1179
1180
Creates intersection of diagonal lines, useful for marking
1181
incorrect answers or indicating removal.
1182
1183
Parameters:
1184
- size: Size of cross arms
1185
- stroke_width: Line thickness
1186
- stroke_color: Line color
1187
"""
1188
1189
def Underline(
1190
mobject: Mobject,
1191
buff: float = SMALL_BUFF,
1192
**kwargs
1193
) -> Line:
1194
"""
1195
Underline decoration for text or objects.
1196
1197
Creates horizontal line positioned below mobject,
1198
automatically sized to match mobject width.
1199
1200
Parameters:
1201
- mobject: Mobject to underline
1202
- buff: Distance below mobject
1203
"""
1204
```
1205
1206
### Labeled Geometry
1207
1208
Geometric shapes with integrated labels and annotations for mathematical diagrams.
1209
1210
```python { .api }
1211
def LabeledDot(
1212
label: str | Mobject,
1213
point: np.ndarray = ORIGIN,
1214
color: str = WHITE,
1215
radius: float = DEFAULT_DOT_RADIUS,
1216
**kwargs
1217
) -> VGroup:
1218
"""
1219
Dot with integrated text label.
1220
1221
Combines dot marker with positioned text label,
1222
useful for marking points in geometric diagrams.
1223
1224
Parameters:
1225
- label: Text or mobject to use as label
1226
- point: Position for dot center
1227
- color: Dot color
1228
- radius: Dot radius
1229
"""
1230
1231
def LabeledLine(
1232
start: np.ndarray,
1233
end: np.ndarray,
1234
label: str | Mobject,
1235
label_position: float = 0.5,
1236
**kwargs
1237
) -> VGroup:
1238
"""
1239
Line segment with integrated label.
1240
1241
Combines line with positioned label, commonly used
1242
for labeled edges in geometric diagrams.
1243
1244
Parameters:
1245
- start: Starting point coordinates
1246
- end: Ending point coordinates
1247
- label: Text or mobject label
1248
- label_position: Position along line for label [0, 1]
1249
"""
1250
1251
def LabeledArrow(
1252
start: np.ndarray,
1253
end: np.ndarray,
1254
label: str | Mobject,
1255
label_position: float = 0.5,
1256
**kwargs
1257
) -> VGroup:
1258
"""
1259
Arrow with integrated label.
1260
1261
Combines directional arrow with positioned label,
1262
useful for labeled vectors and directed edges.
1263
1264
Parameters:
1265
- start: Arrow starting point
1266
- end: Arrow ending point
1267
- label: Text or mobject label
1268
- label_position: Position along arrow for label [0, 1]
1269
"""
1270
1271
def AnnotationDot(
1272
point: np.ndarray = ORIGIN,
1273
radius: float = DEFAULT_SMALL_DOT_RADIUS,
1274
color: str = WHITE,
1275
**kwargs
1276
) -> Dot:
1277
"""
1278
Small dot specifically for annotations and marking points.
1279
1280
Smaller than regular dots, optimized for marking specific
1281
points without dominating the visual presentation.
1282
1283
Parameters:
1284
- point: Position for annotation dot
1285
- radius: Dot radius (smaller than standard)
1286
- color: Dot color
1287
"""
1288
```
1289
1290
### Vector Field Visualization
1291
1292
Specialized mobjects for visualizing vector fields, flow patterns, and field-based mathematical concepts.
1293
1294
```python { .api }
1295
def VectorField(
1296
func: Callable,
1297
x_range: Sequence[float] = None,
1298
y_range: Sequence[float] = None,
1299
z_range: Sequence[float] = None,
1300
delta_x: float = 0.5,
1301
delta_y: float = 0.5,
1302
delta_z: float = 0.5,
1303
min_color_scheme_value: float = 0,
1304
max_color_scheme_value: float = 2,
1305
colors: list[str] = None,
1306
**kwargs
1307
) -> VGroup:
1308
"""
1309
Vector field visualization using arrow arrays.
1310
1311
Creates grid of arrows showing vector field values,
1312
with optional color coding based on vector magnitude.
1313
1314
Parameters:
1315
- func: Vector field function (x,y,z) -> (vx,vy,vz)
1316
- x_range: X coordinate range [min, max, step]
1317
- y_range: Y coordinate range [min, max, step]
1318
- z_range: Z coordinate range [min, max, step]
1319
- delta_x: Spacing between arrows in x direction
1320
- delta_y: Spacing between arrows in y direction
1321
- delta_z: Spacing between arrows in z direction
1322
- min_color_scheme_value: Minimum value for color mapping
1323
- max_color_scheme_value: Maximum value for color mapping
1324
- colors: List of colors for magnitude-based coloring
1325
"""
1326
1327
def StreamLines(
1328
func: Callable,
1329
x_range: Sequence[float] = None,
1330
y_range: Sequence[float] = None,
1331
n_repeats: int = 1,
1332
noise_factor: float = None,
1333
**kwargs
1334
) -> VGroup:
1335
"""
1336
Streamline visualization for vector fields.
1337
1338
Creates flowing curves that follow vector field directions,
1339
showing field flow patterns and trajectories.
1340
1341
Parameters:
1342
- func: Vector field function (x,y) -> (vx,vy)
1343
- x_range: X coordinate range for streamlines
1344
- y_range: Y coordinate range for streamlines
1345
- n_repeats: Number of streamline repetitions
1346
- noise_factor: Random variation in starting positions
1347
"""
1348
1349
def ArrowVectorField(
1350
func: Callable,
1351
color_function: Callable = None,
1352
**kwargs
1353
) -> VGroup:
1354
"""
1355
Arrow-based vector field with customizable coloring.
1356
1357
Enhanced vector field visualization with per-arrow
1358
customization and advanced coloring options.
1359
1360
Parameters:
1361
- func: Vector field function
1362
- color_function: Function determining arrow colors based on field values
1363
"""
1364
```
1365
1366
### Braces and Annotations
1367
1368
Mathematical braces and annotation objects for labeling and grouping elements in diagrams.
1369
1370
```python { .api }
1371
def Brace(
1372
mobject: Mobject,
1373
direction: np.ndarray = DOWN,
1374
buff: float = 0.2,
1375
**kwargs
1376
) -> VMobject:
1377
"""
1378
Curly brace that spans the width or height of a mobject.
1379
1380
Automatically sizes to bracket the specified mobject dimension,
1381
commonly used for mathematical annotations and grouping.
1382
1383
Parameters:
1384
- mobject: Mobject to create brace for
1385
- direction: Direction to place brace (UP, DOWN, LEFT, RIGHT)
1386
- buff: Distance from mobject to brace
1387
"""
1388
1389
def BraceLabel(
1390
mobject: Mobject,
1391
text: str,
1392
brace_direction: np.ndarray = DOWN,
1393
label_constructor: Callable = MathTex,
1394
**kwargs
1395
) -> VGroup:
1396
"""
1397
Brace with integrated text label.
1398
1399
Combines brace with positioned label, streamlining
1400
the creation of labeled mathematical groupings.
1401
1402
Parameters:
1403
- mobject: Mobject to brace and label
1404
- text: Label text content
1405
- brace_direction: Direction for brace placement
1406
- label_constructor: Function to create label (Text, MathTex, etc.)
1407
"""
1408
1409
def BraceBetweenPoints(
1410
point_1: np.ndarray,
1411
point_2: np.ndarray,
1412
direction: np.ndarray = None,
1413
**kwargs
1414
) -> VMobject:
1415
"""
1416
Brace spanning between two specific points.
1417
1418
Creates brace of exact length to span between given points,
1419
useful for measuring or indicating distances.
1420
1421
Parameters:
1422
- point_1: First endpoint for brace span
1423
- point_2: Second endpoint for brace span
1424
- direction: Direction perpendicular to span for brace placement
1425
"""
1426
1427
def ArcBrace(
1428
arc_mobject: Arc | Circle,
1429
direction: np.ndarray = RIGHT,
1430
**kwargs
1431
) -> VMobject:
1432
"""
1433
Curved brace that follows arc or circular shapes.
1434
1435
Creates brace that curves to match arc geometry,
1436
ideal for labeling curved sections and arc measurements.
1437
1438
Parameters:
1439
- arc_mobject: Arc or circular mobject to brace
1440
- direction: Radial direction for brace placement
1441
"""
1442
```
1443
1444
### Advanced Mobjects
1445
1446
Specialized mobject types for complex mathematical visualizations and interactive elements.
1447
1448
```python { .api }
1449
# Tables and matrices
1450
def Table(
1451
table: list[list[str | Mobject]],
1452
row_labels: list[Mobject] = None,
1453
col_labels: list[Mobject] = None,
1454
top_left_entry: Mobject = None,
1455
v_buff: float = 0.8,
1456
h_buff: float = 1.3,
1457
include_outer_lines: bool = False,
1458
add_background_rectangles_to_entries: bool = False,
1459
entries_background_color: str = BLACK,
1460
include_background_rectangle: bool = False,
1461
background_rectangle_color: str = BLACK,
1462
line_config: dict = None,
1463
**kwargs
1464
) -> Table:
1465
"""
1466
Table with customizable formatting and styling.
1467
1468
Parameters:
1469
- table: 2D list of table entries
1470
- row_labels: Labels for rows
1471
- col_labels: Labels for columns
1472
- top_left_entry: Entry for top-left corner
1473
- v_buff: Vertical spacing between entries
1474
- h_buff: Horizontal spacing between entries
1475
- include_outer_lines: Whether to draw outer border
1476
- add_background_rectangles_to_entries: Whether entries have backgrounds
1477
- entries_background_color: Background color for entries
1478
- include_background_rectangle: Whether table has background
1479
- background_rectangle_color: Table background color
1480
- line_config: Configuration for table lines
1481
"""
1482
1483
def Matrix(
1484
matrix: list[list[float | str]] | np.ndarray,
1485
v_buff: float = 0.8,
1486
h_buff: float = 0.8,
1487
bracket_h_buff: float = MED_SMALL_BUFF,
1488
bracket_v_buff: float = MED_SMALL_BUFF,
1489
add_background_rectangles_to_entries: bool = False,
1490
include_background_rectangle: bool = False,
1491
element_to_mobject: Callable = MathTex,
1492
element_to_mobject_config: dict = None,
1493
element_alignment_corner: np.ndarray = DR,
1494
left_bracket: str = "[",
1495
right_bracket: str = "]",
1496
**kwargs
1497
) -> Matrix:
1498
"""
1499
Mathematical matrix with brackets.
1500
1501
Parameters:
1502
- matrix: 2D array or list of matrix entries
1503
- v_buff: Vertical spacing between entries
1504
- h_buff: Horizontal spacing between entries
1505
- bracket_h_buff: Horizontal bracket spacing
1506
- bracket_v_buff: Vertical bracket spacing
1507
- add_background_rectangles_to_entries: Whether entries have backgrounds
1508
- include_background_rectangle: Whether matrix has background
1509
- element_to_mobject: Function to convert entries to mobjects
1510
- element_to_mobject_config: Config for element conversion
1511
- element_alignment_corner: How to align elements in cells
1512
- left_bracket: Left bracket character
1513
- right_bracket: Right bracket character
1514
"""
1515
1516
# Code display
1517
def Code(
1518
file_name: str = None,
1519
code: str = None,
1520
tab_width: int = 3,
1521
line_spacing: float = 0.3,
1522
font_size: float = 24,
1523
font: str = "Monospace",
1524
stroke_width: float = 0,
1525
margin: float = 0.3,
1526
indentation_chars: str = " ",
1527
background: str = "rectangle",
1528
background_stroke_width: float = 1,
1529
background_stroke_color: str = WHITE,
1530
corner_radius: float = 0.2,
1531
insert_line_no: bool = True,
1532
line_no_from: int = 1,
1533
line_no_buff: float = 0.4,
1534
style: str = "vim",
1535
language: str = None,
1536
generate_html_file: bool = False,
1537
warn_missing_font: bool = True,
1538
**kwargs
1539
) -> Code:
1540
"""
1541
Syntax-highlighted code display.
1542
1543
Parameters:
1544
- file_name: Path to source code file
1545
- code: Code string (if not using file)
1546
- tab_width: Width of tab characters
1547
- line_spacing: Spacing between lines
1548
- font_size: Code font size
1549
- font: Font family for code
1550
- stroke_width: Text outline width
1551
- margin: Margin around code block
1552
- indentation_chars: Characters used for indentation
1553
- background: Background type ("rectangle", "window", None)
1554
- background_stroke_width: Background outline width
1555
- background_stroke_color: Background outline color
1556
- corner_radius: Background corner radius
1557
- insert_line_no: Whether to show line numbers
1558
- line_no_from: Starting line number
1559
- line_no_buff: Space between line numbers and code
1560
- style: Syntax highlighting style
1561
- language: Programming language for highlighting
1562
- generate_html_file: Whether to generate HTML file
1563
- warn_missing_font: Whether to warn about missing fonts
1564
"""
1565
1566
# Value tracking
1567
def ValueTracker(
1568
value: float = 0,
1569
**kwargs
1570
) -> ValueTracker:
1571
"""
1572
Invisible mobject that tracks a numeric value for animations.
1573
1574
Used to animate numeric values that control other object properties,
1575
enabling complex parametric animations.
1576
1577
Parameters:
1578
- value: Initial numeric value
1579
"""
1580
1581
def ComplexValueTracker(
1582
value: complex = 0 + 0j,
1583
**kwargs
1584
) -> ComplexValueTracker:
1585
"""
1586
Value tracker for complex numbers.
1587
1588
Parameters:
1589
- value: Initial complex value
1590
"""
1591
```
1592
1593
## Usage Examples
1594
1595
### Basic Shapes and Styling
1596
1597
```python
1598
from manim import *
1599
1600
class ShapesExample(Scene):
1601
def construct(self):
1602
# Create and style basic shapes
1603
circle = Circle(radius=1.5, color=BLUE, fill_opacity=0.5)
1604
square = Square(side_length=2, color=RED, stroke_width=5)
1605
triangle = Triangle(color=GREEN, fill_opacity=0.7)
1606
1607
# Position shapes
1608
shapes = VGroup(circle, square, triangle)
1609
shapes.arrange(RIGHT, buff=1)
1610
1611
# Add to scene
1612
self.add(shapes)
1613
```
1614
1615
### Text and LaTeX
1616
1617
```python
1618
class TextExample(Scene):
1619
def construct(self):
1620
# Regular text
1621
title = Text("Mathematical Animation", font_size=48, color=BLUE)
1622
title.to_edge(UP)
1623
1624
# LaTeX math
1625
equation = MathTex(
1626
r"e^{i\pi} + 1 = 0",
1627
font_size=60,
1628
color=YELLOW
1629
)
1630
1631
# Position and animate
1632
self.play(Write(title))
1633
self.play(Write(equation))
1634
```
1635
1636
### 3D Objects
1637
1638
```python
1639
class ThreeDExample(ThreeDScene):
1640
def construct(self):
1641
# Set 3D camera
1642
self.set_camera_orientation(phi=75*DEGREES, theta=45*DEGREES)
1643
1644
# Create 3D objects
1645
cube = Cube(side_length=2, fill_color=BLUE, fill_opacity=0.7)
1646
sphere = Sphere(radius=1.2, fill_color=RED, fill_opacity=0.8)
1647
1648
# Position objects
1649
cube.shift(LEFT * 2)
1650
sphere.shift(RIGHT * 2)
1651
1652
# Add to scene
1653
self.add(cube, sphere)
1654
1655
# Rotate camera
1656
self.begin_ambient_camera_rotation(rate=0.1)
1657
self.wait(3)
1658
```
1659
1660
### Advanced Combinations
1661
1662
```python
1663
class ComplexExample(Scene):
1664
def construct(self):
1665
# Create matrix
1666
matrix = Matrix([
1667
["a", "b"],
1668
["c", "d"]
1669
], bracket_h_buff=0.1)
1670
1671
# Create table
1672
table_data = [
1673
["x", "y", "f(x,y)"],
1674
["0", "0", "1"],
1675
["1", "0", "2"],
1676
["0", "1", "3"]
1677
]
1678
table = Table(table_data, include_outer_lines=True)
1679
1680
# Create code
1681
code = Code(
1682
code="def fibonacci(n):\n if n <= 1:\n return n\n return fibonacci(n-1) + fibonacci(n-2)",
1683
language="python",
1684
font_size=20
1685
)
1686
1687
# Arrange and display
1688
VGroup(matrix, table, code).arrange(DOWN, buff=0.5).scale(0.8)
1689
self.add(matrix, table, code)
1690
```