Animator and Efield AddObject Method

Almost all Physlets support one or more add methods designed to create an object and add it to the applet.  The addObject method with the following signature

addObject(String name, String attributes)

These objects usually, but not always, have an on-screen representation.  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 JavaScript statement:

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

The addObject method is very forgiving since not all parameters need to be specified.  Default values are overridden only if the parameter appears in the list.  Incorrect and unsupported parameters do not affect the applet and are ignored.

The table below lists the name and the associated parameters for version 4 of the Animator and EField Physlets.  An X in the A or E column indicates that the named object can be added.  Consult the online documentation for information about other Physlets.  DataGraph, for example supports the addObject method for geometric shapes such as circles, boxes, and shells.  OpticsBench, on the other hand, supports the addObject method for lenses, mirrors, and light sources.

 

Name

Attributes

A

E

arrow

Arrows are often animation slaves of other objects.  They can represent almost any vector since the h and v components can be functions of the variables.

x- double x position of the base in world units

y- double y position of the base in world units.

h- string horizontal component as a function of t, x, y, vx, vy, ax, and ay.

v- string vertical components as a function of t, x, y, vx, vy, ax, and ay.

x

x

box

A box is a hollow rectangle.

x- double x position of the center in world units

y- double y position of the center in world units

h- int height in pixels

w- int width in pixels

s-int thickness of the box

m-double the mass

x

x

circle

x- double x position of the center in world units

y- double y position of the center in world units.

r- int radius in pixels

m-double the mass

x

x

caption

A caption is text that is centered near the top of the screen.

text- string 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.

x

x

charge

x- double x position of the center in world units

y- double y position of the center in world units.

q- double object's charge.

r- int radius in pixels

m-double the mass

 

x

connectorline
A straight line connection two objects.

id1- int first object identifier.

id2- int second object identifier.

 

See also: addConnectorSpring(int,int) in the online documentation.  This method is easier to use if the ids are stored as integers.

x

x

connectorspring
A spring connection two objects.

id1- int first object identifier.

id2- int second object identifier.

 

See also: addConnectorLine(int,int) in the online documentation.  This method is easier to use if the ids are stored as integers.

x

x

cursor

A circle with cross hairs.

x- double x position of the center in world units

y- double y position of the center in world units

r- int radius in pixels

x

x

exshell

Extended shell is similar to shell except that the radius can be a function of time.  Useful for shock waves and space-time diagrams.

x- double x position of the center in world units

y- double y position of the center in world units

r- string The radius in world units as a function of time

s- int thickness of the shell in pixels

m-double the mass

x

 

image

Add an animated gif image.  The coordinates are the coordinates of the upper left hand corner.

x- double x position of the left side in world units

y- double y position of the top in world units

file- string name of the gif file.  The image should be in located in the same directory as the jar file for the applet.

m-double the mass

x

x

line

 

 

 

 

 

x- double x position of the base in world units

y- double y position of the base in world units.

h- string horizontal component as a function of t, x, y, vx, vy, ax, and ay.

v- string vertical component as a function of t, x, y, vx, vy, ax, and ay.

x

x

polyshape
polyshape draws an arbitrary shape by connect-the-dots.  The shape is specified by passing the pixel positions of the dots starting at x and y. 

x- double x position of the center in world units

y- double y position of the center in world units.

n- int number of vertices in the polygon.

h- string A slash (/) separated list of the x positions of the vertices in pixel units.

v- string A slash (/) separated list of the y positions of the vertices in pixel units.

m-double the mass

x

 

rectangle

x- double x position of the center in world units

y- double y position of the center in world units.

h- int height in pixels.

w- int width in pixels.

m-double the mass

x

x

relshape
relshape draws an arbitrary shape by connect-the-dots.  The shape is specified by passing the relative pixel positions of the dots starting at x and y.

x- double x position of the center in world units

y- double y position of the center in world units.

n- int 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.

m-double the mass

x

 

shell
a circle with a hollow center

x- double x position of the center in world units

y- double y position of the center in world units

r- int radius in pixels

s-int thickness of the shell

m-double the mass

x

x

testcharge
a charge that is free to move under the action of fixed charges and an external potential.

x- double x position of the center in world units

y- double y position of the center in world units

vx- double x velocity in world units

vy- double y velocity in world units

q- double object's charge

r- int radius in pixels

m-double the mass

 

x

text
a fixed text string followed by an optional calculation.

x- double x position of the left side of the text in world units

y- double y position of the top of the text in world units

text- string static text.

calc- string A function of t, x, y, vx, vy, ax, and ay that is evaluated at every time step.  The value of the function is displayed to the right of the static text.]

 

Note:  Use the setFormat method described in 17.3.1 to change the decimal format used to output the calculation.

x

x