Dynamic optics for Manim — build scenes where light behaves like a living part of the animation rather than a static overlay.
manim_optics provides thin lenses, mirrors, apertures, beam stops, composite optical systems, 3D optics, and reactive rays that recompute their trajectories automatically while your scene is in motion.
- Rays are live objects.
DynamicRayandRayBundlerecalculate their path at every frame — move a lens, change a focal length, or insert a new element and the light follows immediately. - Trackers drive optics. Focal length, pupil diameter, tilt angle, aperture radius — all animatable via
ValueTrackerwhile ray tracing stays coherent. - Classroom-ready visuals. Converging/diverging arrow tips on lenses and mirrors, hatching conventions, focal point dots, principal plane labels — everything matches standard optics diagrams.
- Stays close to Manim. Optical elements are
VGroupsubclasses; scenes stay short and Manim-idiomatic.
| Category | Classes |
|---|---|
| Thin lenses | ThinLens, ConvergingLens, DivergingLens |
| Real lenses | SphericalLens |
| Mirrors | PlaneMirror, SphericalMirror |
| Stops & apertures | LineBeamStop, CircularAperture, ArcBeamStop |
| Reactive rays | DynamicRay, RayBundle, PrincipalRays |
| Composite systems | Eye, CenteredSystem |
| 3D optics | OpticalElement3D, ThinLens3D, RayBundle3D |
| Measurement overlays | LinearGraticule, CrossGraticule, GridGraticule |
| Image analysis | ImageFormation, ImageMarker, RayExtension, find_focal_point_from_rays |
manim_optics builds on Manim Community (manim >= 0.20.0). Install Manim first following the official guide, then:
git clone https://github.com/<your-account>/manim_optics.git
cd manim_optics
pip install -e .import numpy as np
from manim import *
from manim_optics import OpticalScene, ConvergingLens, create_parallel_bundle
class QuickStart(OpticalScene):
def construct(self):
self.play(self.get_optical_axis_animation())
lens = ConvergingLens(focal_length=2.0, height=3.0)
rays = create_parallel_bundle(
num_rays=7,
spacing=0.4,
start_x=-5.0,
optical_elements=[lens],
color=YELLOW,
stroke_width=2,
)
self.play(Create(lens))
self.play(rays.animate_propagation(run_time=1.6))
self.wait()Parallel and diverging bundles with y_offset_tracker and angle_offset_tracker, plus a Mobject-tracked source.
ConvergingLens and DivergingLens with animated focal length and moving image formation.
SphericalLens with animated radii of curvature, thickness, refractive index...
LineBeamStop, CircularAperture, and ArcBeamStop with animated position and radius.
PlaneMirror with tilt_tracker animation and SphericalMirror (concave, R < 0) converging a parallel bundle.
Eye with accommodation (animate_focal_length) and pupil diameter animation.
LinearGraticule, CrossGraticule, and GridGraticule as measurement overlays.
manim_optics uses the French algebraic sign convention:
| R | Mirror type | Visual |
|---|---|---|
| R < 0 | Concave (converging) | Half-arrows point left |
| R > 0 | Convex (diverging) | Half-arrows point right |
The facing parameter only controls hatching placement (facing="left" → hatching to the right).
DynamicRay and RayBundle use Manim updaters — every frame recomputes the full ray path. Move an element, change a tracker, or swap a list of optical elements and the scene stays live.
get_optical_plane_position() returns the true optical reference of an element (the lens or mirror line), not the bounding-box centre, which can be offset by focal-point dots or hatching geometry.
from manim_optics import (
ThinLens, ConvergingLens, DivergingLens,
Mirror, PlaneMirror, SphericalMirror,
BeamStop, LineBeamStop, CircularAperture, ArcBeamStop, SphericalLens
)from manim_optics import (
DynamicRay, RayBundle, PrincipalRays, RayExtension,
create_parallel_bundle, create_diverging_bundle,
find_ray_intersection, find_focal_point_from_rays,
ImageMarker, ImageFormation,
)from manim_optics import (
Eye, CenteredSystem,
OpticalElement3D, ThinLens3D, RayBundle3D,
)from manim_optics import (
OpticalScene, create_object_arrow, create_image_arrow, calculate_image_position,
Graticule, LinearGraticule, CrossGraticule, GridGraticule,
)# render one sub-scene
manim -pql examples/all_2d_gallery.py GalleryRayAvaliable scenes are : GalleryRay, GalleryLens, GalleryBeamStop, GalleryMirror, GalleryEyeModel, GalleryGraticules, GalleryRealLenses
manim_optics/ ← source package
base.py ← OpticalElement ABC
lenses.py ← ThinLens, ConvergingLens, DivergingLens
mirrors.py ← PlaneMirror, SphericalMirror
beam_stops.py ← LineBeamStop, CircularAperture, ArcBeamStop
rays.py ← DynamicRay, RayBundle, PrincipalRays…
real_lenses.py ← SphericalLens, BiconvexLens…
centered_system.py ← CenteredSystem
eye.py ← Eye
optics_3d.py ← OpticalElement3D, ThinLens3D, RayBundle3D
scene_utils.py ← OpticalScene, helpers
miscellaneous.py ← Graticule variants
examples/
all_2d_gallery.py ← all 2D scenes (Ray, Lens, BeamStop, Mirror, EyeModel, Graticules)
example_gif/ ← rendered GIFs + render_gallery.sh
tests/ ← 176 pytest tests






