Skip to contents

Core R6 class representing an animation scene. Supports two APIs:

Pipe API (R-idiomatic):

scene("demo") %>% add_circle() %>% fade_in() %>% render()

Play API (Manim-style):

s <- Scene$new("demo")
c <- Circle$new()
s$add(c)
s$play(FadeIn$new(c))
s$render()

Public fields

name

Scene name/identifier

width

Scene width in pixels

height

Scene height in pixels

fps

Frames per second

background_color

Background color

objects

Named list of objects in the scene

timeline

Animation timeline (list of animation specs)

current_time

Current time in the scene

dimensions

"2D" or "3D"

camera

Camera object for the scene

updaters

List of scene-level updater functions

mobjects

Ordered list of visible mobjects (draw order)

Methods


Method new()

Create a new Scene

Usage

Scene$new(
  name = "untitled",
  width = 1920,
  height = 1080,
  fps = 30,
  background_color = "#000000",
  dimensions = "2D"
)

Arguments

name

Scene name

width

Width in pixels

height

Height in pixels

fps

Frames per second

background_color

Background color

dimensions

"2D" or "3D"


Method add()

Add mobject(s) to the scene (makes them visible). Manim-compatible: scene$add(circle, square).

Usage

Scene$add(...)

Arguments

...

MObjects to add to the scene


Method remove()

Remove mobject(s) from the scene.

Usage

Scene$remove(...)

Arguments

...

MObjects to remove


Method play()

Play one or more Animation objects. This is the primary Manim-style API for adding animations.

Usage

Scene$play(...)

Arguments

...

Animation objects to play simultaneously


Method wait()

Wait (hold) for a duration. Manim-compatible.

Usage

Scene$wait(duration = 1)

Arguments

duration

Duration in seconds


Method add_object()

Add an object to the scene (legacy pipe API)

Usage

Scene$add_object(object, show_immediately = FALSE)

Arguments

object

A MObject to add

show_immediately

Whether to show the object immediately


Method add_animation()

Add an animation to the timeline (legacy pipe API)

Usage

Scene$add_animation(animation)

Arguments

animation

Animation specification (list)


Method get_object()

Get an object by ID

Usage

Scene$get_object(id)

Arguments

id

Object ID


Method get_last_object()

Get the most recently added object

Usage

Scene$get_last_object()


Method get_mobjects()

Get all mobjects currently in the scene

Usage

Scene$get_mobjects()


Method get_duration()

Calculate total duration

Usage

Scene$get_duration()


Method get_frame_count()

Get total number of frames

Usage

Scene$get_frame_count()


Method add_updater()

Add a scene-level updater function

Usage

Scene$add_updater(func)

Arguments

func

Function(scene, dt) called every frame


Method clear_updaters()

Remove all scene updaters

Usage

Scene$clear_updaters()


Method update()

Process one frame of updaters

Usage

Scene$update(dt = NULL)

Arguments

dt

Time step (1/fps)


Method clear()

Clear the scene of all objects and animations

Usage

Scene$clear()


Method get_coord_to_pixel()

Get the coordinate-to-pixel conversion factors

Usage

Scene$get_coord_to_pixel()

Returns

List with x_scale and y_scale


Method print()

Print scene summary

Usage

Scene$print()


Method clone()

The objects of this class are cloneable with this method.

Usage

Scene$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.