animator4
Class Animator

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Panel
              extended byjava.applet.Applet
                  extended byedu.davidson.tools.SApplet
                      extended byanimator4.Animator
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class Animator
extends SApplet

Animator is designed to animate geometric shapes or images on the screen. Objects can move along a predefined trajectory or in response to a force.

The following embedding parameters are defined:

Parameter  Value Description
FPS 10 Frames per second.
dt 0.1 Animation time step per frame.
ShowControls true Show VCR buttons at bottom of applet.
GridUnit 1.0 The grid spacing.  A value of 0 will suppress the grid.
PixPerUnit 10 Conversion factor from pixel units to world units.

Various objects in Animator implement the data source interface.  This interface, SDataSource, enables inter-applet data passing between Physlets.

Object Identifier Variables
images id=addImage(String file,String xStr,String yStr) t, x, y, vx, vy, ax, ay, m
All shapes: circle, rectangle, box, arrow, etc. The id is returned when an object is created using an add method. t, x, y, vx, vy, ax, ay, m
clock id=getClockID() t
ensemble id=getEnsembleID() t, xcm, ycm, px, py , m , ke

See Also:
Serialized Form

Field Summary
 
Fields inherited from class edu.davidson.tools.SApplet
destroyed
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Method Summary
 int addArrow(java.lang.String hStr, java.lang.String vStr, java.lang.String xStr, java.lang.String yStr)
          Adds an arrow, i.e. vector, to the animation.
 int addBox(int w, int h, java.lang.String xStr, java.lang.String yStr)
          Adds a box to the animation.
 int addCalculation(java.lang.String text, java.lang.String calc, java.lang.String xStr, java.lang.String yStr)
          Adds a calculated value, i.e., a function of time that is calculated as a number, to the animation.
 int addCaption(java.lang.String text, java.lang.String calc)
          Add a caption to the animation.
 int addCircle(int diameter, java.lang.String xStr, java.lang.String yStr)
          Adds a filled circle to the animation.
 int addConnectorLine(int id1, int id2)
          Adds a connecting line between two objects.
 int addConnectorSpring(int id1, int id2)
          Adds a connecting spring between two objects.
 int addCursor(int diameter, java.lang.String xStr, java.lang.String yStr)
          Add a cursor to the animation.
 int addExShell(int tickness, java.lang.String rStr, java.lang.String xStr, java.lang.String yStr)
          Adds an expanding shell to the animation.
 int addImage(java.lang.String file, java.lang.String xStr, java.lang.String yStr)
          Adds an image to the animation.
 int addImageFromCodeBase(java.lang.String file, java.lang.String xStr, java.lang.String yStr)
          Adds an image to the animation.
 int addImageFromDocumentBase(java.lang.String file, java.lang.String xStr, java.lang.String yStr)
          Add an image to the animation.
 boolean addInteraction(int id1, int id2, java.lang.String force, java.lang.String mode)
          Adds an interaction between two particles, Force(x,y,r,v,t).
 int addLine(java.lang.String hStr, java.lang.String vStr, java.lang.String xStr, java.lang.String yStr)
          Adds a line to the animation.
 int addObject(java.lang.String name, java.lang.String parList)
          Creates an object and adds it to the Physlet.
 int addParametricCurve(int n, double start, double stop, java.lang.String xStr, java.lang.String yStr)
          Plot a function.
 int addPiston(int s, java.lang.String hStr, java.lang.String vStr, java.lang.String xStr, java.lang.String yStr)
          Add a piston, i.e. a rectangle that changes size, to the animation.
 int addPolyShape(int n, java.lang.String hStr, java.lang.String vStr, java.lang.String xStr, java.lang.String yStr)
          Add a polygon to the animation.
 int addRectangle(int w, int h, java.lang.String xStr, java.lang.String yStr)
          Adds a solid rectangle to the animation.
 int addRelPolyShape(int n, java.lang.String hStr, java.lang.String vStr, java.lang.String xStr, java.lang.String yStr)
          Add a polygon to the animation.
 int addShell(int diameter, java.lang.String xStr, java.lang.String yStr)
          Adds a circular shell to the animation.
 int addSpring(java.lang.String hStr, java.lang.String vStr, java.lang.String xStr, java.lang.String yStr)
          Add a spring to the animation.
 int addText(java.lang.String text, java.lang.String xStr, java.lang.String yStr)
          Adds text to the animation.
 void deleteObject(int id)
          Delete an object from the applet.
 void forward()
          Start the animation.
 double getAnimationTime()
          Get the animation time.
 int getAppletCount()
          Counts the number of applets on the html page.
 java.lang.String getAppletInfo()
          Method getAppletInfo
 int getCollisionID()
          Get the id for collisions.
 int getEnsembleID()
          Get the id for the ensemble of objects.
 double getFx(int id)
          Gets the x component of the force acting on an object.
 double getFy(int id)
          Get the y component of the force acting an object.
 double getH(int id)
          Get the height of an object.
 java.lang.String[][] getParameterInfo()
          Method getParameterInfo
 animator4.AnimatorCanvas getPhysletCanvas()
          Get the Canvas so that Animator can be used in EJS for drawing.
 double getVX(int id)
          Get the x component of an object's velocity.
 double getVY(int id)
          Get the y component of an object's velocity.
 double getW(int id)
          Get the width of an object.
 double getX(int id)
          Gets the x position of an object.
 double getXPos(int id)
          Bug-fix to get the x of an object on Netscape and Sun.
 double getY(int id)
          Gets the y position of an object.
 double getYPos(int id)
          Bug-fix to get the y of an object on Netscape and Sun.
 void pause()
          Pause the animation.
 void reset()
          Clear data from all dataConnections and reset the animation time to 0.
 void reverse()
          Reverse the direction of the time step in the animation.
 boolean setAnimationSlave(int masterID, int slaveID)
          Force an object to follow another object on the screen.
 void setAnimationTime(double time)
          Set the animation time.
 void setAutoRefresh(boolean auto)
          Force the applet to repaint whenever any object changes its properties.
 boolean setBouncy(int id, boolean bounce)
          Make the object bouncy.
 int setCaption(java.lang.String s)
          Add a caption to the applet.
 boolean setCharge(int id, double q)
          Sets the charge on a Charge object.
 void setCollisionMessage(java.lang.String msg)
          Display a message in the yellow message box.
 boolean setConstrainR(int id, double r, double x, double y)
          Constrain the motion of the object to a circular path.
 boolean setConstrainX(int id, double x, double min, double max)
          Constrains the motion of the object to a path of constant x.
 boolean setConstrainY(int id, double y, double min, double max)
          Constrains the motion of the object to a path of constant y.
 boolean setCoordinateOffset(int id, int xOff, int yOff)
          Offset the object's coordinates on the screen.
 void setDampOnMousePressed(boolean damp)
          Set the velocity of an object to zero if it is being dragged.
 void setDefault()
          Set default values and deletes all data connections.
 boolean setDisplayOffset(int id, int xOff, int yOff)
          Offset the object's position on the screen from its default drawing position.
 boolean setDragable(int id, boolean canDrag)
          Make the object with the given id dragable.
 boolean setFont(int id, java.lang.String family, int style, int size)
          Sets the object's font if the object has text that can be displayed.
 boolean setFootPrints(int id, int n)
          Set the trail to leave footprints as the object moves.
 boolean setForce(int id, java.lang.String fxStr, java.lang.String fyStr, double x0, double y0, double vx0, double vy0)
          Set the Force on a particle.
 boolean setFormat(int id, java.lang.String fstr)
          Change the object's format for the display of numeric data.
 boolean setGhost(int id, boolean ghost)
          Have the object draw ghost images as it moves.
 void setGridUnit(double gu)
          Set the grid spacing in world, i.e., not pixel, units.
 boolean setH(int id, double h)
          Change the height of an object.
 boolean setLabel(int id, java.lang.String label)
          Make the object label.
 boolean setMass(int id, double m)
          Set the mass of an object.
 void setMessage(java.lang.String msg)
          Display a message in the yellow message box.
 boolean setObjectFont(int id, java.lang.String family, int style, int size)
          Sets the object's font if the object has text that can be displayed.
 void setOneShot(double min, double max, java.lang.String msg)
          Set the applet to run for a fixed interval, stop, and display a message.
 boolean setOnScreenSize(int id, int size)
          Set a size parameter for an object.
 boolean setPaintBeforeGrid(int id, boolean before)
          Have the object draw itself before the grid is drawn.
 void setPixPerUnit(int pu)
          Set the pixels per unit.
 boolean setReferenceFrame(int id)
          Sets the reference frame.
 boolean setResizable(int id, boolean isResizable)
          Make an object resizable.
 boolean setRGB(int id, int r, int g, int b)
          Set the color of an object.
 void setShapeRGB(int r, int g, int b)
          Set the red, green, and blue color values for all subsequent drawing.
 boolean setShowAComponents(int id, boolean show)
          Have the object show its acceleration components.
 boolean setShowAVector(int id, boolean show)
          Have the object show its acceleration vector.
 boolean setShowConstraintPath(int id, boolean sc)
          Show the objects trajectory constraint if it exists.
 boolean setShowCoordinates(int id, boolean show)
          Have the object show its coordinates on screen.
 boolean setShowFComponents(int id, boolean show)
          Have the object show its force components.
 boolean setShowFVector(int id, boolean show)
          Have the object show its force vector.
 void setShowTime(boolean show)
          Show the simulation time.
 boolean setShowVComponents(int id, boolean show)
          Have the object show its velocity components.
 boolean setShowVVector(int id, boolean show)
          Have the object show its velocity vector.
 int setSketchMode(boolean sketch)
          Enable sketching with the mouse.
 boolean setSpeed(int id, double speed)
          Change the speed of an object.
 boolean setSticky(int id, boolean sticky)
          Make the object sticky.
 void setTimeContinuous()
          Let the animation time increase indefinitely.
 void setTimeCycle(double max)
          Set a time loop for the animation from 0 to max.
 void setTimeDisplay(boolean show)
          Deprecated. replaced by setShowTime
 void setTimeInterval(double min, double max)
          Set a time loop for the animation.
 void setTimeOneShot(double max, java.lang.String msg)
          Runs the simulaiton one time and displays a message.
 void setTimeVisibility(boolean visible)
          Enable the time display in the applet window.
 void setTolerance(double tol)
          Set the tolerance of the ODE solver.
 boolean setTrail(int id, int n)
          Enable an object to display its path as it moves.
 boolean setTrail(int id, int n, int offset)
          Enable an object to display its path as it moves.
 boolean setTrajectory(int id, java.lang.String xStr, java.lang.String yStr)
          Set the trajectory of an object on the screen.
 boolean setVisibility(int id, boolean show)
          Show the visibility of the object.
 boolean setVX(int id, double vx)
          Change the x component of the speed of an object.
 boolean setVY(int id, double vy)
          Change the y component of an object's velocity.
 boolean setW(int id, double w)
          Change the width of an object.
 boolean setX(int id, double x)
          Changes the x of an object.
 boolean setXPos(int id, double x)
          Sets the x position of an object.
 boolean setXY(int id, double x, double y)
          Change the x and y of an object.
 boolean setY(int id, double y)
          Changes the y position of an object.
 boolean setYPos(int id, double y)
          Method setYPos
 void shiftPixOrigin(int xo, int yo)
          Shift the origin for the entire drawing.
 void stepBack()
          Method stepBack
 void stepForward()
          Method stepForward
 void stepTimeBack()
          Step the time backward by dt.
 void stepTimeForward()
          Step the time by dt.
 boolean swapZOrder(int id1, int id2)
          Swap the drawing order on the screen.
 
