The simulation package can draw animated vector images to a tkinter canvas.
Contents:
Inside the loop.py module is defined the main algorithm for a simulation time loop. The simulation loop is responsible for timing the different tasks that take place in a simulation:
- calls the function that updates the model
- redraws the graphic representation of the model
- times the amount of time taken in this process and sleeps for some time in order for the loop to run in equally timed cycles
- updates the frame count and the total elapsed time
- checks if the loop should continue; exits otherwise
The main_loop
function expects four parameters:
update_fn
: a function that updates the simulation modelredraw_fn
: a function that redraws the model in its current state to the screenshould_continue_fn
: a predicate function that determines when the loop should run and when it should be endedframe_rate_s
: the frame rate given in seconds (inverse of the frames per second, defaults to 0.03s)
In order to draw the simulated model to a tkinter canvas, the CanvasDrawing
wrapper class is provided.