search

Class myphysicslab.lab.util.GenericMemo

Provided By
All Implemented Interfaces

A generic Memorizable object that calls a JavaScript function.

Example 1

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

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

This code can be entered as Terminal commands in myphysicslab.sims.pendulum.PendulumApp if using simple-compiled version.

Example 2

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

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

This script can be entered as Terminal commands in myphysicslab.sims.engine2D.CartPendulum2App if using simple-compiled version.

new GenericMemo( func, opt_purpose )

Parameters
funcfunction(): ?

function to execute

opt_purpose(string|undefined)

Describes what this GenericMemo does, for debugging

Instance Methods