Methods inherited from class edu.davidson.tools.SApplet
addDataListener, addDataSource, checkAppletNames, cleanupDataConnections, clearAllData, clearData, deleteDataConnection, deleteDataConnections, formatValue, getAppletName, getClockID, getClockTime, getDataFromDS, getDataListener, getDataSource, getDataSource, getDebugLevel, getID, getSourceData, getSourceVariables, isClockRunning, isValidFunction, makeDataConnection, removeDataListener, removeDataSource, sendDataToListener, setClockContinous, setClockCycle, setClockOneShot, setClockTime, setConnectionBlock, setConnectionListener, setConnectionSmoothing, setConnectionSource, setConnectionStride, setConnectionWindowX, setConnectionWindowY, setDebugLevel, setDt, setExternalClock, setFPS, setIndependentClock, startClock, stepClock, stepTime, stop, stopClock, updateDataConnection, updateDataConnections
 
Methods inherited from class java.applet.Applet
destroy, getAccessibleContext, getAppletContext, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, init, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getAppletCount

public int getAppletCount()
Counts the number of applets on the html page.

Returns:
the number of applets

setAutoRefresh

public void setAutoRefresh(boolean auto)
Force the applet to repaint whenever any object changes its properties. Default is true. Set this value to false at the beginning of long scripts and then reset to true to avoid flashing.

