Animator

addObject Method

Almost all Physlets support one or more add methods designed to create an object and add it to the applet.  These objects usually, but not always, have an on-screen representation.  For example, both Animator and EField support addCircle methods that are invoked using the following JavaScript statements

document.animator.addCircle(int diameter, String xStr,String yStr)

and

document.efield.addCircle(double x, double y, int radius ),

respectively.

Notice that the signatures, that is, the parameters, of these two method are different.  Animator version 1 was designed to move simple geometric shapes along predefined trajectories that were passed to the object's constructor.  EField version 1, on the other hand, was designed plot electric fields for fixed charges so its constructor required only fixed position coordinates.  Hence, animator was passed two functions strings and EField was passed two numbers.  Both applets were designed to run on 90 MHz computers with relatively slow Java virtual machines.  Since each applet only had a half dozen methods, it was not difficult to remember the correct signature.   But computer hardware and software advances have made it possible to add a great deal of functionality and the capabilities of these two applets have slowly converged.  Each applet now supports dozens of methods and although many of the methods names are the same, the method signatures are, unfortunately, still different to maintain backward compatibility.

In order to bring some order to this method madness, version 4 of Animator and EField, along with all newly written Physlets, have adopted a more uniform convention for adding objects.  Both applets now support an addObject method with the following signature

document.physletname.addObject(String name, String list)

The first argument is the name of the object to be added and the second is a comma-delimited list of parameters.  A circle can now be added to either applet using the following statement

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

Furthermore, the new method is more forgiving since not all parameters need be specified. The default values are overridden only if they appear in the list.   Incorrect or unsupported parameters have no effect and are ignored. 

Users of old scripts should note that although the original add methods are still included in version 4 for backward compatibility, they have been depreciated.   In addition, there have been structural changes in the tools package.   The original STools.jar and SGraphics.jar have been combined into a single archive called STools4.jar.    Consequently, archive and code properties that are specified when an applet is embedded should now read

archive="Animator4_.jar,STools4.jar" code="animator4.Animator.class"

and

archive="EField4_.jar,STools4.jar" code="eField4.EField.class".

As before, all jar files need to be specified and listed the same order in every archive tag on a page for inter-applet communication to work on all browsers.

The table below lists the name and the associated parameters for version 4 of the EField and Animator Physlets.  Consult the on-line documentation for information about other Physlets.

Name

Parameters

Animator

EField

arrow

 

  • x- double The x position of the base in world units
  • y- double The y position of the base in world units.
  • h- string The horizontal component as a function of t, x, y, vx, vy, ax, and ay.
  • v- string The vertical component as a function of t, x, y, vx, vy, ax, and ay.
  •  
  •  

box

  • x- double The x position of the center in world units
  • y- double The y position of the center in world units.
  • h- int The height in pixels.
  • w- int The width in pixels.
  •  
  •  

circle

  • x- double The x position of the center in world units
  • y- double The y position of the center in world units.
  • r- int The radius in pixels.
  •  
  •  

caption

  • text- string The text of the caption
  • calc- string A function of t to be evaluated at every time step.  The value of the function is displayed to the right of the text.
  •  
  •  

charge

  • x- double The x position of the center in world units
  • y- double The y position of the center in world units.
  • q- double The object's charge.
  • r- int The radius in pixels.

 

  •  

connectorline

  • id1- int The first object identifier.
  • id2- int The second object identifier.
  •  
  •  

connectorspring

  • id1- int The first object identifier.
  • id2- int The second object identifier.
  •  
  •  

cursor

  • x- double The x position of the center in world units
  • y- double The y position of the center in world units.
  • r- int The radius in pixels.
  •  
  •  

exshell

  • x- double The x position of the center in world units
  • y- double The y position of the center in world units.
  • r- string The radius in world units as a function of time
  • s- int The thickness of the shell in pixels.
  •  

 

image

  • x- double The x position of the left side in world units
  • y- double The y position of the top in world units.
  • file- string The name of the gif file.  The image should be in located in the same directory as the applet.
  •  
  •  

line

 

 

 

 

 

  • x- double The x position of the base in world units
  • y- double The y position of the base in world units.
  • h- string The horizontal component as a function of t, x, y, vx, vy, ax, and ay.
  • v- string The vertical component as a function of t, x, y, vx, vy, ax, and ay.
  •  
  •  

polyshape

  • x- double The x position of the center in world units
  • y- double The y position of the center in world units.
  • n- int The number of vertices in the polygon.
  • hStr- string A comma separated list of the x postions of the vertices in pixel units.
  • vStr- string A comma separated list of the y postions of the vertices in pixel units.
  •  

 

rectangle

  • x- double The x position of the center in world units
  • y- double The y position of the center in world units.
  • h- int The height in pixels.
  • w- int The width in pixels.
  •  
  •  

relshape

  • x- double The x position of the center in world units
  • y- double The y position of the center in world units.
  • n- int The number of vertices in the polygon.
  • hStr- string A comma separated list of the x postions of the relative vertices in pixel units.
  • vStr- string A comma separated list of the y postions of the relative vertices in pixel units.
  •  

 

shell

  • x- double The x position of the center in world units
  • y- double The y position of the center in world units.
  • r- int The radius in pixels.
  •  
  •  

testcharge

  • x- double The x position of the center in world units
  • y- double The y position of the center in world units.
  • vx- double The x velocity in world units
  • vy- double The y velocity in world units.
  • q- double The object's charge.
  • r- int The radius in pixels.

 

  •  

text

  • x- double The x position of the left side of the text in world units
  • y- double The y position of the top of the text in world units.
  • text- string The static text.
  • calc- string A function of t, x, y, vx, vy, ax, and ay to be evaluated at every time step.  The value of the function is displayed to the right of the static text.
  •  
  •