Scene¶
Qualified name: algan.scene.Scene
- class Scene(video_settings=None, background=None, memory=None, scene_initializer=None, *, premultiplied_over=False)[source]¶
Bases:
RenderLoopMixinThe container that turns recorded animations into rendered video.
A Scene owns its actor registry, camera, lights, timeline, animation contexts, audio state, and render loop. Creating one pushes it onto the process-global
SceneManagerstack, making it the destination for mobs constructed without an explicitscene.Rendering (
get_frames(), fromRenderLoopMixin) proceeds in batches of frames sized to the memory budget: for each batch this scene’s timeline materializes every actor’s animated state at the batch’s frame times, actors produce render primitives, and the ray tracer renders and post-processes the frames, which are streamed to the video writer. Batch preparation for the next batch runs concurrently on a worker thread (ALGAN_PREFETCH_BATCHES=0disables).- Parameters:
video_settings (VideoSettings | None) – Resolution / fps / quality settings (see
algan.settings.video_settings).background (Color | str | torch.Tensor | Callable | None) – What the Scene is drawn on: a color, an image tensor, or a procedural callable. A Taichi
@ti.funcuses the scalar(x, y, time) -> colorcontract and is evaluated at render time. Python callables passed through the render APIs receive broadcastable Torch tensors; the direct constructor calls a Python callable once, with a coordinate grid. Defaults toNone, meaningSETTINGS.style.background. It is the same backgroundset_background()sets andsave_video(background=...)overrides for one render.memory – Optional
ManualMemoryrender arena.scene_initializer – Callable run on (re)creation; the default spawns the camera and a point light.
premultiplied_over (bool) – Export transparent frames for linear-light over compositing, keeping glow additive. Defaults to False. See
set_premultiplied_over()for the required color settings and consumer interpretation.
Methods
Register a Mob with this Scene so it takes part in rendering.
Register an audio effect with this Scene.
Add a light to this Scene.
Whether the Scene's background has any transparency.
Remove every light from this Scene.
Get the Scene currently being authored.
Despawn every spawned Mob in the Scene.
Get the Scene's current background.
Get this Scene's camera.
Get this Scene's lights.
Convert a world-space length to a length in rendered pixels.
Convert a length in rendered pixels to a world-space length.
Remove a light from this Scene.
Render discovered scene functions in isolated Scene contexts.
Empty the Scene completely and start over.
Mix this Scene's audio effects down to an audio file.
Render one or more still frames from this Scene.
Render everything recorded on this Scene to a video file.
Set what the Scene is drawn against.
Light the Scene with an environment map, and show it as a backdrop.
Export coverage and additive glow together for linear compositing.
Set this Scene's resolution, frame rate and anti-aliasing.
Render one frame and display it, for interactive work.
Set this Scene up the way Manim sets its scenes up.
Open this Scene in the interactive viewer.
Hold the scene still for a while.
Attributes
premultiplied_overWhether frames are exported for linear-light
overcompositing; seeset_premultiplied_over(), which owns the setting.- add_actor(actor)[source]¶
Register a Mob with this Scene so it takes part in rendering.
Mob constructors call this for you; you only need it for a Mob built with
add_to_scene=Falsethat you later decide to render.- Parameters:
actor – The Mob to register. Ignored if the Scene is no longer accepting actors (during a render).
- Returns:
This Scene, so calls can be chained.
- Return type:
- add_effect(effect)[source]¶
Register an audio effect with this Scene.
The
AudioandSpeechcontexts use this; the effect’s own start time decides where it lands in the finished video.- Parameters:
effect – The
AudioEffectto add.- Returns:
This Scene, so calls can be chained.
- Return type:
- add_light()[source]¶
Add a light to this Scene.
Lights only affect Mobs whose material responds to light – a
MeshBasicMateriallooks the same however the scene is lit. Adding the same light twice does nothing.Animation
Not animated: the light exists from this point in the timeline onwards.
- Parameters:
light – The light to add.
- Returns:
The light that was added, so it can be kept and animated.
- Return type:
- background_is_transparent()[source]¶
Whether the Scene’s background has any transparency.
This decides the output format: a transparent background makes
save_video()write.movwith an alpha channel instead of.mp4. A procedural background is always treated as opaque.- Returns:
Whether any background pixel is less than fully opaque.
- Return type:
bool
- clear_lights()[source]¶
Remove every light from this Scene.
Lit materials go black afterwards unless a new light or an environment map is added.
Animation
Not animated: the lights stop contributing from this point in the timeline onwards.
- Returns:
This Scene, so calls can be chained.
- Return type:
- static current()[source]¶
Get the Scene currently being authored.
Creates the default Scene on first use, so this never returns
None.- Returns:
The active Scene.
- Return type:
- despawn_mobs(retain_history=False, runtime=None, **kwargs)[source]¶
Despawn every spawned Mob in the Scene.
Parents are despawned before their children, so composite Mobs disappear as a unit rather than in pieces.
Animation
Recorded as an animation: all the despawns run together inside a
Sync, over the current context’s runtime (1 second by default) unlessruntimeoverrides it.- Parameters:
retain_history (bool) – Whether to keep the fully despawned actors whose earlier lifespan still has to render, and discard the rest. Defaults to False, which leaves
Scene.actorsalone. True is what a scene-ending fade wants: actors that never acquired a complete lifespan are dropped.runtime (float | None) – Seconds the despawn takes, overriding the current context. Defaults to
None, meaning use the context’s runtime.**kwargs – Passed to each
despawn()– notablyanimate=Falseto remove everything without fading.
- Returns:
This Scene, so calls can be chained.
- Return type:
- get_background()[source]¶
Get the Scene’s current background.
- Returns:
Whatever the background was set to: a color, an image tensor, or a procedural callable.
- Return type:
Coloror torch.Tensor or Callable
- get_camera()[source]¶
Get this Scene’s camera.
- Returns:
The camera, or
Noneif the Scene has not been initialized with one.- Return type:
- get_light_sources()[source]¶
Get this Scene’s lights.
- Returns:
The live list of registered lights; mutating it changes the Scene.
- Return type:
list[
Light]
- length_to_pixels(length)[source]¶
Convert a world-space length to a length in rendered pixels.
- Parameters:
length (float) – Length in world units.
- Returns:
The equivalent number of pixels at the Scene’s current resolution.
- Return type:
float
- pixels_to_length(length)[source]¶
Convert a length in rendered pixels to a world-space length.
- Parameters:
length (float) – Length in pixels.
- Returns:
The equivalent length in world units at the Scene’s current resolution.
- Return type:
float
- remove_light()[source]¶
Remove a light from this Scene.
Removing a light that is not registered does nothing.
Animation
Not animated: the light stops contributing from this point in the timeline onwards.
- Parameters:
light – The light to remove.
- Returns:
The light that was passed in.
- Return type:
- static render_all_funcs(*args, **kwargs)[source]¶
Render discovered scene functions in isolated Scene contexts.
- reset(rebuild_timeline=True)[source]¶
Empty the Scene completely and start over.
Drops all actors, audio effects, the camera and the lights, then re-runs the Scene initializer, which puts the default camera and lighting back. With the default
rebuild_timeline=Truetime also returns to zero and the timeline, animation and audio managers are rebuilt, so nothing recorded so far survives, and Mob references from before the reset are invalid and must not be reused. Other Scenes on the SceneManager stack are untouched.Animation
Not animated, and destructive: this discards the recording rather than animating anything out.
- Parameters:
rebuild_timeline (bool) – Whether to reset time and rebuild the timeline, animation and audio managers as well as the contents. Defaults to True; False rebuilds the contents only and leaves the recording in place.
- Returns:
This Scene, so calls can be chained.
- Return type:
- save_audio(file_path, sample_rate=44100, codec='pcm_s32le', nbytes=4)[source]¶
Mix this Scene’s audio effects down to an audio file.
Every registered effect is placed at its recorded start time and the result is written out.
save_video()does this for you; call it directly only when you want the audio on its own.- Parameters:
file_path (str | Path) – Where to write the audio.
sample_rate (int) – Sample rate in Hz. Defaults to
44100.codec (str) – FFmpeg audio codec. Defaults to
'pcm_s32le'(uncompressed).nbytes (int) – Bytes per sample. Defaults to
4.
- Returns:
The path written, or
Noneif the Scene has no audio effects.- Return type:
str or pathlib.Path or None
- save_frame(video_settings=None, at=None, *, overwrite=True, background=None, post_processes=None)[source]¶
Render one or more still frames from this Scene.
Unlike
save_video()this never modifies the Scene: nothing is despawned, the timeline is left as authored, and any temporary video settings or background are restored before returning. Call it as often as you like while building a scene.- Parameters:
file_path (str | Path | None) – Where to write the image. A bare filename is placed in Algan’s output directory; a path with a parent directory is used as given; a path naming a directory (one that exists, or that ends with a separator) has
SETTINGS.paths.output_filenameplaced inside it. A missing extension defaults to.png. Defaults toNone, meaningSETTINGS.paths.output_filename. The path actually written is reported, absolute, asresult.output_path.video_settings (VideoSettings | None) – Resolution and anti-aliasing for this still only, normally a preset such as
HD. Defaults toNone, meaning the Scene’s current settings.at (float | Sequence[float] | None) – Timestamp in seconds to capture, or a sequence of timestamps to capture several stills in one call. A negative timestamp is an offset backwards from the current authoring time, so
-0.5captures half a second before the current context’s cursor. Resolved timestamps must be finite and non-negative. Defaults toNone, capturing just after the current authoring time – i.e. the scene as it stands.overwrite (bool) – Whether an existing file at the destination is replaced. Defaults to True; False leaves it alone and reports
"skipped".background (Color | str | torch.Tensor | Callable | None) – A color, image, or procedural callable, applied to this still only. Defaults to
None, meaning keep the Scene’s background. Seeset_background()for the callable’s contract – it runs on the render device and is handed broadcastable grids, not scalars.post_processes – Post-processing passes to apply to the frame, as in
save_video(). Defaults toNone, meaning bloom. Pass()for no post-processing, or a tuned pass such aspartial(bloom_filter, glow_spread=0.015)to narrow the glow.
- Returns:
One result per still, with
status("rendered"or"skipped"),output_pathandwalltime_seconds. A list is returned only whenatis a sequence, matching the shape of the input.- Return type:
RenderResult or list of RenderResult
Examples
Scene.save_frame("thumbnail", HD) Scene.save_frame("shot.png", at=2.5) Scene.save_frame("previous.png", at=-0.5) Scene.save_frame("contact_sheet", at=[0, 1, 2])
- save_video(video_settings=None, *, overwrite=True, reset=False, background=None, animate_fade_out=None, post_processes=None, codec=None, audio_codec=None, ffmpeg_params=None)[source]¶
Render everything recorded on this Scene to a video file.
- Parameters:
file_path (str | Path | None) – Where to write the video. A bare filename such as
"my_video"is placed in Algan’s output directory; a path with a parent directory, relative or absolute, is used exactly as given; a path naming a directory (one that exists, or that ends with a separator) hasSETTINGS.paths.output_filenameplaced inside it. If the name has no extension Algan appends.mp4, or.movwhen the background is transparent. Defaults toNone, meaningSETTINGS.paths.output_filename. The path actually written is reported, absolute, asresult.output_path.video_settings (VideoSettings | None) – Resolution, frame rate and anti-aliasing for this render, normally one of the presets (
PREVIEW,LD,MD,HD,PRODUCTION,UHD). Applies to this render only; the Scene’s own settings are restored afterwards. Defaults toNone, meaningSETTINGS.video.overwrite (bool) – Whether an existing file at the destination is replaced. Defaults to True; False skips rendering and returns a
"skipped"result.reset (bool) – Whether to tear the Scene down after rendering: discard its recorded animation, despawn its mobs and rebuild its timeline, animation and audio managers. Mobs created before the render become unusable. Defaults to False, which leaves the Scene exactly as authored, so you can keep animating and render again – including from inside a
withblock that has not finished yet. A mid-block render covers everything recorded so far and changes nothing, so the final render is the same as if the preview had never happened.background (Color | str | torch.Tensor | Callable | None) – A color, image, or procedural callable
(x, y, time) -> color. Python callables run on the render device and receive broadcastable Torch tensors, not scalars – seeset_background()for the exact shapes and the two traps (build constants withx.new_tensor; keep the leading frame axis). A Taichi@ti.funcreceives scalar normalized coordinates and time and must return a color vector; it is evaluated for the whole render batch by one Taichi kernel writing directly into the output buffer. Defaults toNone, meaning keep the Scene’s background.animate_fade_out (bool | None) – Whether to fade every spawned mob out at the end of the video. Recorded on the timeline, so it persists even when
resetis False. Defaults toNone, meaningSETTINGS.style.fade_out_on_scene_end(False).post_processes – Post-processing passes to apply to each frame. Defaults to
None, meaning bloom.codec (str | None) – Encoder overrides passed through to FFmpeg. Each defaults to
None, letting Algan pick from the background’s transparency. With no explicitcodec, Algan encodes withlibx264or – when the machine’s NVIDIA driver exposes NVENC – the hardwareh264_nvencencoder; set theALGAN_VIDEO_ENCODERenvironment variable tosoftwareornvencto pin that choice (see Saving Videos and Images). A transparent background picks from the container instead: losslesspngfor.mov(also.mkv,.avi), andlibvpx-vp9for.webm, whose alpha rides in a 4:2:0 chroma plane and so is lossy at object edges..mp4cannot carry alpha at all and is refused before the render.audio_codec (str | None) – Encoder overrides passed through to FFmpeg. Each defaults to
None, letting Algan pick from the background’s transparency. With no explicitcodec, Algan encodes withlibx264or – when the machine’s NVIDIA driver exposes NVENC – the hardwareh264_nvencencoder; set theALGAN_VIDEO_ENCODERenvironment variable tosoftwareornvencto pin that choice (see Saving Videos and Images). A transparent background picks from the container instead: losslesspngfor.mov(also.mkv,.avi), andlibvpx-vp9for.webm, whose alpha rides in a 4:2:0 chroma plane and so is lossy at object edges..mp4cannot carry alpha at all and is refused before the render.ffmpeg_params (list[str] | None) – Encoder overrides passed through to FFmpeg. Each defaults to
None, letting Algan pick from the background’s transparency. With no explicitcodec, Algan encodes withlibx264or – when the machine’s NVIDIA driver exposes NVENC – the hardwareh264_nvencencoder; set theALGAN_VIDEO_ENCODERenvironment variable tosoftwareornvencto pin that choice (see Saving Videos and Images). A transparent background picks from the container instead: losslesspngfor.mov(also.mkv,.avi), andlibvpx-vp9for.webm, whose alpha rides in a 4:2:0 chroma plane and so is lossy at object edges..mp4cannot carry alpha at all and is refused before the render.
- Returns:
Metadata with
status("rendered"or"skipped"),output_path,walltime_secondsand the resolvedrender_plan.- Return type:
Examples
Scene.save_video("my_video") # LD into algan_outputs/ Scene.save_video("my_video", HD) # one-off quality override Scene.save_video("renders/final.mov") # explicit directory
- set_background(overwrite=True)[source]¶
Set what the Scene is drawn against.
Animation
Not animated: the background changes for the whole video, not from this point onwards, since it is Scene state rather than timeline state. For a one-off render, pass
backgroundtosave_video()instead.- Parameters:
background (Color | str | Tensor | Callable | None) –
A color, a path to an image (scaled to the frame), or a procedural callable
(x, y, time) -> color. A color with alpha below 1 makes the output transparent.Noneleaves the background unchanged.The callable is evaluated on the render device and receives broadcastable grids, not scalars:
xis[1, width, 1]andyis[height, 1, 1], both in[0, 1)withy = 0at the bottom of the frame, andtimeis[frames, 1, 1, 1]in seconds. It must return either a resolution-free color or a tensor broadcasting to[frames, height, width, channels]– so build constants withx.new_tensor(...)(nottorch.tensor, which lands on the CPU) and keep the leading frame axis, e.g. by multiplying a per-pixel term bytorch.ones_like(time). Both are easy to miss; the failure modes are a device-mismatchRuntimeErrorand “callable background must produce one value per supersampled pixel”.overwrite (bool) – Whether to replace a background that has already been set. Defaults to True; False makes the call a no-op once a background exists, which is how defaults are applied without stomping a user’s choice.
- Returns:
This Scene, so calls can be chained.
- Return type:
Examples
def vignette(x, y, t): r2 = (x - 0.5) ** 2 + (y - 0.5) ** 2 fade = torch.exp(-r2 * 4) * torch.ones_like(t) return x.new_tensor((0.02, 0.03, 0.08)) * fade Scene.save_frame("shot", background=vignette)
- set_environment_map(intensity=1.0, ambient=True)[source]¶
Light the Scene with an environment map, and show it as a backdrop.
An equirectangular image surrounds the scene, so reflective and metallic materials pick up their surroundings instead of reflecting a void – the cheapest way to make metal look like metal.
The map is also the backdrop: rays that hit no geometry sample it, so it replaces
backgroundrather than sitting behind it. Only the camera’s share of the map is visible (the frustum’s solid angle), and the map is downsampled above 2048 texels wide, so bake the backdrop into it at a resolution that accounts for that if the backdrop carries detail.Animation
Not animated: the map applies from this point in the timeline onwards.
- Parameters:
source –
Path to an image file, or an image tensor of shape
[height, width, >=3].Noneremoves the current map.Byte-ranged sources – an image file, or an integer-dtype tensor – are divided by 255. A float tensor is taken as authored, so values above 1 are kept: that is what makes a light source in the map brighter than white, which is the whole point of an HDR environment. Author in whatever units you like and use
intensityto set the overall level.intensity (float) – Brightness multiplier for the map’s contribution. Defaults to
1.0.ambient (bool) – Whether the map also provides ambient light to non-reflective surfaces, rather than only appearing in reflections. Defaults to True.
- Returns:
This Scene, so calls can be chained.
- Return type:
- Raises:
FileNotFoundError – If
sourceis a path that cannot be read.ValueError – If the image is not shaped
[height, width, >=3].
- set_premultiplied_over()[source]¶
Export coverage and additive glow together for linear compositing.
Transparent output keeps bloom out of coverage alpha and stores the sRGB encoding of linear premultiplied light, including color at zero alpha. Decode RGB directly to linear light before applying
src + dst * (1 - alpha); do not divide by alpha during that decode. MOV defaults to ProRes 4444, with 8-bit source precision. Ordinary viewers generally do not interpret these samples correctly.Requires linear color, post-process tonemapping, and no nonlinear tone curve. Incompatible settings raise an error when rendering transparent output. The setting is ignored for opaque backgrounds. Bloom comes from the exported layer only; it does not reproduce backdrop-dependent bloom from every opaque render.
Animation
Takes effect immediately for the whole Scene and is not animated. Can be changed before or after spawning mobs, and survives reset().
- Parameters:
enabled (bool) – Whether to enable this export interpretation. Defaults to True; new Scenes default to False.
- Returns:
This Scene, so calls can be chained.
- Return type:
- Raises:
.AlganConfigurationError – If enabled is not a boolean.
Examples
Export one clip for a linear-light compositor:
from algan import * Scene.set_background(TRANSPARENT) Scene.set_premultiplied_over() Circle(color=YELLOW, glow=1.0).spawn() Scene.save_video("glow.mov")
- set_video_settings(_explicit=True)[source]¶
Set this Scene’s resolution, frame rate and anti-aliasing.
video_settingsis aVideoSettingsinstance, usually one of the built-in presets (PREVIEW,LD,MD,HD,PRODUCTION,UHD).They apply to every render of this Scene that does not name settings of its own –
save_video()andsave_frame()alike – and are outranked only by avideo_settingsargument to one of those calls.Most scripts do not need this: pass
video_settingstosave_video()/save_frame()for a one-off render, or setSETTINGS.videofor a process-wide default.- Parameters:
_explicit (bool)
- show_frame(at=None)[source]¶
Render one frame and display it, for interactive work.
Meant for a notebook or REPL: it plots the frame rather than writing a file. Use
save_frame()to save one instead.Animation
Not animated and non-destructive: rendering a frame leaves the Scene as authored.
- Parameters:
at (float | None) – Time to render, in seconds. Defaults to
None, meaning just after the current authoring time – i.e. the scene as it stands.- Returns:
The frame(s) that were plotted, as
(channels, height, width)tensors with values in[0, 1].- Return type:
list[torch.Tensor]
- use_manim_defaults(*, shading=True, background=True, video_settings=False, shape_defaults=False, stroke_geometry=True)[source]¶
Set this Scene up the way Manim sets its scenes up.
Call it once, before building the Scene, and geometry authored against Manim’s conventions – most obviously anything arriving through
ManimMob– lands on the pixels Manim would have put it on: same 8-unit frame height, same perspective, same light position, same black background.Manim’s frame is 8 world units tall and its
ThreeDCamerasits 20 units from the frame plane, which is a vertical field of view of 22.62 degrees. Manim’s plain 2-D camera is a flat orthographic projection, but the two agree exactly atz = 0, so this one perspective camera reproduces 2-D scenes exactly and 3-D scenes with Manim’s own perspective.Manim’s
OUTand Algan’sOUTWARDare both+z, so imported geometry needs no coordinate conversion and none is applied.Animation
Not animated: the Scene is reconfigured immediately, at the point in the timeline where the call happens. Call it before spawning anything.
- Parameters:
camera (bool) – Whether to move the camera to Manim’s viewpoint and set its field of view. Defaults to
True.shading (bool) –
Whether to reproduce Manim’s color pipeline: its single light in its own position,
ManimMaterialas the default material for 3-D Mobs with none of their own – reproducing the shading Manim’sget_shaded_rgbapplies to anything flaggedshade_in_3d, whichManimMobcarries across so even a flatCubeface is lit – no tonemapping, so a flat fill comes out byte-identical to Manim’s, and Manim’s display-referred working color space, since Manim composites alpha and antialiases in sRGB rather than in linear light. Defaults toTrue.The color space is process-wide and changes every render, not only Manim-derived content, and it compiles a separate set of GPU kernels, so the first render after switching pays a cold compile. It is also effectively a process-start decision: the renderer folds it into its kernels at compile time, so switching it after something has already rendered in this process leaves those kernels in the old space while the rest of the pipeline moves to the new one – a measured ~24/255 disagreement. Calling this method once at the top of a script, as intended, is before any render and is safe. To be certain in a process that renders more than once, set
ALGAN_LINEAR_COLOR=0in the environment instead, or passshading=Falsehere and leave the space alone.background (bool) – Whether to set the background to black, Manim’s default. Defaults to
True.video_settings (bool) – Whether to also switch the output to Manim’s default 1920x1080 at 60 fps. Defaults to
False, so an explicitly chosen quality preset survives the call. Only the aspect ratio affects framing.shape_defaults (bool) – Whether Algan’s own shapes (
Square,Circle, …) also adopt Manim’s default colors and stroke styling. Defaults toFalse, since it changes shapes that have nothing to do with Manim.stroke_geometry (bool) – Whether strokes are laid out Manim’s way rather than Algan’s, in the two respects the engines disagree on. Placement (
SETTINGS.style.border_placement): a filled shape’s stroke straddles its outline as Manim’s does instead of running inward as Algan’s does, which otherwise puts a Manim shape’s silhouette half a stroke width inside where Manim draws it. Width (SETTINGS.style.manim_stroke_width_ratio): the compatibility layer converts stroke widths by the exact2.0202rather than Algan’s round2, which is otherwise 1.01% too wide. Defaults toTrue. Neither changes a stroke’s authored color or width, so both are safe for shapes that never came from Manim – but they are process-wide, so passFalseto leave other Scenes alone.
- Returns:
This Scene, so calls can be chained.
- Return type:
See also
ManimMobConvert a Manim Mobject into a Mob.
Examples
Example: Example1SceneUseManimDefaults ¶
from algan import * import manim Scene.use_manim_defaults() ManimMob(manim.Circle()).spawn() Scene.save_video()
- view(*, port=0, open_browser=True, block=True)[source]¶
Open this Scene in the interactive viewer.
Starts a small web server on this machine and points a browser at it. The page plays the Scene as it stands, and lets you stop on a frame and ask what is in it: the Scene’s mobs as a tree with their animatable attributes, any pixel’s colour, and the list of surfaces behind that pixel, nearest first, each with its depth and the mob it came from.
Frames are rendered as you reach them rather than up front, so the window opens immediately and seeking costs one chunk of frames. Nothing is written to disk, and the Scene is left exactly as authored – you can keep adding to it, or call
save_video(), afterwards.The video is the Scene as it stands when you call this. Frames already rendered are kept, so if you go on authoring the same Scene from a REPL (
block=False), open a new viewer to see the additions rather than expecting this one to grow.There is no module-level
view: the viewer is reached from the Scene and nowhere else, because the bare name is too general to spend on a namespace thatfrom algan import *empties into a user’s own.- Parameters:
video_settings (VideoSettings | None) – Resolution and anti-aliasing to render at, normally a preset such as
HD. Defaults toNone, meaning thePREVIEWpreset’s resolution at the Scene’s own frame rate – so seeking stays quick while the frame numbers still match the video the Scene would produce.port (int) – Port to serve on. Defaults to 0, meaning any free port.
open_browser (bool) – Whether to open the page in your default browser. Defaults to True.
block (bool) – Whether to serve until interrupted. Defaults to True, which is what a script wants: the viewer stays up until you close it with Ctrl-C. False returns immediately with the viewer running in the background, which is what a REPL or a test wants. Note that a blocking viewer running on the warm render daemon occupies it until you stop it, since the daemon runs one script at a time.
- Returns:
The running viewer. It carries the
urlbeing served and astop()that shuts it down, and works as a context manager.- Return type:
Animation
Records nothing and renders nothing until the page asks for a frame. The Scene’s timeline, its mobs and its video settings are all left as they were.
Examples
square = Square().spawn() square.move(RIGHT) Scene.view() # opens a browser, serves until Ctrl-C handle = Scene.view(block=False) # keep scripting while it runs print(handle.url) handle.stop()
- wait(**kwargs)[source]¶
Hold the scene still for a while.
Advances time without changing anything, leaving a pause in the video – room for narration, or a beat before the next animation.
Animation
Recorded on the timeline: it consumes video time and nothing else.
- Parameters:
time (float) – How long to wait, in seconds. Must be finite and zero or more. Defaults to
1.**kwargs – Accepted only so that the timing spellings Algan does not use (
duration,run_time,rate_func) can be answered with the name it does; anything else is rejected.
- Returns:
This Scene, so calls can be chained.
- Return type:
- Raises:
.AlganConfigurationError – If
timeis not a finite, non-negative number, or a keyword names a parameterwait()does not have.