Overrides:
setAutoRefresh in class SApplet
Parameters:
auto - The id of the object.

setCaption

public int setCaption(java.lang.String s)
Add a caption to the applet.

Parameters:
s -
Returns:
The id of the caption.

setDragable

public boolean setDragable(int id,
                           boolean canDrag)
Make the object with the given id dragable.

Parameters:
id - of the object.
canDrag - Is the object dragable?
Returns:
true if successful false otherwise

setResizable

public boolean setResizable(int id,
                            boolean isResizable)
Make an object resizable.

Parameters:
id - the object identifier
isResizable - true if the object is resizable
Returns:
true if successful.

setVisibility

public boolean setVisibility(int id,
                             boolean show)
Show the visibility of the object.

Parameters:
id - the object identifier
show - true will show object on screen
Returns:
true if successful false otherwise

setDefault

public void setDefault()
Set default values and deletes all data connections. pixPerUnit= PARAM value. gridUnit= PARAM value. time=0. shapeTrail=0. pixelOrigin=(0,0). caption=null. timeDisplay=tue;

Overrides:
setDefault in class SApplet

setMass

public boolean setMass(int id,
                       double m)
Set the mass of an object.

Parameters:
id - The id of the object.
m - The new mass.
Returns:
True if successful.

setCollisionMessage

public void setCollisionMessage(java.lang.String msg)
Display a message in the yellow message box.

Parameters:
msg - Message to display after the animation stops.

setMessage

public void setMessage(java.lang.String msg)
Display a message in the yellow message box.

Parameters:
msg - Message to display after the animation stops.

setAnimationSlave

public boolean setAnimationSlave(int masterID,
                                 int slaveID)
Force an object to follow another object on the screen.

Parameters:
masterID - The id of the master object.
slaveID - The id of the slave object.
Returns:
true if successful.

setShapeRGB

public void setShapeRGB(int r,
                        int g,
                        int b)
Set the red, green, and blue color values for all subsequent drawing. Color values must be in the range 0..255.

Parameters:
r - red.
g - green.
b - blue.

setRGB

public boolean setRGB(int id,
                      int r,
                      int g,
                      int b)
Set the color of an object.

Parameters:
id - The id of the object.
r - red
g - green
b - blue
Returns:
True if successful.

setOneShot

public void setOneShot(double min,
                       double max,
                       java.lang.String msg)
Set the applet to run for a fixed interval, stop, and display a message.

