search

Class myphysicslab.sims.roller.PathObserver

Provided By
All Implemented Interfaces

Automatically creates a DisplayPath when a NumericalPath is added to a SimList. Observes the SimList of a Simulation, adding or removing DisplayPath to represent the NumericalPath in SimView with a zIndex of -10 so that it appears underneath other objects.

Note that the DisplayPath shows only a single NumericalPath, and is destroyed when that NumericalPath is removed from the SimList.

Setting Style of DisplayPath

To control the style (color, line thickness, etc) used for a particular DisplayPath there are two approaches:

1. Modify the DisplayPath style directly

Modify the DisplayPath's style directly, for example:

var dispPath1 = simView.getDisplayList().find(path1);
dispPath1.setStyle(0, DrawingStyle.lineStyle('red', 2));

2. Modify the prototype

PathObserver has a prototype DisplayPath. When a display property of a DisplayPath is undefined, then the property is fetched from the prototype DisplayPath. If it is also undefined on the prototype then a default value is used.

Keep in mind that all objects with a given prototype will be affected by any changes made to the prototype.

Here is an example where we set the prototype to have a thin blue line.

var pathObs = new PathObserver(simList, simView, null);
pathObs.protoDisplayPath.setStyle(0, DrawingStyle.lineStyle('blue', 1));

Resize the SimView to match NumericalPath

Often we want the SimView's dimensions to match that of the NumericalPath. To have the PathObserver change the bounding rectangle of the SimView to match that of the NumericalPath, specify the simRectSetter argument in the constructor. This will occur whenever the NumericalPath changes.

new PathObserver( simList, simView, simRectSetter, opt_expand )

Parameters
simListmyphysicslab.lab.model.SimList

SimList to observe

simViewmyphysicslab.lab.view.SimView

the SimView to add DisplayObjects to

simRectSetter(function(myphysicslab.lab.util.DoubleRect): ?|null)

function to use for resizing the simulation rectangle of the SimView; if null then resizing is not done

opt_expand(number|undefined)

factor to multiply the width and height by to expand the path bounds, which yields the rectangle used for resizing the SimView. For example, 1.1 will make the bounds 10% larger.

Instance Methods

Instance Properties

Type Definitions