pooltool.ani.animate#

Overview#

Classes#

FrameStepper

Step through a shot frame-by-frame

ShotViewer

An interface for viewing shots from within python.

Game

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: Interface

Methods:

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: Interface

Methods:

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:

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 ShotViewer object:

>>> 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)
class pooltool.ani.animate.Game(config=ShowBaseConfig.default())[source]#

This class runs the pooltool application

Bases: Interface

Methods:

enter_game()[source]#

Close the menu, setup the visualization, and start the game

create_system()[source]#

Create the multisystem and game objects

FIXME This is where menu options for game type and further specifications should plug into.