A generic Memorizable object that calls a JavaScript function.

Example 1

Make a GenericMemo that prints the angle variable of a simulation into the Terminal output area. Here simRun is an instance of SimRunner.

var angle = sim.getVarsList().getVariable('ANGLE');
var memo = new GenericMemo(()=> println('angle: '+angle.getValue()));
simRun.addMemo(memo);

This code can be entered as Terminal commands in Pendulum.

Use the following to turn off the GenericMemo:

simRun.removeMemo(memo);

Example 2

This sets the color of a spring depending on how much it is stretched.

var spring = simList.get('spring1');
var dispSpring = displayList.findSpring(spring);
var memo = new GenericMemo(function() {
var stretch = Math.max(Math.min(spring.getStretch(), 1), -1);
if (stretch < 0) {
dispSpring.setColorCompressed(Util.colorString3(-stretch, 0, 0));
} else {
dispSpring.setColorExpanded(Util.colorString3(0, stretch, 0));
}
});
simRun.addMemo(memo);

This script can be entered as Terminal commands in Cart + Pendulum with Physics Engine.

Example 3

This stops a simulation after 2 seconds. Clicking the "play" button will then continue the simulation, because once has been set false. To re-enable the behavior, set once to true.

var once = true;
var memo = new GenericMemo(function(){
if (once && sim.getTime()>2)
{once=false;simRun.pause()}
});
simRun.addMemo(memo);

This script can be entered as Terminal commands in any simulation.

Implements

Constructors

Properties

Methods

Constructors

  • Parameters

    • func: (() => void)

      function to execute

        • (): void
        • Returns void

    • Optional opt_purpose: string

      Describes what this GenericMemo does, for developers

    Returns GenericMemo

Properties

purpose_: string

Describes what this GenericMemo does, for developers

Methods

  • Memorize the current simulation data, or do some other function that should happen regularly after each simulation time step.

    Returns void

  • Returns a minimal string representation of this object, usually giving just identity information like the class name and name of the object.

    For an object whose main purpose is to represent another Printable object, it is recommended to include the result of calling toStringShort on that other object. For example, calling toStringShort() on a DisplayShape might return something like this:

    DisplayShape{polygon:Polygon{'chain3'}}
    

    Returns string

    a minimal string representation of this object.

Generated using TypeDoc