Class SimulationRecorder
java.lang.Object
com.eco.bio7.spatial.SimulationRecorder
Records a simulation written in Java (e.g., a Bio7 model) step by step and
exports it to an HTML page which plays the recording: Play/Pause, Step,
Reset, the speed, a timeline to jump to a step, a loop and the chart (see
HtmlSimulation for the views). The model runs in Java (any model, the exact
results), the page only plays the recorded frames (the settings of the model
cannot be changed in the page).
Each step adds a frame with the data of the view: a grid of cells (GRID_2D, with optional agents), points and lines (SCENE_3D) or a surface (SURFACE_3D) and the values of the chart.
SimulationRecorder recorder = new SimulationRecorder("Game of Life").view(HtmlSimulation.View.GRID_2D)
.palette(0xFFFFFF, 0x1F3A93).chart("Population");
for (int t = 0; t < 300; t++) {
step(); // the model
recorder.frame().grid(width, height, cells).chart("Population", alive);
}
recorder.export("/path/life.html");
In a Bio7 model the frame can be recorded in the run method (e.g., if
SpatialUtil.canStep() is true) and exported after a number of frames.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe data of a step: the grid, the agents, the points, the lines, the surface and the chart values. -
Constructor Summary
ConstructorsConstructorDescriptionSimulationRecorder(String title) Creates a recorder with the title of the page. -
Method Summary
Modifier and TypeMethodDescriptionagents(double radius, int color) The radius (in cells) and the color of the agents of a grid (if not each agent has a color).autoplay(boolean autoplay) Plays the recording when the page is opened (default false).background(String color) The background color of the view (e.g., "#ffffff").box(double width, double height, double depth) The size of the box of the 3D views (the points are in these coordinates, default 1, 1, 1).Displays a chart of the recorded values (see Frame.chart).clear()Removes the recorded frames.colorMap(int[] ramp) The color map for continuous values of a grid or a surface (e.g., PlotLegend.VIRIDIS).description(String description) A description below the title.Writes the HTML page of the recording.frame()Adds a new frame (a step of the simulation) and returns it for the data.intframes()Returns the number of the recorded frames.lineColor(int color) The color of the lines (if not each line has a color).loop(boolean loop) Plays the recording again from the start at the end (default true, a check box of the page).maxFrames(int maxFrames) The maximum number of the frames (default 100000, further frames are ignored).palette(int... colors) The colors (0xRRGGBB) of the integer states of a grid (state 0, 1, 2, ...).points(double radius, int color) The radius of the points (in the coordinates of the box) and their color (if not each point has a color).range(double min, double max) The range of the values of the color map (and the height of a surface), default: the range of all frames.record(int steps, Consumer<SimulationRecorder.Frame> step) Records a number of steps: the function is called for each step with a new frame (it computes the step of the model and adds the data to the frame).speed(double framesPerSecond) The default speed in frames per second (default 20).toHtml()Returns the HTML page of the recording.view(HtmlSimulation.View view) The view (default GRID_2D).
-
Constructor Details
-
SimulationRecorder
Creates a recorder with the title of the page.
-
-
Method Details
-
description
A description below the title. -
view
The view (default GRID_2D). -
palette
The colors (0xRRGGBB) of the integer states of a grid (state 0, 1, 2, ...). -
colorMap
The color map for continuous values of a grid or a surface (e.g., PlotLegend.VIRIDIS). -
range
The range of the values of the color map (and the height of a surface), default: the range of all frames. -
box
The size of the box of the 3D views (the points are in these coordinates, default 1, 1, 1). -
points
The radius of the points (in the coordinates of the box) and their color (if not each point has a color). -
lineColor
The color of the lines (if not each line has a color). -
agents
The radius (in cells) and the color of the agents of a grid (if not each agent has a color). -
speed
The default speed in frames per second (default 20). -
chart
Displays a chart of the recorded values (see Frame.chart). -
loop
Plays the recording again from the start at the end (default true, a check box of the page). -
autoplay
Plays the recording when the page is opened (default false). -
background
The background color of the view (e.g., "#ffffff"). -
maxFrames
The maximum number of the frames (default 100000, further frames are ignored). -
frame
Adds a new frame (a step of the simulation) and returns it for the data.- Returns:
- the frame
-
frames
public int frames()Returns the number of the recorded frames. -
clear
Removes the recorded frames. -
record
Records a number of steps: the function is called for each step with a new frame (it computes the step of the model and adds the data to the frame).- Parameters:
steps- the number of the stepsstep- the step of the model and the data of the frame- Returns:
- the recorder
-
toHtml
Returns the HTML page of the recording. -
export
Writes the HTML page of the recording.- Parameters:
file- the HTML file- Returns:
- the recorder
- Throws:
IOException- if the file cannot be written
-