Parameters:
min - The starting time value for the loop
max - The ending time for the loop.
msg - Message to display after the animation stops.
See Also:
Animator.setTimeContinuous(), Animator.setTimeInterval(double, double)

setOnScreenSize

public boolean setOnScreenSize(int id,
                               int size)
Set a size parameter for an object. The effect of this parameter varies, or has no effect, depending on the object. For example, the size of a spring determines the number of coild and the size of a box determines the width of the walls.

Parameters:
id - The ID of the object.
size - The size of the object.
Returns:
boolean Returns true if successful.

setTimeCycle

public void setTimeCycle(double max)
Set a time loop for the animation from 0 to max. Animation will run continuously.

Overrides:
setTimeCycle in class SApplet
Parameters:
max - The ending time for the loop.
See Also:
Animator.setTimeContinuous(), Animator.setOneShot(double, double, java.lang.String), Animator.setTimeInterval(double, double)

setTimeInterval

public void setTimeInterval(double min,
                            double max)
Set a time loop for the animation. Animation will run continuously.

Parameters:
min - The starting time value for the loop
max - The ending time for the loop.
See Also:
Animator.setTimeContinuous(), Animator.setOneShot(double, double, java.lang.String)

setTimeContinuous

public void setTimeContinuous()
Let the animation time increase indefinitely. May overflow for very long times.

Overrides:
setTimeContinuous in class SApplet
See Also:
Animator.setTimeOneShot(double, java.lang.String), Animator.setTimeInterval(double, double), Animator.setOneShot(double, double, java.lang.String)

setTimeOneShot

public void setTimeOneShot(double max,
                           java.lang.String msg)
Runs the simulaiton one time and displays a message.

Overrides:
setTimeOneShot in class SApplet
Parameters:
max - Reset the simulation to t=0 when t>=max and stop the simulation.
msg - the message

setFootPrints

public boolean setFootPrints(int id,
                             int n)
Set the trail to leave footprints as the object moves.

Parameters:
id - The id of the object.
n - The number of points to skip between trail footprints or ghost images.
Returns:
boolean True if successful.

setGhost

public boolean setGhost(int id,
                        boolean ghost)
Have the object draw ghost images as it moves. Use footprints to set the spacing.

Parameters:
id - The id of the object.
ghost - Draw ghost?
Returns:
True if successful.

setLabel

public boolean setLabel(int id,
                        java.lang.String label)
Make the object label.

Parameters:
id - the id of the object
label - the label string
Returns:
true if successful

setTolerance

public void setTolerance(double tol)
Set the tolerance of the ODE solver. Default is on part in 1.0e-8.

Parameters:
tol - the tolerance

setTrail

public boolean setTrail(int id,
                        int n)
Enable an object to display its path as it moves. Not all objects can show their path.

Parameters:
id - The id of the object.
n - Number of points in trail. n=0 disables the trail.
Returns:
boolean True if successful.

setTrail

public boolean setTrail(int id,
                        int n,
                        int offset)
Enable an object to display its path as it moves. Not all objects can show their path.

Parameters:
id - the id
n - number of points in trail. n=0 disables the trail.
offset - the number of points to skip before the trail starts
Returns:
boolean true if successful.

setTrajectory

public boolean setTrajectory(int id,
                             java.lang.String xStr,
                             java.lang.String yStr)
Set the trajectory of an object on the screen.

Parameters:
id - The ID of the thing.
xStr - The function x(t).
yStr - The function y(t).
Returns:
boolean True if the functions are valid and the trajectory has been set.

setForce

public boolean setForce(int id,
                        java.lang.String fxStr,
                        java.lang.String fyStr,
                        double x0,
                        double y0,
                        double vx0,
                        double vy0)
Set the Force on a particle.

Parameters:
id - The ID of the pole.
fxStr - A function of t, x, y, vx, vy, ax, ay, m.
fyStr - A function of t, x, y, vx, vy, ax, ay, m.
x0 - The initial value for x.
y0 - The initial value for y.
vx0 - The initial value for vx.
vy0 - The initial value for vy.
Returns:
True if the functions are valid and the trajectory has been set.

setPaintBeforeGrid

public boolean setPaintBeforeGrid(int id,
                                  boolean before)
Have the object draw itself before the grid is drawn.

Parameters:
id - The id of the object.
before - Paint before grid?
Returns:
True if successful.

setTimeDisplay

public void setTimeDisplay(boolean show)
Deprecated. replaced by setShowTime

Enable the time display in the applet window.

Parameters:
show - boolean Show the time?

setShowTime

public void setShowTime(boolean show)
Show the simulation time.

Parameters:
show - true will show

setTimeVisibility

public void setTimeVisibility(boolean visible)
Enable the time display in the applet window.

Parameters:
visible -

setShowConstraintPath

public boolean setShowConstraintPath(int id,
                                     boolean sc)
Show the objects trajectory constraint if it exists.

Parameters:
id - the object identifier
sc - Show the path?
Returns:
true if successful

setShowCoordinates

public boolean setShowCoordinates(int id,
                                  boolean show)
Have the object show its coordinates on screen.

Parameters:
id - The id of the object.
show - Show the coordinates?
Returns:
True if successful.

setShowVComponents

public boolean setShowVComponents(int id,
                                  boolean show)
Have the object show its velocity components.

