Simulation ¶
Simulation(compute=None, reset=None, view=None)
Bases: Animation
delta_time
property
¶
delta_time
Time step between substeps (proxy to engine.delta_time
).
Returns:
Type | Description |
---|---|
float
|
|
engine
property
¶
engine
Global engine singleton.
Returns:
Type | Description |
---|---|
Engine
|
The module-level engine instance that drives the animation. |
time
property
¶
time
Current time in seconds (proxy to engine.time
).
Returns:
Type | Description |
---|---|
float
|
The timeline time including subframes, offset, and scale. |
add_action ¶
add_action(func, *args, start=0, duration=None, flags=0, **kwargs)
Add an action to the simulation
To add an event, you can use <#add_event>.
Arguments
- func (function) : function of template f(simulation, args, *kwargs)
- top (float = 0) : start time for the actiuon
- duration (float = None) : duration of the action (0: call once, None: never stops)
- after (bool = False) : exec the action after the exec_loop
Returns:
Type | Description |
---|---|
- Action : the action added to the simulation
|
|
add_event ¶
add_event(func, *args, start=0, flags=0, **kwargs)
Add an event to the simulation
The event is executed once. To add an action called at each step, use <#add_action>.
Arguments
- func (function) : function of template f(simulation, args, *kwargs)
- top (float = 0) : start time for the actiuon
- after (bool = False) : exec the action after the exec_loop
Returns:
Type | Description |
---|---|
- Action : the event added to the simulation
|
|
change_attribute ¶
change_attribute(attribute, value, incr=None, factor=None)
Modify a points attribute
# gravity
self.add_action("change_attribute", "accel", value=(0, 0, -9.81))
get_frame_state ¶
get_frame_state()
Return state to be saved to resume simulation from the current frame..
Returns:
Type | Description |
---|---|
Any or None
|
Optional state payload |
go ¶
go(subframes=0)
Run this animation once through the engine.
Convenience wrapper for engine.animation(self, subframes=subframes)
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subframes
|
int
|
Number of subframes per frame. |
0
|
Examples:
anim = Animation(compute=lambda: ..., reset=lambda: ..., view=lambda: ...)
anim.go(subframes=4)
newton_law ¶
newton_law(G=1, power=2, min_distance=0.001)
Newton's law between points
The force between two points is given by:
F = G.m1.m2 / dist**p
set_frame_state ¶
set_frame_state(data)
Restore persistent state saved with the current frame.
The simulation can be resume for next frames.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
State payload previously produced by |
required |