app Package¶
app
Package¶
Main package of the software. It contains the Program class which is the core application controller.
-
class
Program
[source]¶ Bases:
object
Main class of ARS.
To run a custom simulation, create a subclass. It must contain an implementation of the ‘create_sim_objects’ method which will be called during the simulation creation.
To use it, only two statements are necessary:
- create an object of this class
>>> sim_program = ProgramSubclass()
- call its ‘start’ method
>>> sim_program.start()
Constructor. Defines some attributes and calls some initialization methods to:
- set the basic mapping of key to action,
- create the visualization window according to class constants,
- create the simulation.
-
BACKGROUND_COLOR
= (1, 1, 1)¶
-
CAMERA_POSITION
= (10, 8, 10)¶
-
FLOOR_BOX_SIZE
= (10, 0.01, 10)¶
-
FPS
= 50¶
-
STEPS_PER_FRAME
= 50¶
-
WINDOW_POSITION
= (0, 0)¶
-
WINDOW_SIZE
= (1024, 768)¶
-
WINDOW_TITLE
= 'ARS simulation'¶
-
WINDOW_ZOOM
= 1.0¶
-
create_screenshot_recorder
(base_filename, periodically=False)[source]¶ Create a screenshot (of the frames displayed in the graphics window) recorder.
Each image will be written to a numbered file according to
base_filename
. By default it will create an image each timerecord_frame()
is called. Ifperiodically
isTrue
then screenshots will be saved in sequence. The time period between each frame is determined according toFPS
.
-
create_sim_objects
()[source]¶ This method must be overriden (at least once in the inheritance tree) by the subclass that will instatiated to run the simulator.
It shall contain statements calling its ‘sim’ attribute’s methods for adding objects (e.g. add_sphere).
For example:
>>> self.sim.add_sphere(0.5, (1,10,1), density=1)
-
create_simulation
(add_axes=True, add_floor=True)[source]¶ Creates an empty simulation and:
adds basic simulation objects (
add_basic_simulation_objects()
),- (if
add_axes
isTrue
) adds axes to the visualization at the coordinates-system origin,
- (if
- (if
add_floor
isTrue
) adds a floor with a defined normal vector and some visualization parameters,
- (if
- calls
create_sim_objects()
(which must be implemented by subclasses),
- calls
- gets the actors representing the simulation objects and adds them to
the graphics adapter.
-
finalize
()[source]¶ Finalize the program, deleting or releasing all associated resources.
Currently, the following is done:
- the graphics engine is told to
all attributes are set to None or False
A finalized program file cannot be used for further simulations.
Note
This method may be called more than once without error.
-
on_pre_frame
()[source]¶ This method will be called before each visualization frame is created. It is meant to be, optionally, implemented by subclasses.
-
on_pre_step
()[source]¶ This method will be called before each integration step of the simulation. It is meant to be, optionally, implemented by subclasses.
-
record_frame
()[source]¶ Record a frame using a screenshot recorder.
If frames are meant to be written periodically, a new one will be recorded only if enough time has elapsed, otherwise it will return
False
. The filename index will betime / period
.If frames are not meant to be written periodically, then index equals simulator’s frame number.
-
reset_simulation
()[source]¶ Resets the simulation by resetting the graphics adapter and creating a new simulation.