Animator addObject Method

The Animator addObject method has the following signature

addObject(String name, String attributes)

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 to either applet using the following JavaScript statement:

id=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.

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 supports the addObject method for lenses, mirrors, and light sources.

 

Name

Attributes

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 component as a function of t, x, y, vx, vy, ax, and ay.
s- int the size of the head in pixels
thickness- int the thickness of the shaft in pixels
filled- solid fill

arrow2
An arrow that can be dragged and resized.

x- double x position of the base in world units
y- double
y position of the base in world units.
h- double horizontal component
v- double vertical component
s- int the size of the head in pixels
thickness- int the thickness of the shaft in pixels
filled- solid fill

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

calculation
a fixed text string followed by an optional calculation.

Alternate name for a text object.

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 to change the decimal format used to output the calculation.

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.
chop- double Smallest calculation result that will display as non-zero.

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

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

connectorline
A straight line connecting 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.

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.

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

curve
a parametric curve

n- int the number of points along curve
x- string analytic function for x:  x(s)
y- string analytic function for y:  y(s)
start- double starting value for s parameter
stop- double stopping value for s parameter

doppler
A point source for waves.

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
n-int
the number of wave crests
period-double the tiem between wave crests
c-double the speed of the wave

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

image
adds 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

interaction
A two-body interaction

id1- int first object identifier.
id2- int
second object identifier.
force- string
analytic expression for the force between the two objects: Force(x,y,r)
mode- string the direction of the interaction; "x", "y", "r"

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.

mouse
an invisible data-source that tracks the mous

click sends mouse click (x,y) values to a data connection
drag sends mouse drag (x,y) values to a data connection
move sends mouse move (x,y) values to a data connection
release sends mouse release (x,y) values to a data connection

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.

drag 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

piston
a rectangle with width and height that can be set using a data connection.

x- double x position of the center in world units
y- double y position of the center in world units.
h- string width as a function of t, x, y, vx, vy, ax, and ay.
v- string height as a function of t, x, y, vx, vy, ax, and ay.

protractor
a protractor for measuring angles

x- double x position of the vertex in world units
y- double
y position of the vertex in world units.
s- int base size in pixel
theta- double vertex interior angle
theta0- double vertex base angle
fixedbase-
fixes the base angle
fixedsize-
fixes the length of the arm

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

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 slash separated list of the x postions of the relative vertices in pixel units. vStr- string A slash separated list of the y postions of the relative vertices in pixel units.
m-double the mass

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

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 to change the decimal format used to output the calculation.