# CLI Options Source: https://manimvtk.mathify.dev/advanced/cli-options Complete command-line interface reference ## Basic Usage ```bash theme={null} manimvtk [OPTIONS] FILE [SCENES] ``` ## Quality Options | Option | Description | | ------ | ---------------------------- | | `-ql` | Low quality (480p, 15fps) | | `-qm` | Medium quality (720p, 30fps) | | `-qh` | High quality (1080p, 60fps) | | `-qk` | 4K quality (2160p, 60fps) | ## Output Options | Option | Description | | ------------- | ------------------------- | | `-p` | Preview after rendering | | `-s` | Save last frame as image | | `-a` | Render all scenes in file | | `-o FILENAME` | Output filename | ## Renderer Options | Option | Description | | ------------------------------- | --------------- | | `--renderer {cairo,opengl,vtk}` | Select renderer | ## VTK Export Options | Option | Description | | ------------------- | ------------------------- | | `--vtk-export` | Export final scene to VTK | | `--vtk-time-series` | Export frame-by-frame VTK | ## Examples ```bash theme={null} # High quality with preview manimvtk -pqh scene.py MyScene # VTK export manimvtk -pqh scene.py MyScene --renderer vtk --vtk-export # Time series for ParaView manimvtk -pqm scene.py MyScene --vtk-time-series # All scenes, low quality manimvtk -aql scene.py ``` ## See Also Config file settings Getting started guide # Configuration Source: https://manimvtk.mathify.dev/advanced/configuration Configuring ManimVTK settings ## Configuration File Create `manim.cfg` in your project directory: ```ini theme={null} [CLI] renderer = vtk quality = high frame_rate = 60 background_color = BLACK [output] video_dir = {media_dir}/videos/{module_name}/{quality} vtk_dir = {media_dir}/vtk ``` ## Configuration Options ### CLI Options * `renderer`: cairo, opengl, or vtk * `quality`: low, medium, high, fourk * `frame_rate`: Frames per second * `background_color`: Scene background ### Output Paths * `video_dir`: Where videos are saved * `images_dir`: Where images are saved * `vtk_dir`: Where VTK exports are saved ## Per-Scene Configuration ```python theme={null} class MyScene(Scene): def construct(self): # Access config config.frame_rate = 30 config.background_color = WHITE # Your scene code pass ``` ## See Also Command-line reference Getting started # Custom Animations Source: https://manimvtk.mathify.dev/advanced/custom-animations Creating custom animation classes ## Creating Custom Animations Extend Animation class: ```python theme={null} from manimvtk import * class CustomAnimation(Animation): def interpolate_mobject(self, alpha): # alpha goes from 0 to 1 # Modify self.mobject based on alpha self.mobject.scale(1 + alpha) ``` ## See Also Animation concepts # Custom Mobjects Source: https://manimvtk.mathify.dev/advanced/custom-mobjects Creating custom mobject classes ## Creating Custom Mobjects Extend VMobject or Mobject to create custom shapes: ```python theme={null} from manimvtk import * class CustomStar(VMobject): def __init__(self, points=5, **kwargs): super().__init__(**kwargs) # Define your shape logic angles = np.linspace(0, TAU, points * 2 + 1) vertices = [ [np.cos(a), np.sin(a), 0] * (2 if i % 2 else 1) for i, a in enumerate(angles[:-1]) ] self.set_points_as_corners(vertices) self.close_path() ``` ## See Also Mobjects concepts # Creation Animations Source: https://manimvtk.mathify.dev/api-reference/animations/creation Creation animation reference ## Creation Animations See [Animations Overview](/api-reference/animations/overview) for complete documentation. Complete animations guide # Indication Animations Source: https://manimvtk.mathify.dev/api-reference/animations/indication Indication animation reference ## Indication Animations See [Animations Overview](/api-reference/animations/overview) for complete documentation. Complete animations guide # Movement Animations Source: https://manimvtk.mathify.dev/api-reference/animations/movement Movement animation reference ## Movement Animations See [Animations Overview](/api-reference/animations/overview) for complete documentation. Complete animations guide # Animations Overview Source: https://manimvtk.mathify.dev/api-reference/animations/overview Complete reference for ManimVTK animations ## Animation Categories Create, Write, FadeIn, GrowFromCenter Transform, ReplacementTransform, MoveToTarget Shift, Rotate, Scale Indicate, Flash, Wiggle, Circumscribe ## Playing Animations ```python theme={null} self.play(AnimationClass(mobject, **kwargs)) ``` **Common parameters:** * `run_time` (float): Duration in seconds * `rate_func` (function): Timing function * `lag_ratio` (float): For grouped animations ## The .animate Syntax ```python theme={null} self.play(mobject.animate.method()) ``` **Example:** ```python theme={null} self.play(circle.animate.shift(RIGHT).scale(2).set_color(RED)) ``` ## See Also Conceptual guide Animation examples # Transform Animations Source: https://manimvtk.mathify.dev/api-reference/animations/transform Transform animation reference ## Transform Animations See [Animations Overview](/api-reference/animations/overview) for complete documentation. Complete animations guide # 3D Objects Source: https://manimvtk.mathify.dev/api-reference/mobjects/3d-objects 3D primitives and surfaces reference ## 3D Primitives ### Sphere ```python theme={null} Sphere(radius=1, resolution=(20, 20), **kwargs) ``` Creates a 3D sphere. **Parameters:** * `radius` (float): Sphere radius * `resolution` (tuple): (u\_res, v\_res) mesh resolution **Example:** ```python theme={null} sphere = Sphere(radius=1.5, resolution=(40, 40), color=BLUE) ``` ### Cube ```python theme={null} Cube(side_length=2, **kwargs) ``` ### Cone ```python theme={null} Cone(base_radius=1, height=2, **kwargs) ``` ### Cylinder ```python theme={null} Cylinder(radius=1, height=2, **kwargs) ``` ## Surfaces ### Surface ```python theme={null} Surface( func, u_range=[-1, 1], v_range=[-1, 1], resolution=(10, 10), **kwargs ) ``` Creates a parametric surface. **Parameters:** * `func`: Function (u, v) → \[x, y, z] * `u_range`: Range for parameter u * `v_range`: Range for parameter v * `resolution`: Mesh resolution **Example:** ```python theme={null} import numpy as np surface = Surface( lambda u, v: np.array([u, v, u**2 - v**2]), u_range=[-2, 2], v_range=[-2, 2], resolution=(30, 30) ) ``` ### ParametricSurface ```python theme={null} ParametricSurface(func, **kwargs) ``` ## 3D Axes ### ThreeDAxes ```python theme={null} ThreeDAxes( x_range=[-6, 6, 1], y_range=[-5, 5, 1], z_range=[-4, 4, 1], **kwargs ) ``` ## See Also 3D visualization examples Export 3D objects to VTK # Geometry Source: https://manimvtk.mathify.dev/api-reference/mobjects/geometry 2D geometric shapes reference ## Circles and Ellipses ### Circle ```python theme={null} Circle(radius=1.0, color=WHITE, **kwargs) ``` Creates a circle. **Parameters:** * `radius` (float): Circle radius * `color` (Color): Circle color * `stroke_width` (float): Width of outline * `fill_opacity` (float): Fill transparency (0-1) **Example:** ```python theme={null} circle = Circle(radius=2, color=BLUE, fill_opacity=0.5) ``` ### Ellipse ```python theme={null} Ellipse(width=2, height=1, **kwargs) ``` **Example:** ```python theme={null} ellipse = Ellipse(width=3, height=1.5, color=RED) ``` ## Polygons ### Square ```python theme={null} Square(side_length=2.0, **kwargs) ``` ### Rectangle ```python theme={null} Rectangle(width=4.0, height=2.0, **kwargs) ``` ### Triangle ```python theme={null} Triangle(**kwargs) ``` ### Polygon ```python theme={null} Polygon(*vertices, **kwargs) ``` **Example:** ```python theme={null} pentagon = Polygon( [0, 0, 0], [1, 0, 0], [1.5, 1, 0], [0.5, 1.5, 0], [-0.5, 1, 0], color=GREEN ) ``` ## Lines and Arrows ### Line ```python theme={null} Line(start=LEFT, end=RIGHT, **kwargs) ``` ### Arrow ```python theme={null} Arrow(start=ORIGIN, end=RIGHT, **kwargs) ``` ### Vector ```python theme={null} Vector(direction=RIGHT, **kwargs) ``` **Example:** ```python theme={null} arrow = Arrow(start=LEFT*2, end=RIGHT*2, color=RED) ``` ## Arcs ### Arc ```python theme={null} Arc(radius=1.0, start_angle=0, angle=TAU/4, **kwargs) ``` ### ArcBetweenPoints ```python theme={null} ArcBetweenPoints(start, end, angle=TAU/4, **kwargs) ``` ## Curves ### CubicBezier ```python theme={null} CubicBezier(start, control1, control2, end, **kwargs) ``` ### ParametricCurve ```python theme={null} ParametricCurve(function, t_range=[0, 1], **kwargs) ``` ## See Also All mobject types Geometry examples # Graphs and Coordinates Source: https://manimvtk.mathify.dev/api-reference/mobjects/graphs Coordinate systems, axes, and graphing reference ## Coordinate Systems ### Axes ```python theme={null} Axes( x_range=[-7, 7, 1], y_range=[-5, 5, 1], **kwargs ) ``` 2D coordinate axes. ### NumberPlane ```python theme={null} NumberPlane( x_range=[-10, 10, 1], y_range=[-10, 10, 1], **kwargs ) ``` Grid plane with axes. ### ThreeDAxes ```python theme={null} ThreeDAxes( x_range=[-6, 6, 1], y_range=[-5, 5, 1], z_range=[-4, 4, 1] ) ``` 3D coordinate system. ## Graphing ### Plotting Functions ```python theme={null} axes = Axes(x_range=[-3, 3], y_range=[-2, 2]) graph = axes.plot(lambda x: x**2, color=BLUE) ``` ### Labels ```python theme={null} axes = Axes() labels = axes.get_axis_labels(x_label="x", y_label="f(x)") ``` ## See Also Graphing examples All mobjects # Mobjects Overview Source: https://manimvtk.mathify.dev/api-reference/mobjects/overview Complete reference for Manim Objects (Mobjects) ## Mobject Types ManimVTK provides a rich set of mobject classes for creating visual elements. 2D geometric shapes: Circle, Square, Line, Arc, Polygon, etc. 3D primitives and surfaces: Sphere, Cube, Surface, etc. Text and mathematical equations: Text, Tex, MathTex Coordinate systems, axes, and graphs ## Base Classes ### Mobject The base class for all Manim objects. **Common methods:** * `shift(vector)` - Move relative to current position * `move_to(point)` - Move to absolute position * `scale(factor)` - Scale by factor * `rotate(angle)` - Rotate by angle * `set_color(color)` - Set color * `copy()` - Create a copy ### VMobject Vectorized mobject for 2D shapes. **Additional methods:** * `set_stroke(color, width, opacity)` - Set stroke properties * `set_fill(color, opacity)` - Set fill properties * `get_points()` - Get bezier curve points ### VGroup Container for grouping multiple mobjects. **Methods:** * `add(*mobjects)` - Add mobjects to group * `remove(*mobjects)` - Remove mobjects * `arrange(direction, buff)` - Arrange in a line * `arrange_in_grid(rows, cols, buff)` - Arrange in grid ## Common Patterns ```python theme={null} # Create and style circle = Circle(radius=1, color=BLUE, fill_opacity=0.5) # Transform circle.shift(RIGHT * 2).scale(1.5).rotate(PI/4) # Group shapes = VGroup(circle, Square(), Triangle()) shapes.arrange(RIGHT, buff=1) ``` ## See Also Conceptual guide See examples Animate mobjects # Text and LaTeX Source: https://manimvtk.mathify.dev/api-reference/mobjects/text Text rendering reference ## Text Objects ### Text ```python theme={null} Text(text, font="", font_size=48, **kwargs) ``` Regular text rendering. **Example:** ```python theme={null} text = Text("Hello, World!", font_size=60, color=BLUE) ``` ### MarkupText ```python theme={null} MarkupText(text, **kwargs) ``` Text with markup support (bold, italic, colors). ### Tex ```python theme={null} Tex(*tex_strings, **kwargs) ``` LaTeX text rendering. **Example:** ```python theme={null} formula = Tex(r"E = mc^2") ``` ### MathTex ```python theme={null} MathTex(*tex_strings, **kwargs) ``` Mathematical equations. **Example:** ```python theme={null} equation = MathTex( r"\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}" ) ``` ## See Also Text examples Mobject concepts # Camera Source: https://manimvtk.mathify.dev/api-reference/scene/camera camera API reference ## API Reference See conceptual guides for detailed documentation. Scene concepts Camera control # Moving camera Source: https://manimvtk.mathify.dev/api-reference/scene/moving-camera moving camera API reference ## API Reference See conceptual guides for detailed documentation. Scene concepts Camera control # Scene Source: https://manimvtk.mathify.dev/api-reference/scene/scene scene API reference ## API Reference See conceptual guides for detailed documentation. Scene concepts Camera control # Three d scene Source: https://manimvtk.mathify.dev/api-reference/scene/three-d-scene three d scene API reference ## API Reference See conceptual guides for detailed documentation. Scene concepts Camera control # Scalar fields Source: https://manimvtk.mathify.dev/api-reference/vtk/scalar-fields scalar fields API reference ## API Reference See the VTK documentation for implementation details. VTK features overview VTK export guide # Vector fields Source: https://manimvtk.mathify.dev/api-reference/vtk/vector-fields vector fields API reference ## API Reference See the VTK documentation for implementation details. VTK features overview VTK export guide # Vtk adapter Source: https://manimvtk.mathify.dev/api-reference/vtk/vtk-adapter vtk adapter API reference ## API Reference See the VTK documentation for implementation details. VTK features overview VTK export guide # Vtk exporter Source: https://manimvtk.mathify.dev/api-reference/vtk/vtk-exporter vtk exporter API reference ## API Reference See the VTK documentation for implementation details. VTK features overview VTK export guide # Vtk renderer Source: https://manimvtk.mathify.dev/api-reference/vtk/vtk-renderer vtk renderer API reference ## API Reference See the VTK documentation for implementation details. VTK features overview VTK export guide # Animations Source: https://manimvtk.mathify.dev/concepts/animations Master animation techniques in ManimVTK ## Animation Basics Animations are transformations applied to mobjects over time. ManimVTK provides a rich set of animation classes for creating smooth, beautiful movements and effects. All animations are played using `self.play()` in your scene's `construct()` method ## Playing Animations ### Basic Syntax ```python theme={null} from manimvtk import * class BasicAnimation(Scene): def construct(self): circle = Circle() # Play a single animation self.play(Create(circle)) # Wait (pause animation) self.wait() ``` ### Multiple Animations ```python theme={null} class MultipleAnimations(Scene): def construct(self): c1 = Circle().shift(LEFT) c2 = Square().shift(RIGHT) # Play animations simultaneously self.play( Create(c1), Create(c2) ) # Play sequentially self.play(FadeOut(c1)) self.play(FadeOut(c2)) ``` ### Animation Parameters ```python theme={null} self.play( Create(circle), run_time=2, # Duration in seconds rate_func=smooth # Timing function ) ``` ## Animation Types ### Creation Animations Animations that introduce objects to the scene: Draw the object from start to finish: ```python theme={null} circle = Circle() self.play(Create(circle)) ``` Write text or equations: ```python theme={null} text = Text("Hello, World!") self.play(Write(text)) ``` Fade object into view: ```python theme={null} square = Square() self.play(FadeIn(square)) ``` Grow object from its center: ```python theme={null} circle = Circle() self.play(GrowFromCenter(circle)) ``` ### Removal Animations Animations that remove objects from the scene: Reverse of Create: ```python theme={null} self.play(Uncreate(circle)) ``` Fade object out of view: ```python theme={null} self.play(FadeOut(square)) ``` Shrink to center point: ```python theme={null} self.play(ShrinkToCenter(circle)) ``` ### Transform Animations Transform one object into another: ```python theme={null} class TransformExample(Scene): def construct(self): circle = Circle() square = Square() self.play(Create(circle)) self.wait() # Transform circle into square self.play(Transform(circle, square)) self.wait() ``` **Types of transforms:** * `Transform` - Morph one object into another * `ReplacementTransform` - Replace and morph * `TransformFromCopy` - Create copy that transforms * `ClockwiseTransform` - Transform with rotation ### Movement Animations Move objects around the scene: ```python theme={null} class MovementExample(Scene): def construct(self): circle = Circle() self.add(circle) # Using .animate syntax (recommended) self.play(circle.animate.shift(RIGHT * 3)) self.play(circle.animate.move_to(UP * 2)) # Using explicit animations self.play(circle.animate.to_edge(LEFT)) ``` ### Rotation Animations Rotate objects: ```python theme={null} class RotationExample(Scene): def construct(self): square = Square() self.add(square) # Rotate 90 degrees self.play(Rotate(square, PI / 2)) # Or using .animate self.play(square.animate.rotate(PI / 2)) ``` ### Indication Animations Draw attention to objects: Briefly highlight: ```python theme={null} self.play(Indicate(circle)) ``` Flash effect: ```python theme={null} self.play(Flash(point)) ``` Wiggle animation: ```python theme={null} self.play(Wiggle(text)) ``` Draw attention with shape around object: ```python theme={null} self.play(Circumscribe(equation)) ``` ## The .animate Syntax The most intuitive way to animate transformations: ```python theme={null} class AnimateSyntax(Scene): def construct(self): circle = Circle() self.add(circle) # Chain multiple transformations self.play( circle.animate .shift(RIGHT * 2) .scale(1.5) .set_color(RED) ) ``` **Benefits:** * Readable and intuitive * Supports method chaining * Works with most mobject methods **Examples:** ```python theme={null} # Movement self.play(mob.animate.shift(UP)) self.play(mob.animate.move_to([1, 2, 0])) self.play(mob.animate.to_edge(RIGHT)) # Scaling self.play(mob.animate.scale(2)) self.play(mob.animate.stretch(2, 0)) # Rotation self.play(mob.animate.rotate(PI / 4)) # Color self.play(mob.animate.set_color(BLUE)) self.play(mob.animate.set_opacity(0.5)) # Combination self.play( mob.animate .shift(RIGHT) .rotate(PI / 2) .set_color(RED) ) ``` ## Rate Functions Control the timing and pacing of animations: ```python theme={null} from manimvtk import * class RateFunctions(Scene): def construct(self): circle = Circle() self.add(circle) # Linear (constant speed) self.play(circle.animate.shift(RIGHT), rate_func=linear) # Smooth (ease in and out) self.play(circle.animate.shift(LEFT), rate_func=smooth) # Rush into (accelerate) self.play(circle.animate.shift(UP), rate_func=rush_into) # Rush from (decelerate) self.play(circle.animate.shift(DOWN), rate_func=rush_from) ``` **Common rate functions:** * `linear` - Constant speed * `smooth` - Ease in and out * `rush_into` - Start slow, end fast * `rush_from` - Start fast, end slow * `there_and_back` - Go and return * `running_start` - Build momentum ## Animation Composition ### Succession Animate one after another: ```python theme={null} from manimvtk import Succession self.play( Succession( Create(circle), FadeIn(square), Write(text) ) ) ``` ### AnimationGroup Group animations to play together: ```python theme={null} from manimvtk import AnimationGroup self.play( AnimationGroup( Create(circle), FadeIn(square), lag_ratio=0.5 # Stagger the animations ) ) ``` ### LaggedStart Start animations with a delay: ```python theme={null} from manimvtk import LaggedStart shapes = VGroup(*[Circle() for _ in range(5)]) shapes.arrange(RIGHT) self.play( LaggedStart(*[Create(s) for s in shapes], lag_ratio=0.2) ) ``` ## Advanced Techniques ### Custom Run Time ```python theme={null} # Slow animation self.play(Create(circle), run_time=3) # Fast animation self.play(FadeOut(square), run_time=0.5) ``` ### UpdateFromFunc Animate based on custom function: ```python theme={null} def update_func(mob, alpha): # alpha goes from 0 to 1 mob.move_to(alpha * RIGHT * 3) circle = Circle() self.add(circle) self.play(UpdateFromFunc(circle, update_func)) ``` ### ValueTracker Animate a value over time: ```python theme={null} tracker = ValueTracker(0) def update_circle(circle): circle.move_to(RIGHT * tracker.get_value()) circle = Circle() circle.add_updater(update_circle) self.add(circle) self.play(tracker.animate.set_value(3), run_time=2) ``` ### Updaters Continuous updates during animation: ```python theme={null} def update_text(text): text.next_to(circle.get_center(), UP) circle = Circle() text = Text("Follow me") text.add_updater(update_text) self.add(circle, text) self.play(circle.animate.shift(RIGHT * 3)) ``` ## Animation Timing ### Wait Duration ```python theme={null} # Wait 1 second self.wait() # Wait 2 seconds self.wait(2) # Wait 0.5 seconds self.wait(0.5) ``` ### Controlling Speed ```python theme={null} # Default speed self.play(Create(circle)) # Slow motion (2x slower) self.play(Create(circle), run_time=2) # Fast forward (2x faster) self.play(Create(circle), run_time=0.5) ``` ## Best Practices Choose run times that feel natural: ```python theme={null} # Good - gives viewers time to process self.play(Write(important_equation), run_time=2) self.wait(1) # Too fast - hard to follow self.play(Write(important_equation), run_time=0.2) ``` ```python theme={null} # Good - simultaneous related actions self.play( circle.animate.shift(RIGHT), square.animate.shift(LEFT) ) # Less effective - sequential when simultaneous makes sense self.play(circle.animate.shift(RIGHT)) self.play(square.animate.shift(LEFT)) ``` ```python theme={null} # Smooth for most animations self.play(mob.animate.shift(UP), rate_func=smooth) # Linear for constant motion self.play(mob.animate.shift(RIGHT), rate_func=linear) # Rush for dramatic effect self.play(mob.animate.scale(2), rate_func=rush_into) ``` ```python theme={null} # Preferred - clear and concise self.play(circle.animate.shift(RIGHT).scale(2)) # Avoid - more verbose self.play( ApplyMethod(circle.shift, RIGHT), ApplyMethod(circle.scale, 2) ) ``` ## Common Patterns ### Intro → Content → Outro ```python theme={null} class StandardPattern(Scene): def construct(self): # Intro title = Text("My Topic") self.play(Write(title)) self.wait() self.play(FadeOut(title)) # Content circle = Circle() self.play(Create(circle)) self.play(circle.animate.scale(2)) self.wait() # Outro self.play(FadeOut(circle)) ``` ### Build Up Gradually ```python theme={null} class BuildUp(Scene): def construct(self): elements = VGroup(*[Square() for _ in range(4)]) elements.arrange(RIGHT, buff=0.5) # Add one at a time for elem in elements: self.play(FadeIn(elem)) self.wait(0.3) ``` ### Transform Chain ```python theme={null} class TransformChain(Scene): def construct(self): shapes = [Circle(), Square(), Triangle(), Star()] current = shapes[0] self.play(Create(current)) for next_shape in shapes[1:]: self.wait(0.5) self.play(Transform(current, next_shape)) ``` ## Next Steps Complete animations API Learn about animatable objects Browse animation examples Explore timing functions # Cameras Source: https://manimvtk.mathify.dev/concepts/cameras Understanding and controlling cameras in ManimVTK ## Camera Basics The camera determines what is visible in your scene and from what perspective. ManimVTK provides different camera types for different needs. For 2D scenes, the camera is mostly invisible. For 3D scenes, camera control is essential. ## Camera Types ### 2D Camera (Scene) The default camera for 2D scenes: ```python theme={null} class Basic2D(Scene): def construct(self): circle = Circle() self.play(Create(circle)) # Camera is fixed, looking straight at the XY plane ``` **Characteristics:** * Fixed perspective * Orthographic projection * Default view: looking down Z-axis ### 3D Camera (ThreeDScene) Camera with full 3D control: ```python theme={null} class Basic3D(ThreeDScene): def construct(self): # Set camera angle self.set_camera_orientation( phi=60 * DEGREES, theta=30 * DEGREES ) sphere = Sphere() self.play(Create(sphere)) ``` **Characteristics:** * Adjustable viewing angle * Can rotate around objects * Perspective projection ### Moving Camera (MovingCameraScene) Camera that can zoom and pan in 2D: ```python theme={null} class MovingCamera(MovingCameraScene): def construct(self): square = Square() self.add(square) # Zoom in self.play(self.camera.frame.animate.scale(0.5)) # Pan to the right self.play(self.camera.frame.animate.shift(RIGHT * 2)) ``` ## 3D Camera Control ### Setting Initial Orientation ```python theme={null} class CameraOrientation(ThreeDScene): def construct(self): # Set at the beginning self.set_camera_orientation( phi=75 * DEGREES, # Vertical angle (0 = top view, 90 = side view) theta=-30 * DEGREES, # Horizontal rotation distance=8, # Distance from origin gamma=0 * DEGREES # Camera roll (usually 0) ) # Add objects axes = ThreeDAxes() self.add(axes) ``` **Understanding angles:** * **phi**: Vertical angle from Z-axis (0° = top, 90° = side) * **theta**: Horizontal rotation around Z-axis * **distance**: How far the camera is from the origin * **gamma**: Camera rotation (tilt) ### Animating Camera Movement ```python theme={null} class CameraMovement(ThreeDScene): def construct(self): sphere = Sphere() self.add(sphere) # Initial position self.set_camera_orientation(phi=60 * DEGREES, theta=30 * DEGREES) self.wait() # Move camera self.move_camera( phi=90 * DEGREES, theta=45 * DEGREES, run_time=3 ) self.wait() ``` ### Ambient Camera Rotation Continuous rotation for showcasing 3D objects: ```python theme={null} class AmbientRotation(ThreeDScene): def construct(self): torus = Torus() self.add(torus) # Start rotation self.begin_ambient_camera_rotation(rate=0.2) # Let it rotate for 5 seconds self.wait(5) # Stop rotation self.stop_ambient_camera_rotation() ``` **Rate parameter:** * Positive: Counter-clockwise rotation * Negative: Clockwise rotation * Typical values: 0.1 to 0.3 ### Camera at a Specific Point Point camera at an object: ```python theme={null} class LookAtPoint(ThreeDScene): def construct(self): # Create objects at different locations sphere1 = Sphere().shift(LEFT * 2) sphere2 = Sphere().shift(RIGHT * 2) self.add(sphere1, sphere2) # Look at first sphere self.set_camera_orientation(phi=60 * DEGREES, theta=0) self.wait() # Adjust to look at second sphere self.move_camera(theta=30 * DEGREES, run_time=2) self.wait() ``` ## Moving Camera (2D) ### Frame Control ```python theme={null} class FrameControl(MovingCameraScene): def construct(self): # Get the camera frame frame = self.camera.frame # Create content larger than the frame grid = NumberPlane(x_range=[-10, 10], y_range=[-10, 10]) self.add(grid) # Pan around self.play(frame.animate.shift(RIGHT * 3)) self.play(frame.animate.shift(UP * 2)) # Return to origin self.play(frame.animate.move_to(ORIGIN)) ``` ### Zooming ```python theme={null} class ZoomExample(MovingCameraScene): def construct(self): circle = Circle(radius=0.1) text = Text("Tiny text", font_size=12).next_to(circle, UP, buff=0.1) self.add(circle, text) # Zoom in to see details self.play(self.camera.frame.animate.scale(0.2)) self.wait() # Zoom out self.play(self.camera.frame.animate.scale(5)) self.wait() ``` ### Following Objects ```python theme={null} class FollowObject(MovingCameraScene): def construct(self): dot = Dot() self.add(dot) # Camera follows the dot self.camera.frame.add_updater( lambda m: m.move_to(dot.get_center()) ) # Move the dot around self.play(dot.animate.shift(RIGHT * 5), run_time=3) self.play(dot.animate.shift(UP * 3), run_time=2) # Stop following self.camera.frame.clear_updaters() ``` ## Camera Presets ### Common 3D Views ```python theme={null} class CommonViews(ThreeDScene): def construct(self): axes = ThreeDAxes() self.add(axes) # Top view self.set_camera_orientation(phi=0, theta=0) self.wait() # Front view self.move_camera(phi=90 * DEGREES, theta=0) self.wait() # Side view self.move_camera(phi=90 * DEGREES, theta=90 * DEGREES) self.wait() # Isometric view self.move_camera(phi=60 * DEGREES, theta=45 * DEGREES) self.wait() ``` ### Reset Camera ```python theme={null} # Reset to default position self.set_camera_orientation(phi=0, theta=0, distance=8) # Or in MovingCameraScene self.play(self.camera.frame.animate.move_to(ORIGIN).scale(1)) ``` ## Advanced Techniques ### Camera Along Path ```python theme={null} class CameraPath(ThreeDScene): def construct(self): surface = Sphere() self.add(surface) # Define camera positions positions = [ (60 * DEGREES, 0 * DEGREES), (60 * DEGREES, 90 * DEGREES), (60 * DEGREES, 180 * DEGREES), (60 * DEGREES, 270 * DEGREES), (60 * DEGREES, 360 * DEGREES), ] # Move through positions for phi, theta in positions: self.move_camera(phi=phi, theta=theta, run_time=1.5) ``` ### Combine Zoom and Pan ```python theme={null} class ZoomAndPan(MovingCameraScene): def construct(self): shapes = VGroup(*[Square() for _ in range(9)]) shapes.arrange_in_grid(3, 3, buff=1) self.add(shapes) # Zoom and pan to top-left square self.play( self.camera.frame.animate .scale(0.3) .move_to(shapes[0]) ) self.wait() ``` ### Smooth Camera Transitions ```python theme={null} class SmoothTransition(ThreeDScene): def construct(self): cube = Cube() self.add(cube) # Smooth camera movement with rate function self.set_camera_orientation(phi=60 * DEGREES, theta=0) self.move_camera( phi=90 * DEGREES, theta=180 * DEGREES, run_time=4, rate_func=smooth # Smooth ease in/out ) ``` ## Best Practices * **2D content**: Use standard `Scene` * **3D objects**: Use `ThreeDScene` with good phi/theta * **Detail work**: Use `MovingCameraScene` to zoom ```python theme={null} # Good - slow enough to follow self.move_camera(phi=90 * DEGREES, run_time=3) # Too fast - disorienting self.move_camera(phi=90 * DEGREES, run_time=0.2) ``` Set initial camera position that shows your object well: ```python theme={null} # Good starting point for most 3D objects self.set_camera_orientation(phi=60 * DEGREES, theta=45 * DEGREES) ``` ```python theme={null} # Good - slow rotation for showcase self.begin_ambient_camera_rotation(rate=0.1) # Too fast - nauseating self.begin_ambient_camera_rotation(rate=1.0) ``` ## Camera Configuration ### Via Code ```python theme={null} # In your scene class ConfiguredCamera(ThreeDScene): def construct(self): # Camera settings self.camera.frame_width = 15 self.camera.frame_height = 15 # Your content sphere = Sphere() self.add(sphere) ``` ### Via Config File ```ini theme={null} [camera] frame_width = 15 frame_height = 15 ``` ## Common Patterns ### Orbit Around Object ```python theme={null} class OrbitPattern(ThreeDScene): def construct(self): obj = Torus() self.add(obj) # Set initial position self.set_camera_orientation(phi=60 * DEGREES, theta=0) # Orbit 360 degrees self.move_camera(theta=360 * DEGREES, run_time=8) ``` ### Zoom to Detail ```python theme={null} class ZoomToDetail(MovingCameraScene): def construct(self): # Large scene full_scene = VGroup(*[Circle() for _ in range(20)]) full_scene.arrange_in_grid(4, 5) self.add(full_scene) self.wait() # Zoom to one element target = full_scene[5] self.play( self.camera.frame.animate .scale(0.2) .move_to(target) ) self.wait() ``` ### Pan Across Scene ```python theme={null} class PanAcross(MovingCameraScene): def construct(self): # Create wide content content = VGroup( Text("Part 1").shift(LEFT * 6), Text("Part 2"), Text("Part 3").shift(RIGHT * 6) ) self.add(content) # Pan from left to right self.camera.frame.move_to(LEFT * 6) self.play( self.camera.frame.animate.move_to(ORIGIN), run_time=3 ) self.play( self.camera.frame.animate.move_to(RIGHT * 6), run_time=3 ) ``` ## Next Steps Learn about different rendering backends ThreeDScene API reference See camera control examples VTK rendering for 3D # Mobjects Source: https://manimvtk.mathify.dev/concepts/mobjects Understanding and working with Manim objects (Mobjects) ## What are Mobjects? **Mobjects** (Manim Objects) are the visual elements in your scenes - everything you see in a ManimVTK animation is a mobject: * Geometric shapes (circles, squares, polygons) * 3D objects (spheres, cubes, surfaces) * Text and mathematical equations * Graphs, plots, and coordinate systems * Custom drawn paths Mobjects are the building blocks of ManimVTK - understanding them is key to creating great animations ## Mobject Hierarchy ``` Mobject (base class) ├── VMobject (vectorized 2D shapes) │ ├── Circle, Square, Triangle │ ├── Line, Arrow, Vector │ ├── Text, Tex, MathTex │ └── Polygon, Rectangle ├── ThreeDMobject (3D objects) │ ├── Sphere, Cube, Cone │ ├── Surface, ParametricSurface │ └── Prism, Cylinder, Torus └── VGroup (container for grouping) ``` ## Creating Mobjects ### Basic 2D Shapes ```python theme={null} from manimvtk import * class BasicShapes(Scene): def construct(self): # Circle circle = Circle(radius=1, color=BLUE) # Square square = Square(side_length=2, color=RED) # Triangle triangle = Triangle(color=GREEN) # Rectangle rectangle = Rectangle(width=3, height=1.5, color=YELLOW) # Arrange and display shapes = VGroup(circle, square, triangle, rectangle) shapes.arrange(RIGHT, buff=0.5) self.play(Create(shapes)) self.wait() ``` ### Basic 3D Objects ```python theme={null} from manimvtk import * class Basic3DObjects(ThreeDScene): def construct(self): # Sphere sphere = Sphere(radius=1, color=BLUE) # Cube cube = Cube(side_length=1.5, color=RED) # Cone cone = Cone(base_radius=0.5, height=1, color=GREEN) # Arrange objects = VGroup(sphere, cube, cone) objects.arrange(RIGHT, buff=1.5) self.set_camera_orientation(phi=60 * DEGREES, theta=30 * DEGREES) self.play(Create(objects)) self.wait() ``` ### Text and Math ```python theme={null} from manimvtk import * class TextAndMath(Scene): def construct(self): # Regular text text = Text("Hello, ManimVTK!", font_size=48) # Mathematical equation equation = MathTex(r"E = mc^2") # Arrange vertically VGroup(text, equation).arrange(DOWN, buff=1) self.play(Write(text)) self.play(Write(equation)) self.wait() ``` ## Mobject Properties ### Color ```python theme={null} # Set color at creation circle = Circle(color=BLUE) # Set color after creation circle.set_color(RED) # Gradient color square = Square() square.set_color_by_gradient(BLUE, RED) # RGB values circle.set_color(rgb_to_color([0.5, 0.7, 0.9])) ``` ### Opacity ```python theme={null} # Stroke opacity (outline) circle.set_stroke(opacity=0.8) # Fill opacity (interior) circle.set_fill(opacity=0.5) # Overall opacity circle.set_opacity(0.7) ``` ### Size ```python theme={null} # Scale circle.scale(2) # 2x larger circle.scale(0.5) # Half size # Set specific dimensions rectangle.width = 3 rectangle.height = 2 # Stretch in one direction square.stretch(2, 0) # Stretch horizontally ``` ### Position ```python theme={null} # Shift (relative movement) circle.shift(RIGHT * 2) circle.shift(UP + LEFT) # Move to absolute position circle.move_to(ORIGIN) circle.move_to([1, 2, 0]) # Align circle.to_edge(LEFT) circle.to_corner(UR) # Upper right ``` ### Rotation ```python theme={null} # Rotate around center square.rotate(PI / 4) # 45 degrees # Rotate around a point square.rotate(PI / 4, about_point=ORIGIN) # Rotate around axis (3D) cube.rotate(PI / 2, axis=UP) ``` ## Styling Mobjects ### Stroke (Outline) ```python theme={null} circle = Circle() # Stroke color circle.set_stroke(color=BLUE) # Stroke width circle.set_stroke(width=5) # Combine circle.set_stroke(color=BLUE, width=3, opacity=0.8) ``` ### Fill (Interior) ```python theme={null} square = Square() # Fill color square.set_fill(color=RED) # Fill opacity square.set_fill(opacity=0.5) # Combine square.set_fill(color=RED, opacity=0.7) ``` ### Combining Stroke and Fill ```python theme={null} # Circle with blue fill and red outline circle = Circle() circle.set_fill(BLUE, opacity=0.5) circle.set_stroke(RED, width=3) ``` ## Grouping Mobjects ### VGroup Group multiple mobjects together: ```python theme={null} # Create individual shapes c1 = Circle() c2 = Square() c3 = Triangle() # Group them group = VGroup(c1, c2, c3) # Operations on group affect all members group.arrange(RIGHT, buff=1) group.set_color(BLUE) group.scale(0.5) ``` ### Arrangement ```python theme={null} shapes = VGroup(*[Circle() for _ in range(6)]) # Arrange in a row shapes.arrange(RIGHT, buff=0.5) # Arrange in a column shapes.arrange(DOWN, buff=0.5) # Arrange in a grid shapes.arrange_in_grid(rows=2, cols=3, buff=0.5) # Arrange in a circle shapes.arrange_in_circle() ``` ## Copying Mobjects ```python theme={null} # Simple copy circle1 = Circle() circle2 = circle1.copy() # Copy and modify circle2.shift(RIGHT * 2) circle2.set_color(RED) # Deep copy (for complex objects) import copy complex_group = VGroup(...) copy_of_group = copy.deepcopy(complex_group) ``` ## Mobject Methods ### Common Methods Get the center point: ```python theme={null} center = circle.get_center() print(center) # [x, y, z] ``` Get dimensions: ```python theme={null} width = rectangle.get_width() height = rectangle.get_height() ``` Get current color: ```python theme={null} color = circle.get_color() ``` Rotate the mobject: ```python theme={null} square.rotate(PI / 4) ``` Scale the mobject: ```python theme={null} circle.scale(2) # Double size ``` Move relative to current position: ```python theme={null} circle.shift(RIGHT * 2 + UP) ``` ### Alignment Methods ```python theme={null} # Align to edges mobject.to_edge(UP) mobject.to_edge(LEFT) # Align to corners mobject.to_corner(UL) # Upper left mobject.to_corner(DR) # Down right # Align relative to other mobject circle.next_to(square, RIGHT) circle.next_to(square, DOWN, buff=0.5) # Move to specific position mobject.move_to(ORIGIN) mobject.move_to([1, 2, 0]) ``` ## Custom Mobjects ### Creating Custom Shapes ```python theme={null} from manimvtk import * class CustomStar(VMobject): def __init__(self, **kwargs): super().__init__(**kwargs) # Define your custom shape points = [...] # Define points self.set_points_as_corners(points) ``` ### Using Paths ```python theme={null} # Custom path path = VMobject() path.set_points_as_corners([ ORIGIN, UP, UP + RIGHT, RIGHT ]) path.set_stroke(BLUE, width=3) ``` ## Surfaces and Parametric Objects ### Parametric Surface ```python theme={null} from manimvtk import * import numpy as np class ParametricSurfaceExample(ThreeDScene): def construct(self): surface = Surface( lambda u, v: np.array([ u, v, np.sin(u) * np.cos(v) ]), u_range=[-2, 2], v_range=[-2, 2], resolution=(30, 30) ) surface.set_color_by_gradient(BLUE, GREEN, RED) self.set_camera_orientation(phi=60 * DEGREES) self.play(Create(surface)) self.wait() ``` ### Common Parametric Surfaces ```python theme={null} # Torus torus = Surface( lambda u, v: np.array([ (2 + np.cos(v)) * np.cos(u), (2 + np.cos(v)) * np.sin(u), np.sin(v) ]), u_range=[0, TAU], v_range=[0, TAU] ) # Sphere (parametric) sphere = Surface( lambda u, v: np.array([ np.cos(u) * np.cos(v), np.sin(u) * np.cos(v), np.sin(v) ]), u_range=[0, TAU], v_range=[-PI/2, PI/2] ) ``` ## Best Practices Set properties when creating: ```python theme={null} # Good circle = Circle(radius=2, color=BLUE, fill_opacity=0.5) # Less efficient circle = Circle() circle.scale(2) circle.set_color(BLUE) circle.set_fill(opacity=0.5) ``` ```python theme={null} # Good - reuse and transform circle = Circle() self.play(Create(circle)) self.play(circle.animate.shift(RIGHT)) # Avoid - creating new objects circle1 = Circle() self.play(Create(circle1)) circle2 = Circle().shift(RIGHT) self.play(Transform(circle1, circle2)) ``` ```python theme={null} # Organize related objects axes_group = VGroup(x_axis, y_axis, labels) data_group = VGroup(points, lines, curves) # Easy to manipulate together axes_group.shift(LEFT * 3) data_group.set_color(BLUE) ``` Define color schemes: ```python theme={null} PRIMARY = BLUE SECONDARY = RED ACCENT = YELLOW title = Text("Title", color=PRIMARY) shape = Circle(color=SECONDARY) highlight = Square(color=ACCENT) ``` ## Next Steps Learn how to animate mobjects Complete geometry API reference Complete 3D objects API See mobject examples # Renderers Source: https://manimvtk.mathify.dev/concepts/renderers Understanding ManimVTK's rendering backends ## Renderer Overview ManimVTK supports three rendering backends, each optimized for different use cases: **2D Vector Graphics** Best for 2D animations and diagrams **3D Hardware Acceleration** Fast real-time 3D rendering **Scientific Visualization** High-quality 3D with VTK export ## Selecting a Renderer ### Via Command Line ```bash theme={null} # Cairo (default) manimvtk -pqh scene.py MyScene # OpenGL manimvtk -pqh scene.py MyScene --renderer opengl # VTK manimvtk -pqh scene.py MyScene --renderer vtk ``` ### Via Configuration In `manim.cfg`: ```ini theme={null} [CLI] renderer = vtk ``` ## Cairo Renderer The default renderer, based on the Cairo graphics library. ### Characteristics * ✅ **Excellent 2D quality**: Sharp vector graphics * ✅ **Text rendering**: High-quality text and LaTeX * ✅ **Mature and stable**: Well-tested, minimal bugs * ⚠️ **2D focused**: Basic 3D support only * ⚠️ **CPU-based**: No GPU acceleration ### Best For * 2D mathematical animations * Educational diagrams * Text-heavy content * Precise vector graphics ### Example ```python theme={null} from manimvtk import * class CairoExample(Scene): def construct(self): # Perfect for 2D equation = MathTex(r"e^{i\pi} + 1 = 0") self.play(Write(equation)) self.wait() ``` ```bash theme={null} # Render with Cairo (default) manimvtk -pqh scene.py CairoExample ``` ## OpenGL Renderer Hardware-accelerated rendering using OpenGL. ### Characteristics * ✅ **Fast**: GPU-accelerated * ✅ **Real-time preview**: Interactive viewing * ✅ **3D support**: Good 3D capabilities * ⚠️ **Less mature**: May have edge cases * ⚠️ **Platform-dependent**: Requires OpenGL drivers ### Best For * Interactive development * Real-time previews * 3D animations (lighter-weight than VTK) * Fast iteration ### Example ```python theme={null} from manimvtk import * class OpenGLExample(ThreeDScene): def construct(self): sphere = Sphere() self.set_camera_orientation(phi=60 * DEGREES) self.play(Create(sphere)) self.wait() ``` ```bash theme={null} # Render with OpenGL manimvtk -pqh scene.py OpenGLExample --renderer opengl ``` ## VTK Renderer Scientific visualization renderer with VTK export capabilities. ### Characteristics * ✅ **Scientific quality**: Publication-grade 3D * ✅ **VTK export**: Export to .vtp, .vtm, .pvd formats * ✅ **Advanced lighting**: Realistic shading * ✅ **ParaView integration**: Direct export to ParaView * ⚠️ **Slower startup**: VTK initialization overhead * ⚠️ **3D focused**: Best for 3D content ### Best For * Scientific visualization * 3D surfaces and meshes * CFD/FEA visualization * ParaView workflows * High-quality 3D renders ### Example ```python theme={null} from manimvtk import * import numpy as np class VTKExample(ThreeDScene): def construct(self): surface = Surface( lambda u, v: np.array([u, v, np.sin(u) * np.cos(v)]), u_range=[-2, 2], v_range=[-2, 2], resolution=(50, 50) ) surface.set_color_by_gradient(BLUE, RED) self.set_camera_orientation(phi=60 * DEGREES) self.play(Create(surface)) self.wait() ``` ```bash theme={null} # Render with VTK and export manimvtk -pqh scene.py VTKExample --renderer vtk --vtk-export ``` Detailed guide on VTK renderer features ## Renderer Comparison | Feature | Cairo | OpenGL | VTK | | -------------------- | ----------- | ----------- | --------- | | **2D Quality** | ⭐⭐⭐ | ⭐⭐ | ⭐⭐ | | **3D Quality** | ⭐ | ⭐⭐ | ⭐⭐⭐ | | **Performance** | ⭐⭐ | ⭐⭐⭐ | ⭐⭐ | | **Text/LaTeX** | ⭐⭐⭐ | ⭐⭐ | ⭐⭐ | | **Stability** | ⭐⭐⭐ | ⭐⭐ | ⭐⭐⭐ | | **Export Formats** | Image/Video | Image/Video | VTK Files | | **GPU Acceleration** | ❌ | ✅ | ✅ | | **Scientific Use** | ⭐ | ⭐⭐ | ⭐⭐⭐ | ## Choosing the Right Renderer ### Decision Tree ``` Are you creating 2D content? ├─ Yes → Use Cairo └─ No (3D content) ├─ Need VTK export? │ └─ Yes → Use VTK └─ Need fast preview? ├─ Yes → Use OpenGL └─ Need highest quality → Use VTK ``` ### Use Cases **Recommendation: Cairo** Most educational content is 2D: * Equations and text * 2D graphs * Geometric diagrams ```bash theme={null} manimvtk -pqh lesson.py Lecture ``` **Recommendation: VTK** Scientific work needs VTK export: * Surface meshes * CFD data * ParaView integration ```bash theme={null} manimvtk -pqh simulation.py CFDViz --renderer vtk --vtk-export ``` **Recommendation: OpenGL or VTK** 3D demonstrations: * Product visualizations * Architecture * Mathematical surfaces ```bash theme={null} # Fast preview manimvtk -pql demo.py Product --renderer opengl # Final quality manimvtk -pqh demo.py Product --renderer vtk ``` **Recommendation: OpenGL (low quality)** Fast iteration: * Testing animations * Debugging layouts * Quick previews ```bash theme={null} manimvtk -ql test.py TestScene --renderer opengl ``` ## Renderer-Specific Features ### Cairo Only * **Precise 2D rendering**: Perfect for diagrams * **Text shaping**: Advanced typography * **SVG-like quality**: Clean vector output ### OpenGL Only * **Interactive preview**: Real-time interaction * **Fast rendering**: GPU acceleration * **Window mode**: Live preview window ### VTK Only * **VTK file export**: .vtp, .vtm, .pvd formats * **Scientific data**: Scalar/vector fields * **Advanced shading**: Physically-based rendering * **ParaView compatibility**: Direct export ## Switching Renderers You can use different renderers for the same scene: ```python theme={null} class UniversalScene(ThreeDScene): def construct(self): sphere = Sphere() self.set_camera_orientation(phi=60 * DEGREES) self.play(Create(sphere)) self.wait() ``` ```bash theme={null} # Test with OpenGL (fast) manimvtk -ql scene.py UniversalScene --renderer opengl # Final render with VTK (quality) manimvtk -qh scene.py UniversalScene --renderer vtk --vtk-export # Alternative with Cairo (if 2D is enough) manimvtk -qh scene.py UniversalScene ``` ## Performance Considerations ### Cairo * **Startup**: Fast * **Rendering**: Moderate (CPU-bound) * **Memory**: Low to moderate * **Best for**: Small to medium 2D scenes ### OpenGL * **Startup**: Moderate * **Rendering**: Fast (GPU-accelerated) * **Memory**: Moderate * **Best for**: Large 3D scenes, development ### VTK * **Startup**: Slow (VTK initialization) * **Rendering**: Moderate to slow * **Memory**: Higher (complex meshes) * **Best for**: Final quality renders, export ## Troubleshooting **Cause:** OpenGL drivers not available **Solution:** ```bash theme={null} # On headless servers xvfb-run -a manimvtk -pqh scene.py MyScene --renderer opengl # Or use Cairo/VTK instead manimvtk -pqh scene.py MyScene --renderer cairo ``` **Cause:** VTK not installed **Solution:** ```bash theme={null} pip install vtk # Or reinstall with VTK extras pip install manimvtk[vtk] ``` **Cause:** Cairo is optimized for 2D **Solution:** Switch to VTK or OpenGL for 3D: ```bash theme={null} manimvtk -pqh scene.py MyScene --renderer vtk ``` **Cause:** Complex geometry or wrong renderer **Solution:** * Use lower quality for testing: `-ql` * Use OpenGL for faster preview * Reduce geometry resolution ## Best Practices ```bash theme={null} # Testing - fast manimvtk -ql scene.py Test --renderer opengl # Final 2D - quality manimvtk -qh scene.py Final # Final 3D with export - quality + export manimvtk -qh scene.py Final --renderer vtk --vtk-export ``` Most code works across all renderers: ```python theme={null} # This works with any renderer class AgnosticScene(Scene): def construct(self): circle = Circle() self.play(Create(circle)) ``` Verify your scene works across renderers: ```bash theme={null} manimvtk -ql scene.py Test --renderer cairo manimvtk -ql scene.py Test --renderer opengl manimvtk -ql scene.py Test --renderer vtk ``` ## Next Steps Detailed VTK renderer guide Learn about VTK file export Configure renderer settings All command-line options # Scenes Source: https://manimvtk.mathify.dev/concepts/scenes Understanding scenes and the construct method in ManimVTK ## What is a Scene? A **Scene** is the fundamental building block of ManimVTK. It's a container for your animation that manages: * **Mobjects** (visual objects) * **Animations** (movements and transformations) * **Camera** (viewpoint and perspective) * **Rendering** (video output and VTK export) Every ManimVTK animation starts with a scene class. ## Basic Scene Structure ```python theme={null} from manimvtk import * class MyScene(Scene): def construct(self): # Your animation code goes here pass ``` **Key components:** 1. **Import**: `from manimvtk import *` 2. **Class definition**: Inherit from `Scene` 3. **construct() method**: Where you build your animation ## The construct() Method The `construct()` method is where all your animation logic lives: ```python theme={null} class SimpleAnimation(Scene): def construct(self): # Create objects circle = Circle(radius=1, color=BLUE) # Add to scene self.add(circle) # Animate self.play(circle.animate.scale(2)) # Wait self.wait() ``` The `construct()` method is called automatically when you render the scene ## Scene Types ManimVTK provides several scene types for different use cases: **Basic 2D scene** - Default scene type ```python theme={null} class Basic2D(Scene): def construct(self): square = Square() self.play(Create(square)) ``` **Use for:** * 2D animations * Graphs and plots * Educational diagrams **3D scene with camera controls** ```python theme={null} class Basic3D(ThreeDScene): def construct(self): # Set camera angle self.set_camera_orientation(phi=60 * DEGREES, theta=30 * DEGREES) # Add 3D object sphere = Sphere() self.play(Create(sphere)) ``` **Use for:** * 3D visualizations * Surfaces and parametric objects * Scientific simulations **Scene with movable camera** ```python theme={null} class CameraMove(MovingCameraScene): def construct(self): square = Square() self.add(square) # Zoom in self.play(self.camera.frame.animate.scale(0.5)) ``` **Use for:** * Zooming animations * Pan and scan effects * Focus on details **Scene with picture-in-picture zoom** ```python theme={null} class ZoomExample(ZoomedScene): def construct(self): # Main content dots = VGroup(*[Dot() for _ in range(10)]).arrange_in_grid() self.add(dots) # Create zoomed camera zoomed_camera = self.zoomed_camera # Activate zoom self.activate_zooming() ``` **Use for:** * Detail views * Magnification effects * Complex diagrams ## Adding Objects to a Scene ### Using add() Instantly add objects without animation: ```python theme={null} class AddExample(Scene): def construct(self): circle = Circle() square = Square() # Add instantly (no animation) self.add(circle, square) self.wait() ``` ### Using play() Add objects with animation: ```python theme={null} class PlayExample(Scene): def construct(self): circle = Circle() # Add with creation animation self.play(Create(circle)) self.wait() ``` ### Adding Multiple Objects ```python theme={null} class MultipleObjects(Scene): def construct(self): # Create a group shapes = VGroup( Circle(), Square(), Triangle() ).arrange(RIGHT, buff=1) # Add all at once self.play(Create(shapes)) self.wait() ``` ## Scene Methods ### Animation Control Play one or more animations: ```python theme={null} self.play(Create(circle)) self.play(Transform(square, circle)) # Multiple animations simultaneously self.play( Create(circle), FadeIn(text) ) ``` Pause the animation: ```python theme={null} self.wait() # Wait 1 second (default) self.wait(2) # Wait 2 seconds self.wait(0.5) # Wait 0.5 seconds ``` Add objects without animation: ```python theme={null} self.add(circle) self.add(square, triangle) # Multiple objects ``` Remove objects from scene: ```python theme={null} self.remove(circle) self.remove(square, triangle) ``` ### Camera Control (ThreeDScene) Set the initial camera position: ```python theme={null} self.set_camera_orientation( phi=60 * DEGREES, # Vertical angle theta=30 * DEGREES, # Horizontal angle distance=8 # Distance from origin ) ``` Start continuous camera rotation: ```python theme={null} self.begin_ambient_camera_rotation(rate=0.1) self.wait(5) # Rotate for 5 seconds self.stop_ambient_camera_rotation() ``` Animate camera movement: ```python theme={null} self.move_camera( phi=75 * DEGREES, theta=45 * DEGREES, run_time=2 ) ``` ## Scene Lifecycle Understanding the order of operations: ```python theme={null} class LifecycleExample(Scene): def construct(self): # 1. Object creation circle = Circle() # 2. Add to scene (instant) self.add(circle) # 3. Animations self.play(circle.animate.scale(2)) # 4. Wait/pause self.wait() # 5. More animations self.play(FadeOut(circle)) # 6. Scene ends (automatic rendering) ``` **Rendering process:** 1. `construct()` method executes 2. Animations are recorded 3. Frames are generated 4. Video is encoded 5. VTK export (if requested) ## Configuration ### In Scene Class ```python theme={null} class ConfiguredScene(Scene): def construct(self): # Access config print(f"Frame rate: {config.frame_rate}") print(f"Resolution: {config.pixel_width}x{config.pixel_height}") # Your animation circle = Circle() self.play(Create(circle)) ``` ### Via Command Line ```bash theme={null} # Set quality manimvtk -qh scene.py MyScene # High quality # Set frame rate manimvtk -r 60 scene.py MyScene # 60 fps # Set resolution manimvtk --resolution 1920,1080 scene.py MyScene ``` ### Via Config File Create `manim.cfg`: ```ini theme={null} [CLI] quality = high frame_rate = 60 background_color = BLACK ``` ## Common Patterns ### Simple Animation ```python theme={null} class SimplePattern(Scene): def construct(self): # Create → Animate → Remove obj = Circle() self.play(Create(obj)) self.play(obj.animate.shift(RIGHT)) self.play(FadeOut(obj)) ``` ### Sequential Animations ```python theme={null} class Sequential(Scene): def construct(self): objs = VGroup(*[Circle() for _ in range(3)]) objs.arrange(RIGHT, buff=1) # Animate one by one for obj in objs: self.play(Create(obj)) self.wait() ``` ### Simultaneous Animations ```python theme={null} class Simultaneous(Scene): def construct(self): c1 = Circle().shift(LEFT) c2 = Circle().shift(RIGHT) # Both at the same time self.play( Create(c1), Create(c2) ) ``` ### Build Up and Transform ```python theme={null} class BuildAndTransform(Scene): def construct(self): # Build up circle = Circle() self.play(Create(circle)) # Transform square = Square() self.play(Transform(circle, square)) # Continue with transformed object self.play(circle.animate.rotate(PI/4)) ``` ## Best Practices Break complex scenes into helper methods: ```python theme={null} class OrganizedScene(Scene): def construct(self): self.intro() self.main_content() self.outro() def intro(self): title = Text("Introduction") self.play(Write(title)) self.wait() self.play(FadeOut(title)) def main_content(self): # Main animation logic pass def outro(self): # Closing pass ``` ```python theme={null} # Good class QuadraticFunction(Scene): pass # Avoid class Test1(Scene): pass ``` Give viewers time to process: ```python theme={null} self.play(Create(important_diagram)) self.wait(2) # Let viewers see it self.play(FadeOut(important_diagram)) ``` ```python theme={null} # Efficient circle = Circle() self.play(Create(circle)) self.play(circle.animate.shift(RIGHT)) # Less efficient circle1 = Circle() self.play(Create(circle1)) circle2 = circle1.copy().shift(RIGHT) self.play(Transform(circle1, circle2)) ``` ## Debugging Scenes ### Print Debug Info ```python theme={null} class DebugScene(Scene): def construct(self): circle = Circle() # Debug output print(f"Circle center: {circle.get_center()}") print(f"Circle color: {circle.get_color()}") self.add(circle) ``` ### Preview Frames ```bash theme={null} # Save last frame only (fast) manimvtk -s scene.py MyScene # Save all frames manimvtk --save_sections scene.py MyScene ``` ### Use Lower Quality for Testing ```bash theme={null} # Fast preview manimvtk -ql scene.py MyScene # Final render manimvtk -qh scene.py MyScene ``` ## Next Steps Learn about creating and manipulating objects Master animation techniques Control camera movement and perspective Browse example scenes # Animation Examples Source: https://manimvtk.mathify.dev/examples/animations Advanced animation techniques and patterns ## Animation Patterns Master common animation patterns used in ManimVTK projects. ## Transformation Chains ```python theme={null} from manimvtk import * class TransformChain(Scene): def construct(self): # Start with a circle shapes = [ Circle(color=BLUE), Square(color=GREEN), Triangle(color=RED), Star(color=YELLOW) ] current = shapes[0] self.play(Create(current)) # Transform through each shape for next_shape in shapes[1:]: self.wait(0.5) self.play(Transform(current, next_shape)) self.wait() ``` ## Lagged Animations ```python theme={null} from manimvtk import * class LaggedExample(Scene): def construct(self): squares = VGroup(*[ Square(side_length=0.5).shift(RIGHT * i) for i in range(-3, 4) ]) # Staggered creation self.play( LaggedStart(*[Create(s) for s in squares], lag_ratio=0.15) ) self.wait() # Staggered color change self.play( LaggedStart(*[s.animate.set_color(RED) for s in squares], lag_ratio=0.1) ) self.wait() ``` ## Value Tracking ```python theme={null} from manimvtk import * class ValueTrackingExample(Scene): def construct(self): # Create a tracker tracker = ValueTracker(0) # Create object that follows tracker dot = Dot() dot.add_updater(lambda m: m.move_to([tracker.get_value(), 0, 0])) self.add(dot) # Animate tracker value self.play(tracker.animate.set_value(3), run_time=2) self.play(tracker.animate.set_value(-3), run_time=2) self.play(tracker.animate.set_value(0), run_time=1) ``` ## Next Steps Complete animations guide Animations API reference # Basic 2D Examples Source: https://manimvtk.mathify.dev/examples/basic-2d Simple 2D shape and animation examples ## Introduction Start with these basic 2D examples to learn ManimVTK fundamentals. These examples use the default Cairo renderer and are perfect for beginners. ## Simple Shapes ### Circle Example ```python theme={null} from manimvtk import * class CircleExample(Scene): def construct(self): circle = Circle(radius=2, color=BLUE, fill_opacity=0.5) self.play(Create(circle)) self.wait() ```