Scene
(renderer=None, camera_class=<class 'manim.camera.camera.Camera'>, always_update_mobjects=False, random_seed=0, **kwargs)[source]¶Bases: manim.container.Container
A Scene is the canvas of your animation.
The primary role of Scene
is to provide the user with tools to manage
mobjects and animations. Generally speaking, a manim script consists of a class
that derives from Scene
whose Scene.construct()
method is overridden
by the user’s code.
Mobjects are displayed on screen by calling Scene.add()
and removed from
screen by calling Scene.remove()
. All mobjects currently on screen are kept
in Scene.mobjects
. Animations are played by calling Scene.play()
.
A Scene
is rendered internally by calling Scene.render()
. This in
turn calls Scene.setup()
, Scene.construct()
, and
Scene.tear_down()
, in that order.
It is not recommended to override the __init__
method in user Scenes. For code
that should be ran before a Scene is rendered, use Scene.setup()
instead.
Examples
Override the Scene.construct()
method with your code.
class MyScene(Scene):
def construct(self):
self.play(Write(Text("Hello World!")))
Methods
Mobjects will be displayed, from background to foreground in the order with which they are added. |
|
Adds a single mobject to the foreground, and internally to the list foreground_mobjects, and mobjects. |
|
Adds mobjects to the foreground, and internally to the list foreground_mobjects, and mobjects. |
|
|
|
This method is used to add a sound to the animation. |
|
|
|
Removes the mobject from the scene and adds them to the back of the scene. |
|
Adds the passed mobjects to the scene again, pushing them to he front of the scene. |
|
Removes all mobjects present in self.mobjects and self.foreground_mobjects from the scene. |
|
|
|
Creates _MethodAnimations from any _AnimationBuilders and updates animation kwargs with kwargs passed to play(). |
|
Add content to the Scene. |
|
Gets attributes of a scene given the attribute’s identifier/name. |
|
Returns list of family-members of all mobjects in scene. |
|
|
|
Gets all moving mobjects in the passed animation(s). |
|
Given a list of mobjects and a list of mobjects to be removed, this filters out the removable mobjects from the list of mobjects. |
|
Gets the total run time for a list of animations. |
|
You will hardly use this when making your own animations. |
|
Returns all mobjects which are not submobjects. |
|
|
|
This method is used to prep the animations for rendering, apply the arguments and parameters required to them, render them, and write them to the video file. |
|
Removes mobjects in the passed list of mobjects from the scene and the foreground, by removing them from “mobjects” and “foreground_mobjects” |
|
Removes a single mobject from the foreground, and internally from the list foreground_mobjects. |
|
Removes mobjects from the foreground, and internally from the list foreground_mobjects. |
|
Render this Scene. |
|
tl:wr |
|
This is meant to be implemented by any scenes which are commonly subclassed, and have some common setup involved before the construct method is called. |
|
Returns True if any mobject in Scene is being updated or if the scene has always_update_mobjects set to true. |
|
This is meant to be implemented by any scenes which are commonly subclassed, and have some common method to be invoked before the scene ends. |
|
Begins updating all mobjects in the Scene. |
|
|
|
|
|
Like a wrapper for wait(). |
Attributes
|
add
(*mobjects)[source]¶Mobjects will be displayed, from background to foreground in the order with which they are added.
add_foreground_mobject
(mobject)[source]¶Adds a single mobject to the foreground, and internally to the list foreground_mobjects, and mobjects.
add_foreground_mobjects
(*mobjects)[source]¶Adds mobjects to the foreground, and internally to the list foreground_mobjects, and mobjects.
add_sound
(sound_file, time_offset=0, gain=None, **kwargs)[source]¶This method is used to add a sound to the animation.
sound_file (str) – The path to the sound file.
time_offset (int,float, optional) – The offset in the sound file after which the sound can be played.
gain –
bring_to_back
(*mobjects)[source]¶Removes the mobject from the scene and adds them to the back of the scene.
bring_to_front
(*mobjects)[source]¶Adds the passed mobjects to the scene again, pushing them to he front of the scene.
clear
()[source]¶Removes all mobjects present in self.mobjects and self.foreground_mobjects from the scene.
The Scene, with all of its mobjects in self.mobjects and self.foreground_mobjects removed.
compile_animations
(*args, **kwargs)[source]¶Creates _MethodAnimations from any _AnimationBuilders and updates animation
kwargs with kwargs passed to play().
:param *args: Animations to be played.
:type *args: Tuple[Animation
]
:param **kwargs: Configuration for the call to play().
Animations to be played.
Tuple[Animation
]
construct
()[source]¶Add content to the Scene.
From within Scene.construct()
, display mobjects on screen by calling
Scene.add()
and remove them from screen by calling Scene.remove()
.
All mobjects currently on screen are kept in Scene.mobjects
. Play
animations by calling Scene.play()
.
Notes
Initialization code should go in Scene.setup()
. Termination code should
go in Scene.tear_down()
.
Examples
A typical manim script includes a class derived from Scene
with an
overridden Scene.contruct()
method:
class MyScene(Scene):
def construct(self):
self.play(Write(Text("Hello World!")))
See also
get_attrs
(*keys)[source]¶Gets attributes of a scene given the attribute’s identifier/name.
*keys (str) – Name(s) of the argument(s) to return the attribute of.
List of attributes of the passed identifiers.
list
get_mobject_family_members
()[source]¶Returns list of family-members of all mobjects in scene. If a Circle() and a VGroup(Rectangle(),Triangle()) were added, it returns not only the Circle(), Rectangle() and Triangle(), but also the VGroup() object.
List of mobject family members.
list
get_moving_mobjects
(*animations)[source]¶Gets all moving mobjects in the passed animation(s).
*animations (Animation) – The animations to check for moving mobjects.
The list of mobjects that could be moving in the Animation(s)
list
get_restructured_mobject_list
(mobjects, to_remove)[source]¶Given a list of mobjects and a list of mobjects to be removed, this filters out the removable mobjects from the list of mobjects.
mobjects (list) – The Mobjects to check.
to_remove (list) – The list of mobjects to remove.
The list of mobjects with the mobjects to remove removed.
list
get_run_time
(animations)[source]¶Gets the total run time for a list of animations.
animations (List[Animation
, …]) – A list of the animations whose total
run_time
is to be calculated.
The total run_time
of all of the animations in the list.
float
get_time_progression
(run_time, description, n_iterations=None, override_skip_animations=False)[source]¶You will hardly use this when making your own animations. This method is for Manim’s internal use.
Returns a CommandLine ProgressBar whose fill_time
is dependent on the run_time
of an animation,
the iterations to perform in that animation
and a bool saying whether or not to consider
the skipped animations.
run_time (float) – The run_time
of the animation.
n_iterations (int, optional) – The number of iterations in the animation.
override_skip_animations (bool, optional) – Whether or not to show skipped animations in the progress bar.
The CommandLine Progress Bar.
time_progression
get_top_level_mobjects
()[source]¶Returns all mobjects which are not submobjects.
List of top level mobjects.
list
play_internal
(skip_rendering=False)[source]¶This method is used to prep the animations for rendering, apply the arguments and parameters required to them, render them, and write them to the video file.
args – Animation or mobject with mobject method and params
kwargs – named parameters affecting what was passed in args
,
e.g. run_time
, lag_ratio
and so on.
remove
(*mobjects)[source]¶Removes mobjects in the passed list of mobjects from the scene and the foreground, by removing them from “mobjects” and “foreground_mobjects”
*mobjects (Mobject) – The mobjects to remove.
remove_foreground_mobject
(mobject)[source]¶Removes a single mobject from the foreground, and internally from the list foreground_mobjects.
remove_foreground_mobjects
(*to_remove)[source]¶Removes mobjects from the foreground, and internally from the list foreground_mobjects.
restructure_mobjects
(to_remove, mobject_list_name='mobjects', extract_families=True)[source]¶If your scene has a Group(), and you removed a mobject from the Group, this dissolves the group and puts the rest of the mobjects directly in self.mobjects or self.foreground_mobjects.
In cases where the scene contains a group, e.g. Group(m1, m2, m3), but one of its submobjects is removed, e.g. scene.remove(m1), the list of mobjects will be edited to contain other submobjects, but not m1, e.g. it will now insert m2 and m3 to where the group once was.
to_remove (Mobject) – The Mobject to remove.
mobject_list_name (str, optional) – The list of mobjects (“mobjects”, “foreground_mobjects” etc) to remove from.
extract_families (bool, optional) – Whether the mobject’s families should be recursively extracted.
The Scene mobject with restructured Mobjects.
setup
()[source]¶This is meant to be implemented by any scenes which are commonly subclassed, and have some common setup involved before the construct method is called.
should_update_mobjects
()[source]¶Returns True if any mobject in Scene is being updated or if the scene has always_update_mobjects set to true.
bool
tear_down
()[source]¶This is meant to be implemented by any scenes which are commonly subclassed, and have some common method to be invoked before the scene ends.
update_mobjects
(dt)[source]¶Begins updating all mobjects in the Scene.
dt (int or float) – Change in time between updates. Defaults (mostly) to 1/frames_per_second
wait_until
(stop_condition, max_time=60)[source]¶Like a wrapper for wait(). You pass a function that determines whether to continue waiting, and a max wait time if that is never fulfilled.
stop_condition (function) – The function whose boolean return value determines whether to continue waiting
max_time (int or float, optional) – The maximum wait time in seconds, if the stop_condition is never fulfilled.