Parameters:
id - The id of the object.
show - Show the velocity?
Returns:
True if successful.

setShowFComponents

public boolean setShowFComponents(int id,
                                  boolean show)
Have the object show its force components.

Parameters:
id - The id of the object.
show - Show the force?
Returns:
True if successful.

setShowAComponents

public boolean setShowAComponents(int id,
                                  boolean show)
Have the object show its acceleration components.

Parameters:
id - The id of the object.
show - Show the acceleration?
Returns:
True if successful.

setShowVVector

public boolean setShowVVector(int id,
                              boolean show)
Have the object show its velocity vector.

Parameters:
id - The id of the object.
show - Show the velocity?
Returns:
True if successful.

setShowAVector

public boolean setShowAVector(int id,
                              boolean show)
Have the object show its acceleration vector.

Parameters:
id - The id of the object.
show - Show the acceleration?
Returns:
True if successful.

setShowFVector

public boolean setShowFVector(int id,
                              boolean show)
Have the object show its force vector.

Parameters:
id - The id of the object.
show - Show the force?
Returns:
True if successful.

setSticky

public boolean setSticky(int id,
                         boolean sticky)
Make the object sticky. A sticky object will stop the clock upon a collision with another sticky object. The sticky object must be moving under the action of forces. Objects that have trajectories will not stick.

Parameters:
id - of the object.
sticky - Sticky?
Returns:
true if successful.

setBouncy

public boolean setBouncy(int id,
                         boolean bounce)
Make the object bouncy. A dynamic object will bounce off of bouncy objects.

Parameters:
id - of the object.
bounce -
Returns:
true if successful.

setConstrainR

public boolean setConstrainR(int id,
                             double r,
                             double x,
                             double y)
Constrain the motion of the object to a circular path.

Parameters:
id - the object identifier
r - The r value.
x - The x coordinate of the center
y - The y coordinate of the center
Returns:
True if successful.

setConstrainX

public boolean setConstrainX(int id,
                             double x,
                             double min,
                             double max)
Constrains the motion of the object to a path of constant x.

Parameters:
id - the object identifier
x - The x value.
min - the min value
max - the max value
Returns:
True if successful.

setConstrainY

public boolean setConstrainY(int id,
                             double y,
                             double min,
                             double max)
Constrains the motion of the object to a path of constant y.

Parameters:
id - the object identifier
y - The y value.
min - the min value
max - the max value
Returns:
true if successful.

setCoordinateOffset

public boolean setCoordinateOffset(int id,
                                   int xOff,
                                   int yOff)
Offset the object's coordinates on the screen.

Parameters:
id - The id of the object.
xOff - the x offset
yOff - the yoffset
Returns:
True if successful.

setDampOnMousePressed

public void setDampOnMousePressed(boolean damp)
Set the velocity of an object to zero if it is being dragged.

Parameters:
damp - the velocity?

setFont

public boolean setFont(int id,
                       java.lang.String family,
                       int style,
                       int size)
Sets the object's font if the object has text that can be displayed. This method fails due to operator overloading on some browers. Use setObjectFont instead.

Parameters:
id - The id of the object.
family - The font family: Helvetica, Times.
style - The style, 0=plain, 1=bold.
size - The size of the font;
Returns:
true if successful.

setObjectFont

public boolean setObjectFont(int id,
                             java.lang.String family,
                             int style,
                             int size)
Sets the object's font if the object has text that can be displayed.

Parameters:
id - The id of the object.
family - The font family: Helvetica, Times.
style - The style, 0=plain, 1=bold.
size - The size of the font;
Returns:
true if successful.

setFormat

public boolean setFormat(int id,
                         java.lang.String fstr)
Change the object's format for the display of numeric data. Us this method to control the number of significant digits in calculations with text objects. Use Unix printf conventions. For example fstr="%6.3f"

Parameters:
id - The id of the object.
fstr - the format string.
Returns:
True if successful.

setDisplayOffset

public boolean setDisplayOffset(int id,
                                int xOff,
                                int yOff)
Offset the object's position on the screen from its default drawing position.

Parameters:
id - The id of the object.
xOff - the x offset
yOff - the y offset
Returns:
true if successful.

setGridUnit

public void setGridUnit(double gu)
Set the grid spacing in world, i.e., not pixel, units. Zero will suppress the drawing of the grid.

Parameters:
gu - grid unit.

setSketchMode

public int setSketchMode(boolean sketch)
Enable sketching with the mouse.

Parameters:
sketch - true will sketch
Returns:
int the id of the mouse data source

setPixPerUnit

public void setPixPerUnit(int pu)
Set the pixels per unit. This sets the scale for the animation.

Parameters:
pu - pixels per unit.

shiftPixOrigin

public void shiftPixOrigin(int xo,
                           int yo)
Shift the origin for the entire drawing. Shift is specified in pixels.

Parameters:
xo - x pixel shift.
yo - y pixel shift.

reset

public void reset()
Clear data from all dataConnections and reset the animation time to 0.

Overrides:
reset in class SApplet
See Also:
Animator.setAnimationTime(double)

setAnimationTime

public void setAnimationTime(double time)
Set the animation time.

Parameters:
time - The new time displayed inside the applet.

stepTimeForward

