Class Simulation

java.lang.Object
com.eco.bio7.compile.Model
com.eco.bio7.simulation.Simulation
Direct Known Subclasses:
AgentModel, GeoAgentModel, GridModel, ValueGridModel

public abstract class Simulation extends Model
The base class of the simulation models of the simulation API (see GridModel, ValueGridModel and AgentModel). A model implements init() (the start state) and step() (one time step). Bio7 calls them with the Setup button and the Play/Pause button (the time interval of the Play/Pause button sets the speed); the model is displayed in an ImageJ image (grids) or in the 3D view (agents).

The same model runs in the web browser: "Export Simulation as HTML..." (in the menu of the Play/Pause button) translates the model class to JavaScript. Fields with the annotation Param become controls of the page and of the "Settings" view in Bio7. The random numbers of random() are the same in Java and JavaScript (same seed, same numbers).

The translation supports a subset of Java: fields, methods, static nested classes, control flow, arrays, Math, lambdas, ArrayList and String concatenation (see the documentation of the export for the details).

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    The derivatives of a system of differential equations: dy/dt = f(t, y).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    boolean
    true (default): the first setup arranges the views in the Custom perspective of Bio7: the display of the model (ImageJ, the 3D view or the WorldWind globe) on the right, its options (e.g., Options3D) top left and the settings left.
    static final int
    The seed of the random numbers (set it in init() with seed(...)).
    int
    The number of the time steps since the setup.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    chance(double p)
    true with the probability p (e.g., chance(0.1): in 10 % of the calls).
    void
    chart(String name, double value)
    A value of a series of the first chart (one value per step; the Charts view of Bio7 and the HTML page).
    void
    chart(String chart, String name, double value)
    A value of a series of another chart with a title (a second, third, ...
    void
    chartBars(String chart, String[] labels, double[] values)
    A bar chart with a title: the labels and the values (replaced in each call, e.g., a histogram).
    void
    chartXY(String chart, String name, double x, double y)
    A point (x, y) of a series of an XY chart with a title (e.g., a phase plot of two populations).
    static double
    clamp(double value, double min, double max)
    The value limited to [min, max].
    void
    click(double x, double y)
    A click of the mouse in the view of the model (override it): for a grid the position in cells (the cell ((int) x, (int) y), y from the top as in get(x, y)), for an agent model the point on the floor of the box.
    static double
    correlation(double[] x, double[] y)
    The correlation coefficient of Pearson.
    static double
    cosDeg(double deg)
    The cosine of an angle in degrees (the same digits in Bio7 and in the browser, e.g., for a movement in the heading).
    static double
    determinant(double[][] a)
    The determinant of a matrix.
    protected abstract void
    Displays the model (ImageJ image or 3D view).
    static double
    distance(double x1, double y1, double x2, double y2)
    The distance of two points in 2D.
    static double
    distance3(double x1, double y1, double z1, double x2, double y2, double z2)
    The distance of two points in 3D.
    static double
    dot(double[] a, double[] b)
    The dot product of two vectors.
    void
    drag(double x, double y)
    A drag of the mouse in the view of the model (override it), e.g., to paint cells: called for the position where the drag started and for each further position (a grid: each new cell).
    void
    drawBox(double x, double y, double z, double w, double h, double d, String fill, String stroke)
    A box in 3D (an agent model): the corner x, y, z (the lowest values), the width (x), the height (y) and the depth (z, upwards) as in box(...); fill: the color of the sides, stroke: the color of the edges (null: none), e.g., a house or a tower.
    void
    drawCircle(double x, double y, double radius, String fill, String stroke)
    A circle (a geospatial agent model: the radius in km).
    void
    drawCircle(double x, double y, double radius, String fill, String stroke, double z)
    A circle at the height z above the floor (an agent model).
    void
    drawImage(String name, double x, double y, double size, double angle)
    An image (loaded with loadImage) centered at x, y: the size (the larger side, in cells of a grid, in pixels on a map or the globe) and the angle in degrees (clockwise, e.g., the heading of an animal).
    void
    drawImage(String name, double x, double y, double size, double angle, double z)
    An image at the height z above the floor (an agent model: the lower edge of the image, standing).
    void
    drawLine(double x1, double y1, double x2, double y2, String color, double width)
    A line (the width in pixels).
    void
    drawLine(double x1, double y1, double x2, double y2, String color, double width, double z)
    A line at the height z above the floor (an agent model).
    void
    drawLine3(double x1, double y1, double z1, double x2, double y2, double z2, String color, double width)
    A line in 3D (an agent model: x, y, z of the box).
    void
    drawPath(double[] xs, double[] ys, String color, double width)
    A line through the points (e.g., the track of an agent).
    void
    drawPath(double[] xs, double[] ys, String color, double width, double z)
    A line through the points at the height z above the floor (an agent model).
    void
    drawPath3(double[] xs, double[] ys, double[] zs, String color, double width)
    A line through the points in 3D (an agent model; the width in pixels), e.g., a flight path.
    void
    drawPillar(double x, double y, double radius, double height, String color)
    A pillar in 3D (an agent model: a vertical cylinder from the floor at x, y of the box with the radius and the height, e.g., an obstacle; color: e.g., "#9aa6b8").
    void
    drawPoint3(double x, double y, double z, double size, String color)
    A point in 3D (an agent model): a small sphere with the diameter size, e.g., a marker.
    void
    drawPolygon(double[] xs, double[] ys, String fill, String stroke)
    A polygon (the fill and the color of the line, null: none; e.g., a pasture or a territory).
    void
    drawPolygon(double[] xs, double[] ys, String fill, String stroke, double z)
    A polygon at the height z above the floor (an agent model).
    void
    drawPolygon3(double[] xs, double[] ys, double[] zs, String fill, String stroke)
    A flat polygon in 3D (an agent model; the points should lie in a plane): the fill and the color of the outline (null: none), e.g., a roof or a ramp.
    void
    drawRect(double x, double y, double w, double h, String fill, String stroke)
    A rectangle (x, y: the upper left corner of a grid).
    void
    drawRect(double x, double y, double w, double h, String fill, String stroke, double z)
    A rectangle at the height z above the floor (an agent model).
    void
    drawSphere(double x, double y, double z, double radius, String fill)
    A sphere in 3D (an agent model): the center and the radius, e.g., a balloon or a tree crown.
    void
    drawText(double x, double y, String text, String color, double size)
    A text (the size in cells of a grid, in pixels on a map or the globe).
    void
    drawText(double x, double y, String text, String color, double size, double z)
    A text at the height z above the floor (an agent model, e.g., a label above an object).
    static double
    fractalNoise(double x, double y, int octaves)
    A fractal noise (0 - 1): the sum of octaves of noise (finer details with more octaves).
    List<com.eco.bio7.simulation.ChartData>
    Copies of all charts (the first chart has the title "").
    List<com.eco.bio7.simulation.Shape>
    The shapes of the current step (a copy).
    The images loaded with loadImage (the name and the file).
    The 3D models loaded with loadModel (the name and the file).
    Map<String, List<double[]>>
    The values of the series of the first chart (name: [step, value] pairs).
    int
    The seed of the setup (default 42; the field Seed of the settings in Bio7).
    static double
    headingOf(double dx, double dy)
    The heading of a movement (dx, dy) in degrees: 0 the direction of y, clockwise (as the angle of drawImage and the heading of the agents).
    abstract void
    Creates the start state (called by the Setup button and after the compilation).
    static double[][]
    inverse(double[][] a)
    The inverse matrix (NaN if the matrix is singular).
    boolean
    True if stop() was called in the last step (or in init()).
    void
    key(String key)
    A key pressed in the view of the model (override it): a character ("a", "A", "1", " ") or the name of a special key ("ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Enter", "Escape", "Backspace", "Delete", "Tab"; the names of the key of JavaScript).
    static double
    lerp(double a, double b, double t)
    The linear interpolation between a and b (t = 0: a, t = 1: b).
    static double[]
    linearRegression(double[] x, double[] y)
    The linear regression y = a + b x: the intercept a, the slope b and the coefficient of determination r².
    void
    loadImage(String name, String file)
    Loads an image (PNG with transparency, JPEG) for drawImage and the agents (agent.image = name).
    void
    loadModel(String name, String file)
    Loads a 3D model (glTF: .glb or .gltf, also animated; Wavefront OBJ with the materials and textures of its .mtl file, y up; STL, binary or ASCII, z up) for the agents (agent.model = name, agent.animation = the name of an animation) and placeModel.
    static double
    logistic(double x)
    The logistic function 1 / (1 + e^-x) (e.g., a smooth switch from 0 to 1).
    static double
    logisticGrowth(double n, double r, double k)
    The logistic growth of a population per time unit: r * n * (1 - n / k).
    static double
    mapRange(double value, double inMin, double inMax, double outMin, double outMax)
    The value of the range [inMin, inMax] in the range [outMin, outMax] (linear).
    static double[][]
    matMul(double[][] a, double[][] b)
    The product of two matrices (rows of columns).
    static double[]
    matVec(double[][] a, double[] v)
    The product of a matrix and a vector (e.g., a Leslie matrix and the age classes).
    static double
    max(double[] values)
    The maximum of the values (-Infinity if empty).
    static double
    mean(double[] values)
    The mean of the values (0 if empty).
    static double
    mean(int[] values)
    The mean of the values (0 if empty).
    static double
    median(double[] values)
    The median of the values.
    static double
    min(double[] values)
    The minimum of the values (Infinity if empty).
    static double
    noise(double x, double y)
    A smooth noise (0 - 1) at x, y (value noise: e.g., a landscape, the grass of a pasture; the same in the browser).
    static double
    norm(double[] a)
    The length of a vector.
    static double
    normalCdf(double x, double mean, double sd)
    The distribution function of the normal distribution (an accuracy of about 1e-7).
    static double
    normalPdf(double x, double mean, double sd)
    The density of the normal distribution.
    protected void
    Prepares the display before init() (called in the thread of the user interface).
    static double
    quantile(double[] values, double p)
    The quantile p (0 - 1) of the values (linear interpolation of the sorted values).
    double
    A random number in [0, 1) (the same numbers in Java and in the HTML export).
    double
    random(double min, double max)
    A random number in [min, max).
    double
    randomAt(int index)
    A random number in [0, 1) for an index (e.g., of a cell or an agent) in this time step: computed from the seed, the time step and the index (no common sequence), so it can be used in parallel threads (e.g., IntStream.range(0, height).parallel().forEach(...)) and gives the same numbers in any order of the threads, in Java and in JavaScript.
    double
    randomAt(int index, int k)
    A random number in [0, 1) for an index and a number k of the draw (several numbers for one index in a step).
    int
    randomBinomial(int n, double p)
    A random number of successes of n trials with the probability p.
    <T> T
    A random element of the list (null if empty).
    double
    randomExponential(double rate)
    An exponentially distributed random number (e.g., a waiting time) with the rate.
    double
    A normally distributed random number (mean 0, standard deviation 1).
    double
    randomGaussian(double mean, double sd)
    A normally distributed random number with the mean and the standard deviation.
    int
    randomInt(int n)
    A random integer in [0, n).
    int
    randomInt(int min, int max)
    A random integer in [min, max) (min included, max excluded).
    int
    randomPoisson(double lambda)
    A Poisson distributed random integer (e.g., the number of events) with the mean lambda.
    int
    randomWeighted(double[] weights)
    A random index chosen with the weights (e.g., a cell with more grass is chosen more often), -1 if all are 0.
    void
    record(String name, double value)
    Records a value of the current step for an Experiment (a column of its table, besides the values of the line charts).
    static double[]
    rk4(Simulation.Derivatives f, double t, double[] y, double dt)
    One step of the Runge-Kutta method (4th order) for dy/dt = f(t, y), e.g., a Lotka-Volterra model:
    void
    run()
    The main method which is called from the calculation thread!
    static double
    sd(double[] values)
    The standard deviation of the values.
    void
    seed(int seed)
    Sets the seed of the random numbers (e.g., in init()).
    void
    setStartSeed(int seed)
    Sets the seed of the next setup (the field Seed of the settings).
    org.eclipse.swt.widgets.Composite
    settings(org.eclipse.swt.widgets.Composite parent)
    An own panel for the settings in Bio7 (null: the settings of the Param fields and Action methods are created).
    void
    The setup method to initialize values etc.!
    void
    shuffle(List<?> list)
    Shuffles the list randomly (e.g., the agents for a random order of the updates).
    static double
    sinDeg(double deg)
    The sine of an angle in degrees (the same digits in Bio7 and in the browser).
    static double[]
    solve(double[][] a, double[] b)
    The solution x of A x = b (Gaussian elimination with partial pivoting; NaN if A is singular).
    static double
    sq(double value)
    The square of the value.
    void
    Starts the model after its creation by the compiler of Bio7: the setup in the thread of the user interface.
    abstract void
    One time step (called by the Play/Pause button).
    void
    Ends the simulation after this step, e.g., if (infected == 0) stop(); in step(): Bio7 pauses the simulation (Play continues it), the HTML page stops, an Experiment ends the run (its last step is recorded).
    static double
    sum(double[] values)
    The sum of the values.
    static double
    sum(int[] values)
    The sum of the values.
    static double[][]
    transpose(double[][] a)
    The transposed matrix.
    static double
    variance(double[] values)
    The variance of the values (n - 1, 0 for less than two values).
    static double
    wrapAround(double value, double size)
    The value on a torus of the size (e.g., wrapAround(-1, 100) = 99).

    Methods inherited from class Model

    close, draw, getGLProfile, run, run, setup, setup
    Modifier and Type
    Method
    Description
    void
    A method to allow closing operations with a compiled Model class called,e.g., from the CustomView implementation.
    void
    The draw method for the Points panel with the Graphics context to draw directly on the panel with available Java routines!
    The OpenGL profile of the 3D view for this model, e.g., GLProfile.GL4 or GLProfile.GL3 (the names of com.jogamp.opengl.GLProfile).
    void
    run(com.jogamp.opengl.GL2 gl, com.jogamp.opengl.glu.GLU glu, com.jogamp.opengl.util.gl2.GLUT glut)
    The main OpenGL method with the OpenGL context as parameters!
    void
    run(com.jogamp.opengl.GLAutoDrawable drawable)
    The main OpenGL method with the drawable of the 3D view (see getGLProfile).
    void
    setup(com.jogamp.opengl.GL2 gl, com.jogamp.opengl.glu.GLU glu, com.jogamp.opengl.util.gl2.GLUT glut)
    The setup OpenGL method with the OpenGL context as parameters!
    void
    setup(com.jogamp.opengl.GLAutoDrawable drawable)
    The setup OpenGL method with the drawable of the 3D view (see getGLProfile), e.g., to create shaders and buffers.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_SEED

      public static final int DEFAULT_SEED
      The seed of the random numbers (set it in init() with seed(...)).
      See Also:
    • t

      public int t
      The number of the time steps since the setup.
    • arrangeViews

      public boolean arrangeViews
      true (default): the first setup arranges the views in the Custom perspective of Bio7: the display of the model (ImageJ, the 3D view or the WorldWind globe) on the right, its options (e.g., Options3D) top left and the settings left. false: the views open in the current perspective.
  • Constructor Details

    • Simulation

      protected Simulation()
  • Method Details

    • startAfterCreation

      public void startAfterCreation()
      Starts the model after its creation by the compiler of Bio7: the setup in the thread of the user interface. It is called after the constructor has finished (a setup from the constructor could run before the fields of the subclass are initialized).
    • init

      public abstract void init()
      Creates the start state (called by the Setup button and after the compilation).
    • step

      public abstract void step()
      One time step (called by the Play/Pause button).
    • display

      protected abstract void display()
      Displays the model (ImageJ image or 3D view).
    • click

      public void click(double x, double y)
      A click of the mouse in the view of the model (override it): for a grid the position in cells (the cell ((int) x, (int) y), y from the top as in get(x, y)), for an agent model the point on the floor of the box. Called between the steps (also when the simulation is paused; the view is updated after the call), in the HTML export with the same values.
      Parameters:
      x - the x position
      y - the y position
    • drag

      public void drag(double x, double y)
      A drag of the mouse in the view of the model (override it), e.g., to paint cells: called for the position where the drag started and for each further position (a grid: each new cell). In the 2D view a drag with the left mouse button, in the 3D view with the Shift key (a drag without it rotates the view). The positions as in click(double, double).
      Parameters:
      x - the x position
      y - the y position
    • key

      public void key(String key)
      A key pressed in the view of the model (override it): a character ("a", "A", "1", " ") or the name of a special key ("ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Enter", "Escape", "Backspace", "Delete", "Tab"; the names of the key of JavaScript). With this method, the view gives the keys to the model (not to its own shortcuts).
      Parameters:
      key - the key
    • prepareDisplay

      protected void prepareDisplay()
      Prepares the display before init() (called in the thread of the user interface).
    • setup

      public void setup()
      Description copied from class: Model
      The setup method to initialize values etc.!
      Overrides:
      setup in class Model
    • stop

      public void stop()
      Ends the simulation after this step, e.g., if (infected == 0) stop(); in step(): Bio7 pauses the simulation (Play continues it), the HTML page stops, an Experiment ends the run (its last step is recorded).
    • isStopped

      public boolean isStopped()
      True if stop() was called in the last step (or in init()).
    • getStartSeed

      public int getStartSeed()
      The seed of the setup (default 42; the field Seed of the settings in Bio7).
    • setStartSeed

      public void setStartSeed(int seed)
      Sets the seed of the next setup (the field Seed of the settings). A seed set in init() with seed(...) has priority.
    • record

      public void record(String name, double value)
      Records a value of the current step for an Experiment (a column of its table, besides the values of the line charts). Without an Experiment, the value is kept but not shown.
    • run

      public void run()
      Description copied from class: Model
      The main method which is called from the calculation thread!
      Overrides:
      run in class Model
    • settings

      public org.eclipse.swt.widgets.Composite settings(org.eclipse.swt.widgets.Composite parent)
      An own panel for the settings in Bio7 (null: the settings of the Param fields and Action methods are created). Create, e.g., a Composite designed with the WindowBuilder: return new MySettings(parent, SWT.NONE);. Its widgets are bound to the model by the names of its fields (a Scale "feed" to the Param field feed, a push Button "addSeed" to the Action method addSeed(), see SimulationSettings.bind(Object, Simulation)). The HTML export creates the controls of the Param fields and Action methods (this method is not exported).
      Parameters:
      parent - the parent of the panel (the "Settings" view)
      Returns:
      the panel or null
    • seed

      public void seed(int seed)
      Sets the seed of the random numbers (e.g., in init()).
    • randomAt

      public double randomAt(int index)
      A random number in [0, 1) for an index (e.g., of a cell or an agent) in this time step: computed from the seed, the time step and the index (no common sequence), so it can be used in parallel threads (e.g., IntStream.range(0, height).parallel().forEach(...)) and gives the same numbers in any order of the threads, in Java and in JavaScript.
    • randomAt

      public double randomAt(int index, int k)
      A random number in [0, 1) for an index and a number k of the draw (several numbers for one index in a step).
    • random

      public double random()
      A random number in [0, 1) (the same numbers in Java and in the HTML export).
    • randomInt

      public int randomInt(int n)
      A random integer in [0, n).
    • random

      public double random(double min, double max)
      A random number in [min, max).
    • randomInt

      public int randomInt(int min, int max)
      A random integer in [min, max) (min included, max excluded).
    • chance

      public boolean chance(double p)
      true with the probability p (e.g., chance(0.1): in 10 % of the calls).
    • randomGaussian

      public double randomGaussian()
      A normally distributed random number (mean 0, standard deviation 1).
    • randomGaussian

      public double randomGaussian(double mean, double sd)
      A normally distributed random number with the mean and the standard deviation.
    • randomExponential

      public double randomExponential(double rate)
      An exponentially distributed random number (e.g., a waiting time) with the rate.
    • randomPoisson

      public int randomPoisson(double lambda)
      A Poisson distributed random integer (e.g., the number of events) with the mean lambda.
    • randomElement

      public <T> T randomElement(List<T> list)
      A random element of the list (null if empty).
    • shuffle

      public void shuffle(List<?> list)
      Shuffles the list randomly (e.g., the agents for a random order of the updates).
    • clamp

      public static double clamp(double value, double min, double max)
      The value limited to [min, max].
    • lerp

      public static double lerp(double a, double b, double t)
      The linear interpolation between a and b (t = 0: a, t = 1: b).
    • mapRange

      public static double mapRange(double value, double inMin, double inMax, double outMin, double outMax)
      The value of the range [inMin, inMax] in the range [outMin, outMax] (linear).
    • wrapAround

      public static double wrapAround(double value, double size)
      The value on a torus of the size (e.g., wrapAround(-1, 100) = 99).
    • sq

      public static double sq(double value)
      The square of the value.
    • distance

      public static double distance(double x1, double y1, double x2, double y2)
      The distance of two points in 2D.
    • distance3

      public static double distance3(double x1, double y1, double z1, double x2, double y2, double z2)
      The distance of two points in 3D.
    • logistic

      public static double logistic(double x)
      The logistic function 1 / (1 + e^-x) (e.g., a smooth switch from 0 to 1).
    • logisticGrowth

      public static double logisticGrowth(double n, double r, double k)
      The logistic growth of a population per time unit: r * n * (1 - n / k).
    • sum

      public static double sum(double[] values)
      The sum of the values.
    • sum

      public static double sum(int[] values)
      The sum of the values.
    • mean

      public static double mean(double[] values)
      The mean of the values (0 if empty).
    • mean

      public static double mean(int[] values)
      The mean of the values (0 if empty).
    • variance

      public static double variance(double[] values)
      The variance of the values (n - 1, 0 for less than two values).
    • sd

      public static double sd(double[] values)
      The standard deviation of the values.
    • min

      public static double min(double[] values)
      The minimum of the values (Infinity if empty).
    • max

      public static double max(double[] values)
      The maximum of the values (-Infinity if empty).
    • rk4

      public static double[] rk4(Simulation.Derivatives f, double t, double[] y, double dt)
      One step of the Runge-Kutta method (4th order) for dy/dt = f(t, y), e.g., a Lotka-Volterra model:
      y = rk4((t, v) -> new double[] { a * v[0] - b * v[0] * v[1], c * v[0] * v[1] - d * v[1] }, t, y, 0.01);
      
      Returns:
      the values at t + dt (a new array)
    • dot

      public static double dot(double[] a, double[] b)
      The dot product of two vectors.
    • norm

      public static double norm(double[] a)
      The length of a vector.
    • matMul

      public static double[][] matMul(double[][] a, double[][] b)
      The product of two matrices (rows of columns).
    • matVec

      public static double[] matVec(double[][] a, double[] v)
      The product of a matrix and a vector (e.g., a Leslie matrix and the age classes).
    • transpose

      public static double[][] transpose(double[][] a)
      The transposed matrix.
    • solve

      public static double[] solve(double[][] a, double[] b)
      The solution x of A x = b (Gaussian elimination with partial pivoting; NaN if A is singular).
    • inverse

      public static double[][] inverse(double[][] a)
      The inverse matrix (NaN if the matrix is singular).
    • determinant

      public static double determinant(double[][] a)
      The determinant of a matrix.
    • linearRegression

      public static double[] linearRegression(double[] x, double[] y)
      The linear regression y = a + b x: the intercept a, the slope b and the coefficient of determination r².
    • correlation

      public static double correlation(double[] x, double[] y)
      The correlation coefficient of Pearson.
    • quantile

      public static double quantile(double[] values, double p)
      The quantile p (0 - 1) of the values (linear interpolation of the sorted values).
    • median

      public static double median(double[] values)
      The median of the values.
    • normalPdf

      public static double normalPdf(double x, double mean, double sd)
      The density of the normal distribution.
    • normalCdf

      public static double normalCdf(double x, double mean, double sd)
      The distribution function of the normal distribution (an accuracy of about 1e-7).
    • noise

      public static double noise(double x, double y)
      A smooth noise (0 - 1) at x, y (value noise: e.g., a landscape, the grass of a pasture; the same in the browser).
    • fractalNoise

      public static double fractalNoise(double x, double y, int octaves)
      A fractal noise (0 - 1): the sum of octaves of noise (finer details with more octaves).
    • cosDeg

      public static double cosDeg(double deg)
      The cosine of an angle in degrees (the same digits in Bio7 and in the browser, e.g., for a movement in the heading).
    • sinDeg

      public static double sinDeg(double deg)
      The sine of an angle in degrees (the same digits in Bio7 and in the browser).
    • headingOf

      public static double headingOf(double dx, double dy)
      The heading of a movement (dx, dy) in degrees: 0 the direction of y, clockwise (as the angle of drawImage and the heading of the agents).
    • randomBinomial

      public int randomBinomial(int n, double p)
      A random number of successes of n trials with the probability p.
    • randomWeighted

      public int randomWeighted(double[] weights)
      A random index chosen with the weights (e.g., a cell with more grass is chosen more often), -1 if all are 0.
    • chart

      public void chart(String name, double value)
      A value of a series of the first chart (one value per step; the Charts view of Bio7 and the HTML page).
    • chart

      public void chart(String chart, String name, double value)
      A value of a series of another chart with a title (a second, third, ... chart, one value per step).
    • chartXY

      public void chartXY(String chart, String name, double x, double y)
      A point (x, y) of a series of an XY chart with a title (e.g., a phase plot of two populations).
    • chartBars

      public void chartBars(String chart, String[] labels, double[] values)
      A bar chart with a title: the labels and the values (replaced in each call, e.g., a histogram).
    • getSeries

      public Map<String, List<double[]>> getSeries()
      The values of the series of the first chart (name: [step, value] pairs).
    • getCharts

      public List<com.eco.bio7.simulation.ChartData> getCharts()
      Copies of all charts (the first chart has the title "").
    • drawLine

      public void drawLine(double x1, double y1, double x2, double y2, String color, double width)
      A line (the width in pixels).
    • drawLine

      public void drawLine(double x1, double y1, double x2, double y2, String color, double width, double z)
      A line at the height z above the floor (an agent model).
    • drawLine3

      public void drawLine3(double x1, double y1, double z1, double x2, double y2, double z2, String color, double width)
      A line in 3D (an agent model: x, y, z of the box).
    • drawPillar

      public void drawPillar(double x, double y, double radius, double height, String color)
      A pillar in 3D (an agent model: a vertical cylinder from the floor at x, y of the box with the radius and the height, e.g., an obstacle; color: e.g., "#9aa6b8").
    • drawPath

      public void drawPath(double[] xs, double[] ys, String color, double width)
      A line through the points (e.g., the track of an agent).
    • drawPath

      public void drawPath(double[] xs, double[] ys, String color, double width, double z)
      A line through the points at the height z above the floor (an agent model).
    • drawPolygon

      public void drawPolygon(double[] xs, double[] ys, String fill, String stroke)
      A polygon (the fill and the color of the line, null: none; e.g., a pasture or a territory).
    • drawPolygon

      public void drawPolygon(double[] xs, double[] ys, String fill, String stroke, double z)
      A polygon at the height z above the floor (an agent model).
    • drawCircle

      public void drawCircle(double x, double y, double radius, String fill, String stroke)
      A circle (a geospatial agent model: the radius in km).
    • drawCircle

      public void drawCircle(double x, double y, double radius, String fill, String stroke, double z)
      A circle at the height z above the floor (an agent model).
    • drawRect

      public void drawRect(double x, double y, double w, double h, String fill, String stroke)
      A rectangle (x, y: the upper left corner of a grid).
    • drawRect

      public void drawRect(double x, double y, double w, double h, String fill, String stroke, double z)
      A rectangle at the height z above the floor (an agent model).
    • drawText

      public void drawText(double x, double y, String text, String color, double size)
      A text (the size in cells of a grid, in pixels on a map or the globe).
    • drawText

      public void drawText(double x, double y, String text, String color, double size, double z)
      A text at the height z above the floor (an agent model, e.g., a label above an object).
    • drawImage

      public void drawImage(String name, double x, double y, double size, double angle)
      An image (loaded with loadImage) centered at x, y: the size (the larger side, in cells of a grid, in pixels on a map or the globe) and the angle in degrees (clockwise, e.g., the heading of an animal).
    • drawImage

      public void drawImage(String name, double x, double y, double size, double angle, double z)
      An image at the height z above the floor (an agent model: the lower edge of the image, standing).
    • drawPoint3

      public void drawPoint3(double x, double y, double z, double size, String color)
      A point in 3D (an agent model): a small sphere with the diameter size, e.g., a marker.
    • drawPath3

      public void drawPath3(double[] xs, double[] ys, double[] zs, String color, double width)
      A line through the points in 3D (an agent model; the width in pixels), e.g., a flight path.
    • drawBox

      public void drawBox(double x, double y, double z, double w, double h, double d, String fill, String stroke)
      A box in 3D (an agent model): the corner x, y, z (the lowest values), the width (x), the height (y) and the depth (z, upwards) as in box(...); fill: the color of the sides, stroke: the color of the edges (null: none), e.g., a house or a tower.
    • drawSphere

      public void drawSphere(double x, double y, double z, double radius, String fill)
      A sphere in 3D (an agent model): the center and the radius, e.g., a balloon or a tree crown.
    • drawPolygon3

      public void drawPolygon3(double[] xs, double[] ys, double[] zs, String fill, String stroke)
      A flat polygon in 3D (an agent model; the points should lie in a plane): the fill and the color of the outline (null: none), e.g., a roof or a ramp.
    • getDrawing

      public List<com.eco.bio7.simulation.Shape> getDrawing()
      The shapes of the current step (a copy).
    • loadImage

      public void loadImage(String name, String file)
      Loads an image (PNG with transparency, JPEG) for drawImage and the agents (agent.image = name). A relative path is searched in the project of the model; the HTML export embeds the image.
    • loadModel

      public void loadModel(String name, String file)
      Loads a 3D model (glTF: .glb or .gltf, also animated; Wavefront OBJ with the materials and textures of its .mtl file, y up; STL, binary or ASCII, z up) for the agents (agent.model = name, agent.animation = the name of an animation) and placeModel. A relative path is searched in the project of the model; the HTML export embeds the model (OBJ and STL converted to glTF).
    • getImageFiles

      public Map<String,String> getImageFiles()
      The images loaded with loadImage (the name and the file).
    • getModelFiles

      public Map<String,String> getModelFiles()
      The 3D models loaded with loadModel (the name and the file).