Windows¶
Animations are displayed in dedicated windows created with
anim.window. A single instantiation is enough to get a fully
functional animation window: the Qt event loop, keyboard shortcuts, layout
management, and movie recording are handled internally.
Creating a window¶
Start with the smallest possible setup:
import anim
W = anim.window('My animation')
W.add(anim.plane.canva(W))
W.show()
Then tune anim.window with constructor options:
Parameter |
Default |
Description |
|---|---|---|
|
|
Title displayed in the window title bar. |
|
|
Visual theme. Available values are |
|
|
Window height as a fraction of the screen height. For example,
|
|
|
Window width as a fraction of the screen width. If |
|
|
Width/height ratio of the animation area (excluding the information dock). |
|
|
Custom |
Styling¶
Styling is controlled by the style argument of
anim.window.
# Default dark theme
W = anim.window('Night view', style='dark')
# Bright theme for print-like visuals
W2 = anim.window('Day view', style='light')
The dark theme is usually best for high-contrast animated objects,
while light is useful when your figure uses dark strokes and you want
an interface close to standard report figures.
Adding canvas panels¶
Canvas panels are added with
anim.window.add and arranged in a
grid. By default, each new panel is appended to the right.
W.add(MyCanva) # automatic placement
W.add(MyCanva, row=1, col=0) # explicit placement
You can pass a class (instantiated automatically) or an existing object.
Extra keyword arguments are forwarded to the canvas constructor (for example
anim.plane.canva subclasses):
W.add(clock, city='Europe/Paris')
For instance in the multiple canva demo,
each canvas is added by a call to
anim.window.add:
W.add(clock, city='America/New_York')
W.add(clock, city='Europe/Paris')
W.add(clock, city='Asia/Singapore')
Timing and playback¶
The animation runs at a fixed frame rate, defaulting to 25 fps. Each frame
increments an integer step counter. Real time is step * dt where
dt = 1 / fps.
The following attributes can be set before
anim.window.show:
Attribute |
Default |
Description |
|---|---|---|
|
|
Frames per second. |
|
|
Start playing automatically when the window opens. |
|
|
Maximum step. If set, animation pauses at this value. |
|
|
Allow backward stepping. |
|
|
Allow step values below zero. |
W.fps = 30
W.autoplay = False
W.step_max = 200
W.allow_backward = True
Keyboard shortcuts¶
The following shortcuts are available in every window:
Key |
Action |
|---|---|
Space |
Play/pause |
Right |
Step forward by one frame (when paused) |
Left |
Step backward by one frame (if |
i |
Show/hide the information panel |
Esc |
Close the window |
Information dock behavior and content updates are documented in the information section.
Recording a movie¶
Set W.movieFile before calling
anim.window.show to record the animation:
W.movieFile = 'output/my_movie.mp4'
W.show()
Additional recording options:
Attribute |
Default |
Description |
|---|---|---|
|
|
Output video frame rate. |
|
|
Output video width in pixels (must be a multiple of 16). |
|
|
Record one frame every |