pooltool.ani.animate#
Overview#
Step through a shot frame-by-frame |
|
An interface for viewing shots from within python. |
|
This class runs the pooltool application |
Classes#
- class pooltool.ani.animate.FrameStepper(config: ShowBaseConfig = DEFAULT_FBF_CONFIG)[source]#
Step through a shot frame-by-frame
Bases:
InterfaceMethods:
- iterator(*args, **kwargs) Tuple[Generator, int][source]#
Iterate through each frame
- Parameters:
shot -- The shot you would like to iterate through. It should already by simulated. It is OK if you have continuized the shot (you can check with shot.continuized), but the continuization will be overwritten to match the fps chosen in this method.
size -- The number of pixels in x and y. If x:y != 1.6, the aspect ratio will look distorted.
fps -- This is the rate (in frames per second) that the shot is iterated through.
- Returns:
- This is an iterator. next(iterator) will advance the rendered objects
to the next frame.
- frames:
This is the length of the iterator (by the time you receive it). Useful for things like for frame in frames: next(iterator).
- Return type:
iterator
- class pooltool.ani.animate.ShotViewer(config=ShowBaseConfig.default())[source]#
An interface for viewing shots from within python.
Important
For instructions on how to use the interactive interface, see The Interface.
Important
Only one instance of this class can be created per python process. You’ll receive a runtime error if you try. Instead, create one instance and use it for the lifetime of your python process.
For usage, see
show().Bases:
InterfaceMethods:
- show(shot_or_shots: pooltool.system.datatypes.System | pooltool.system.datatypes.MultiSystem, title: str = '', camera_state: pooltool.ani.camera.CameraState | None = None)[source]#
Opens the interactive interface for one or more shots.
Important
For instructions on how to use the interactive interface, see The Interface.
- Parameters:
shot_or_shots (Union[pooltool.system.datatypes.System, pooltool.system.datatypes.MultiSystem]) --
The shot or collection of shots to visualize. This can be a single
pooltool.system.datatypes.Systemobject or apooltool.system.datatypes.MultiSystemobject containing multiple systems.Note
If a multisystem is passed, the systems can be scrolled through by pressing n (next) and p (previous).
title (str) -- The title to display in the visualization. Defaults to an empty string.
camera_state (Optional[pooltool.ani.camera.CameraState]) -- The initial camera state that the visualization is rendered with.
Example
This example visualizes a single shot.
>>> import pooltool as pt >>> system = pt.System.example()
Make sure the shot is simulated, otherwise it will make for a boring visualization:
>>> pt.simulate(system, inplace=True)
Create a
ShotViewerobject:>>> gui = pt.ShotViewer()
Now visualize the shot:
>>> gui.show(system)
(Press escape to exit the interface and continue script execution)
Example
This example explains the order in which events and script execution happens.
import pooltool as pt system = pt.System.example() pt.simulate(system, inplace=True) # This line takes a view seconds to execute. It will generate a visible # window. Once the window has been generated, script execution continues gui = pt.ShotViewer() # When this line is called, the window is populated with an animated # scene of the shot. gui.show(system) # This line will not execute until <esc> is pressed while the window is # active. print('script continues') # For subsequent calls to `show`, you must use the same `ShotViewer` # object: gui.show(system)