public class Behavior extends java.lang.Object { // Methods public Behavior bvrHook(BvrCallback callback); public Behavior debug(); public Behavior debug(String name); public Behavior debug(String name, boolean onStart); public Behavior debug(String name, boolean onStart, PrintStream std); public Behavior duration(NumberBvr length) public Object extract(); public void init(Behavior a); public Behavior repeat(int repetitions); public Behavior repeatForever(); public Behavior runOnce(); public Behavior substituteTime(NumberBvr a); }
All behaviors are potentially time-varying and/or reactive values such as colors, numbers and images. They can be used to construct animated objects. All behavior subclasses inherit the methods of this class.
Because all behaviors are potentially time-varying and/or reactive, their values can change as a function of time or as the result of user input. Time-varying behaviors are created by combining time-based default behaviors (such as localTime) with other behaviors. Reactive behaviors are created using the until, untilEx, and untilNotify methods and specifying input events, such as mouse clicks. Complex behaviors can be built by combining existing behaviors. The value of a complex behavior always depends on the values of the behaviors that comprise it.
Behaviors are started either by the createModel method (which means they start at time = 0) or with the untilNotify.notify method, when they are started at the event time. When a behavior runs, its time-varying and reactive qualities are active. This means the user can experience any changes that occur in the behavior as time passes or events occur.
In order to type-check behaviors, all behavior types must be known at construction time. This is why there is no Behavior.newUninitBvr() method included in the Behavior class. notifier);
Allows a running behavior to be sampled.
public Behavior BvrHook(
BvrCallback callback
);
Returns the Behavior object that is the value of the running behavior at the time it was sampled.
Gives the following information about a running behavior:
The method assumes the following defaults:
The following example shows that, when it was started, the second instance of a behavior was started at a global time of 39.66 seconds, and had a value of 0.5:
2 started at 39.66 result = 0.5
public Behavior debug( );
This method is unavailable to viewers that don't display the standard output.
Gives the following information about a running behavior:
The method assumes the following defaults:
The following example shows that, when it was started, the second instance of a behavior called "b" was started at a global time of 39.66 seconds, and had a value of 0.5:
"b" 2 started at 39.66 result = 0.5
The next example displays a solid-colored image whose red and green components are 1, and whose blue component is time-varying. The NumberBvr x initially has a value of "b" (a value that varies over time) . When the left button of the mouse is pressed, "b" (and therefore, "x" starts all over again, with a value of 0.5.
The debugging information (shown in the previous example) is displayed each time the left mouse button is pressed.
import com.ms.dxmedia.*; public class DebugTest extends DXMApplet{ public DebugTest() { // Set the model setModel(new DebugTestModel()) ; } } class DebugTestModel extends Model { public void createModel(BvrsToRun extraBvrsToRun) { NumberBvr b = (NumberBvr) add(localTime, toBvr(0.5)).Debug("b"); NumberBvr x = NumberBvr.newUninitBvr(); x.init(until(b, leftButtonDown, x)); ImageBvr model = solidColorImage(colorRgb(toBvr(1), toBvr(1), x)); setImage(model); } }
public Behavior debug(
String name
);
Returns the Behavior object.
This method is unavailable to viewers that don't display the standard output.
Gives the following information about a running behavior:
This method assumes the information is displayed on the standard output.
The following example shows that, when it was started, the second instance of a behavior called "b" was started at a global time of 39.66 seconds, and had a value of 0.5:
"b" 2 started at 39.66 result = 0.5
public Behavior debug(
String name,
boolean onStart
);
Returns the Behavior object.
This method is unavailable to viewers that don't display the standard output.
Gives the following information about a running behavior:
The following example shows that, when it was started, the second instance of a behavior called "b" was started at a global time of 39.66 seconds, and had a value of 0.5:
"b" 2 started at 39.66 result = 0.5
public Behavior debug(
String name,
boolean onStart,
PrintStream std
);
Returns the Behavior object.
This method is unavailable to viewers that don't display the standard output.
Creates an animation fragment by associating a local "stop time" with a behavior. The result is a new behavior that is the same as the original behavior for the length of the duration. Once the duration is over, the behavior is a snapshot of the behavior's state when the duration ended.
public Behavior duration(
NumberBvr length
)
Returns the Behavior object.
Extracts the value of the behavior, returning a Java object. This behavior must have a constant value.
public Object extract( );
Returns a Java object. For more information about java.lang.Object objects, consult a Java reference.
Initializes a behavior created by the newUninit method.
public void init(
Behavior a
)
Creates a behavior that repeats itself the number of times specified by repetitions.
public Behavior repeat(
int repetitions
);
Returns the Behavior object.
Creates a behavior that repeats infinitely.
public Behavior repeatForever( );
Returns the Behavior object.
Used when applications must reference a running behavior once it starts running, but don't require the application to explicitly start that behavior. The following code fragment plays 2 movies. The first movie plays from the beginning for 10 seconds. It then fades, over a 2 second interval, into a second movie. (Assume the existence of a fade method.)
ImageBvr movie1Once = (ImageBvr)movie1.runOnce(); ImageBvr movie2Once = (ImageBvr)movie2.runOnce(); until(movie1Once, timer(toBvr(10)), until(fade(div(localTime, toBvr(2)), movie1Once, movie2Once), timer(toBvr(2)), movie2Once);
public Behavior runOnce( );
Creates a new behavior from an existing Behavior and a NumberBvr. In the new behavior, the number behavior replaces all occurrences of localTime in the original behavior. (This includes behaviors where localTime is implicit, such as imported movies. The method can be used even if localTime isn't explicitly in the code.) This allows behaviors to be, for example, time-scaled to run faster or slower, time-shifted to start at a different time, or frozen at a particular point in time. Here are some examples:
//A point moving 1 unit in x/second, starting at 0 b0 = point2(localTime, toBvr(0)); //Create new behavior moving 0.5 units/second, //by replacing localTime with localTime/2 b1 = origBvr.substituteTime(div(localTime, toBvr(2))); //Create new behavior moving 1 unit/second, //starting at 33, by replacing localTime with localTime + 33 b2 = origBvr.substituteTime(add(localTime, toBvr(33)); //Create new behavior moving 2 units/second, starting at 33, //by replacing localTime with (localTime *2) + 33 b3 = origBvr.substituteTime(add(mul(localTime, toBvr(2)), toBvr(33)); //Freeze the original behavior at time 77 b4 = origBvr.substituteTime(toBvr(77)); //Tie the new behavior to the x-component of the mouse b5 = origBvr.substituteTime(mousePosition.getX()); //Show that replacements are cumulative. The following sequence: c0 = point2(localTime, toBvr(0)); c1 = c0.substituteTime(add(localTime, toBvr(33))); c2 = c1.substituteTime(mul(localTime, toBvr(2))); //is equivalent to: c0.substituteTime(add(mul(localTime, toBvr(2))), toBvr(33));
public Behavior substituteTime(
NumberBvr a
);
Returns the Behavior object.
The following methods are defined in the Statics class and are most relevant to objects of type Behavior.
public static Behavior cond(BooleanBvr bool, Behavior a, Behavior b);
public static Behavior sequence(Behavior a, Behavior b);
public static Behavior until(Behavior a, DXMEvent e, Behavior b);
public static Behavior untilEx(Behavior a, DXMEvent e);
public static Behavior untilNotify(Behavior a, DXMEvent e, UntilNotifier notifier);
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.