public void stepTimeForward()
Step the time by dt.

Overrides:
stepTimeForward in class SApplet
See Also:
SApplet.setDt(double)

stepForward

public void stepForward()
Method stepForward


stepTimeBack

public void stepTimeBack()
Step the time backward by dt.

Overrides:
stepTimeBack in class SApplet
See Also:
SApplet.setDt(double)

stepBack

public void stepBack()
Method stepBack


addObject

public int addObject(java.lang.String name,
                     java.lang.String parList)
Creates an object and adds it to the Physlet. The first argument is the name of the object to be added and the second is a comma-delimited list of parameters. For example, a circle can be added a follows:

addObject ("circle", "x = 0, y = -1.0, r = 10");

See the supplemental documentation for a list of object names and parameters.

Parameters:
name - the type of object to be created.
parList - a list of parameters to be set
Returns:
double id of the object

addCircle

public int addCircle(int diameter,
                     java.lang.String xStr,
                     java.lang.String yStr)
Adds a filled circle to the animation. Duplicates functionality of addObject(String String) method.

Parameters:
diameter - The diameter of the circle in pixels.
xStr - The x position of the center.
yStr - The y position of the center.
Returns:
id of filled circle.

addShell

public int addShell(int diameter,
                    java.lang.String xStr,
                    java.lang.String yStr)
Adds a circular shell to the animation. Duplicates functionality of addObject(String String) method.

Parameters:
diameter - The diameter of the shell in pixels.
xStr - The x position of the center.
yStr - The y position of the center.
Returns:
id of shell.

addExShell

public int addExShell(int tickness,
                      java.lang.String rStr,
                      java.lang.String xStr,
                      java.lang.String yStr)
Adds an expanding shell to the animation. Duplicates functionality of addObject(String String) method.

Parameters:
tickness - The thickness of the shell in pixels.
rStr - The radius of the shell.
xStr - The x position of the center.
yStr - The y position of the center.
Returns:
id of the object

addPiston

public int addPiston(int s,
                     java.lang.String hStr,
                     java.lang.String vStr,
                     java.lang.String xStr,
                     java.lang.String yStr)
Add a piston, i.e. a rectangle that changes size, to the animation. Both the position, length and width can be functions of time. Duplicates functionality of addObject(String String) method.

Parameters:
s -
hStr - The horizontal size.
vStr - The vertical size.
xStr - The x position of the base.
yStr - The y position of the base.
Returns:
id of the object
See Also:
Animator.addRectangle(int, int, java.lang.String, java.lang.String)

addSpring

public int addSpring(java.lang.String hStr,
                     java.lang.String vStr,
                     java.lang.String xStr,
                     java.lang.String yStr)
Add a spring to the animation. Both the position and the direction components can be functions of time. Duplicates functionality of addObject(String String) method.

Parameters:
hStr - The horizontal size.
vStr - The vertical size.
xStr - The x position of the base.
yStr - The y position of the base.
Returns:
id of the object

addArrow

public int addArrow(java.lang.String hStr,
                    java.lang.String vStr,
                    java.lang.String xStr,
                    java.lang.String yStr)
Adds an arrow, i.e. vector, to the animation. Both the position and the direction components can be functions of time. Duplicates functionality of addObject(String String) method.

Parameters:
hStr - The horizontal component. Can be a function of x,y,vx,vy,ax,ay, and t.
vStr - The vertical component. Can be a function of x,y,vx,vy,ax,ay, and t.
xStr - The x position of the base. Can be a function of t.
yStr - The y position of the base. Can be a function of t.
Returns:
true if successful
See Also:
Animator.addLine(java.lang.String, java.lang.String, java.lang.String, java.lang.String)

addInteraction

public boolean addInteraction(int id1,
                              int id2,
                              java.lang.String force,
                              java.lang.String mode)
Adds an interaction between two particles, Force(x,y,r,v,t). All values except time are relative values. That is, v is the relative velocity, x is the relative x separation, etc. Duplicates functionality of addObject(String String) method.

Parameters:
id1 - The first particle.
id2 - The second particle
force - The force between the particles as a function of x, y, r, v, t
mode - "r", "x", or "y"
Returns:
double id of the object

addCalculation

public int addCalculation(java.lang.String text,
                          java.lang.String calc,
                          java.lang.String xStr,
                          java.lang.String yStr)
Adds a calculated value, i.e., a function of time that is calculated as a number, to the animation. The position on the screen can change so that this value can move with other objects. Duplicates functionality of addObject(String String) method.

Parameters:
text -
calc - A function of position, velocity, acceleration, and time that will be evaluated at every time step.
xStr - The x position of the base.
yStr - The y position of the base.
Returns:
double id of the object

addCaption

public int addCaption(java.lang.String text,
                      java.lang.String calc)
Add a caption to the animation. A caption is centered on the screen and uses a bold font. The position on the screen can change so that this value can move with other objects. Duplicates functionality of addObject(String String) method.

Parameters:
text - A fixed caption to the left of the number.
calc - A function of time that will be evaluated.
Returns:
The id of the object.
See Also:
Animator.addCalculation(java.lang.String, java.lang.String, java.lang.String, java.lang.String)

addCursor

public int addCursor(int diameter,
                     java.lang.String xStr,
                     java.lang.String yStr)
Add a cursor to the animation. Duplicates functionality of addObject(String String) method.

Parameters:
diameter - The diameter.
xStr -
yStr -
Returns:
id of the object

addText

public int addText(java.lang.String text,
                   java.lang.String xStr,
                   java.lang.String yStr)
Adds text to the animation. Duplicates functionality of addObject(String String) method.

Parameters:
text - The text.
xStr - The x position of the text.
yStr - The y position of the text.
Returns:
id of the object

addLine

public int addLine(java.lang.String hStr,
                   java.lang.String vStr,
                   java.lang.String xStr,
                   java.lang.String yStr)
Adds a line to the animation. Both the position and the direction components can be functions of time. Duplicates functionality of addObject(String String) method.

Parameters:
hStr - The horizontal size.
vStr - The vertical size.
xStr - The x position of the base.
yStr - The y position of the base.
Returns:
id of the object
See Also:
Animator.addArrow(java.lang.String, java.lang.String, java.lang.String, java.lang.String)

addConnectorLine

public int addConnectorLine(int id1,
                            int id2)
Adds a connecting line between two objects. Duplicates functionality of addObject(String String) method.

Parameters:
id1 - The first id of a screen object.
id2 - The second id of a screen object.
Returns:
id that identifies the connector.

addConnectorSpring

public int addConnectorSpring(int id1,
                              int id2)
Adds a connecting spring between two objects. Duplicates functionality of addObject(String String) method.

Parameters:
id1 - The first id of a screen object.
id2 - The second id of a screen object.
Returns:
id that identifies the connector.

swapZOrder

public boolean swapZOrder(int id1,
                          int id2)
Swap the drawing order on the screen.

Parameters:
id1 - The first id of a screen object.
id2 - The second id of a screen object.
Returns:
True if successful.

deleteObject

public void deleteObject(int id)
Delete an object from the applet.

Parameters:
id - the object identifier

addBox

public int addBox(int w,
                  int h,
                  java.lang.String xStr,
                  java.lang.String yStr)
Adds a box to the animation. Duplicates functionality of addObject(String String) method.

Parameters:
w - The width of the circle in pixels.
h - The height of the circle in pixels.
xStr - The x position of the center.
yStr - The y position of the center.
Returns:
True if successful.
See Also:
Animator.addRectangle(int, int, java.lang.String, java.lang.String)

addRectangle

public int addRectangle(int w,
                        int h,
                        java.lang.String xStr,
                        java.lang.String yStr)
Adds a solid rectangle to the animation. Duplicates functionality of addObject(String String) method.

Parameters:
w - The width of the circle in pixels.
h - The height of the circle in pixels.
xStr - The x position of the center.
yStr - The y position of the center.
Returns:
id of the object
See Also:
Animator.addBox(int, int, java.lang.String, java.lang.String)

addParametricCurve

public int addParametricCurve(int n,
                              double start,
                              double stop,
                              java.lang.String xStr,
                              java.lang.String yStr)
Plot a function. The x and y coodinates are specified as a parametric curve.

Parameters:
n - The number of points to plot.
start - The starting value of the parameter, s.
stop - The ending value of the paramter, s.
xStr - The x function, x(s,t).
yStr - The y function, y(s,t).
Returns:
id of the object

addPolyShape

public int addPolyShape(int n,
                        java.lang.String hStr,
                        java.lang.String vStr,
                        java.lang.String xStr,
                        java.lang.String yStr)
Add a polygon to the animation. The polygon can have an arbitrary number of points but the shape is fixed. The position can be a function of time.

Parameters:
n - The number of vertices in the polygon.
hStr - A slash separated list of the x postions of the vertices in pixel units. MUST BE A STRING.
vStr - A slash separated list of the y postions of the vertices in pixel units. MUST BE A STRING.
xStr - The x position of the base.
yStr - The y position of the base.
Returns:
id of the object
See Also:
Animator.addRectangle(int, int, java.lang.String, java.lang.String)

addRelPolyShape

public int addRelPolyShape(int n,
                           java.lang.String hStr,
                           java.lang.String vStr,
                           java.lang.String xStr,
                           java.lang.String yStr)
Add a polygon to the animation. The polygon can have an arbitrary number of points but the shape is fixed. Use relative postions for the vertices.

Parameters:
n - The number of vertices in the polygon.
hStr - A slash separated list of the x postions of the relative vertices in pixel units. MUST BE A STRING.
vStr - A slash separated list of the y postions of the relative vertices in pixel units. MUST BE A STRING.
xStr - The x position of the base.
yStr - The y position of the base.
Returns:
id of the shape.
See Also:
Animator.addRectangle(int, int, java.lang.String, java.lang.String)

addImage

public int addImage(java.lang.String file,
                    java.lang.String xStr,
                    java.lang.String yStr)
Adds an image to the animation. Looks for image in the code base, the document base, and absolute URL.

Parameters:
file - Location of image relative to the document containing the HTML page.
xStr - The x position of the image.
yStr - The y position of the image.
Returns:
id of the object

addImageFromDocumentBase

public int addImageFromDocumentBase(java.lang.String file,
                                    java.lang.String xStr,
                                    java.lang.String yStr)
Add an image to the animation. The position of the image can change during the animation. Duplicates functionality of addObject(String String) method.

Parameters:
file - Location of image relative to the document containing the HTML page.
xStr - The x position of the image.
yStr - The y position of the image.
Returns:
id of the object

addImageFromCodeBase

public int addImageFromCodeBase(java.lang.String file,
                                java.lang.String xStr,
                                java.lang.String yStr)
Adds an image to the animation. The position of the image can change during the animation. Duplicates functionality of addObject(String String) method.

Parameters:
file - Location of image relative to the code containing the jar files.
xStr - The x position of the image.
yStr - The y position of the image.
Returns:
id of the object

getPhysletCanvas

public animator4.AnimatorCanvas getPhysletCanvas()
Get the Canvas so that Animator can be used in EJS for drawing.

Returns:
AnimatorCanvas

getEnsembleID

public int getEnsembleID()
Get the id for the ensemble of objects. This id can be used to access the ensemble as a data source.

Returns:
int The id of the ensemble containing all objects on the screen. Used as a data source.

getCollisionID

public int getCollisionID()
Get the id for collisions. This id can be used to access the collision as a data source.

Returns:
int The id of the ensemble containing all objects on the screen. Used as a data source.

reverse

public void reverse()
Reverse the direction of the time step in the animation.

Overrides:
reverse in class SApplet

forward

public void forward()
Start the animation.

Overrides:
forward in class SApplet

pause

public void pause()
Pause the animation.

Overrides:
pause in class SApplet

getAnimationTime

public double getAnimationTime()
Get the animation time.

Returns:
The time displayed inside the applet.

getX

public double getX(int id)
Gets the x position of an object.

Parameters:
id - the object identifier
Returns:
the x position

setX

public boolean setX(int id,
                    double x)
Changes the x of an object.

Parameters:
id - The id of the object.
x - new x value
Returns:
true if successful

setXPos

public boolean setXPos(int id,
                       double x)
Sets the x position of an object.

Parameters:
id - the object identifier
x -
Returns:
true of successful

getXPos

public double getXPos(int id)
Bug-fix to get the x of an object on Netscape and Sun.

Parameters:
id - The id of the object.
Returns:
true if successful

getYPos

public double getYPos(int id)
Bug-fix to get the y of an object on Netscape and Sun.

Parameters:
id - The id of the object.
Returns:
true if successful

setXY

public boolean setXY(int id,
                     double x,
                     double y)
Change the x and y of an object.

Parameters:
id - The id of the object.
x - new x value
y - new y value
Returns:
true if successful

getH

public double getH(int id)
Get the height of an object.

Parameters:
id - the object identifier
Returns:
the height

setH

public boolean setH(int id,
                    double h)
Change the height of an object.

Parameters:
id - the object identifier
h - new height
Returns:
true if successful

getW

public double getW(int id)
Get the width of an object.

Parameters:
id - The id of the object.
Returns:
the width

setW

public boolean setW(int id,
                    double w)
Change the width of an object.

Parameters:
id - the object identifier
w - new width
Returns:
true if successful

getY

public double getY(int id)
Gets the y position of an object.

Parameters:
id - the object identifier
Returns:
the y position

setY

public boolean setY(int id,
                    double y)
Changes the y position of an object.

Parameters:
id - The id of the object.
y - new postion
Returns:
true if successful

setYPos

public boolean setYPos(int id,
                       double y)
Method setYPos

Parameters:
id - the object identifier
y -
Returns:
true if successful

getVX

public double getVX(int id)
Get the x component of an object's velocity.

Parameters:
id - The id of the object.
Returns:
the x component of an object's velocity.

setVX

public boolean setVX(int id,
                     double vx)
Change the x component of the speed of an object.

Parameters:
id - The id of the object.
vx - new vx
Returns:
true if successful

getVY

public double getVY(int id)
Get the y component of an object's velocity.

Parameters:
id - The id of the object.
Returns:
the velocity component

setVY

public boolean setVY(int id,
                     double vy)
Change the y component of an object's velocity.

Parameters:
id - The id of the object.
vy -
Returns:
true if successful

setSpeed

public boolean setSpeed(int id,
                        double speed)
Change the speed of an object. Direction of motion remains unchanged.

Parameters:
id - The id of the object.
speed - new speed
Returns:
true if successful

setCharge

public boolean setCharge(int id,
                         double q)
Sets the charge on a Charge object.

Parameters:
id - The id of the charge.
q - new charge value
Returns:
true if successful

getFx

public double getFx(int id)
Gets the x component of the force acting on an object.

Parameters:
id - The id of the object.
Returns:
the force

setReferenceFrame

public boolean setReferenceFrame(int id)
Sets the reference frame. The new reference frame is the frame in which the object with id is stationary.

Parameters:
id - the object from which the motion will be observed
Returns:
true if successful

getFy

public double getFy(int id)
Get the y component of the force acting an object.

Parameters:
id - The id of the object.
Returns:
the force

getAppletInfo

public java.lang.String getAppletInfo()
Method getAppletInfo

Returns:
the info

getParameterInfo

public java.lang.String[][] getParameterInfo()
Method getParameterInfo

Returns:
the info


Visit the Davidson College Physlet Site for additional information.