@physletName|Animator
@code|animator4.Animator.class
@archive|Animator4_.jar,STools4.jar
@appletSize|400|300
@scriptHeader|setAutoRefresh(false);
@scriptFooter|setAutoRefresh(true);
@embedParam|b|ShowControls|false|show controls:
@embedParam|i|FPS|20|animation frames per second:
@embedParam|d|Dt|0.05|time step per frame:
@embedParam|i|PixPerUnit|10|pixels per unit:
@embedParam|d|GridUnit|1.0|on-screen grid unit:
forward|
#E9D3FF
>>> tt >>>
Start the animation clock. This is necessary before any object will move, or to resume after "pause".
Creating a new script "Forward" with just this command will result in an appropriate button.
See other correspondent methods (pause, step forward...)
>>> tt >>>
Forward
addObject|shpID
#FF707D
>>> tt >>>
circle - filled circle, shell - hollow circle, rectangle - filled rectangle, box - hollow rectangle, cursor - hollow circle with cross hairs
Shapes can either move along an analytic path (see "Trajectory") or they follow dynamic simulation (see "Set Force")
The position x,y for the center (in units) is irrelevant in the latter case, because "Enable force" will set the initial position again.
Specify radius or height/width in pixels (or leave blank for defaults). Default mass is 1.
The ID variables can be used to change properties later on.
>>> tt >>>
Add shape
s|type|circle;rectangle;shell;box|Add:
$
.|d|x|0|x (units):
.|d|y|0|y:
.|i|w||w (pixels):
.|i|h||h:
.|i|r||r:
.|i|s||border:
addObject|vecID
#FF707D
>>> tt >>>
An arrow or line, starting in point (x,y) and ending in (x+h,y+v).
h and v are given in units and can be functions of t,x,y,vx,vy,ax,ay. The motion variables make sense if the vector itself is following a "trajectory" or is "animation slave" of another moving object.
The thickness can be specified and in the case of the arrow the size of its head.
>>> tt >>>
Add vector
s|type|arrow;line|Add:
$
.|d|x|0|at x:
.|d|y|0|y:
.|i|thickness||thickness:
.|i|s||size head:
.|s|h||
h(t,x,y,vx...):
.|s|v||v(t,x,y,vx...):
addObject|pgnID
#FF707D
>>> tt >>>
Draws a polygon shape by connect-the-dots.
With polyshape all dots are specified by the pixel distance to an arbitrary center (x,y).
With relshape each dot is specified by the pixel distance relative to the previous dot (only the first one relative to the center)
x, y = reference point (center) in units
h, v = slash separated lists (e.g. 0/10/0) containing the horizontal or the vertical pixel distances of the dots in pixels
n = number of vertices (dots) in the polygon
m = mass in a dynamic simulation(by default 1)
>>> tt >>>
Add polygon
s|type|polyshape;relshape|Add:
$
.|d|x|0|center x:
.|d|y|0|y:
.|i|m||mass:
.|i|n||
n:
.|s|h||x-coord. (pixels):
.|s|v||y-coord:
addObject|imgID
#FF707D
>>> tt >>>
Displays an image - gif/jpg/png - with upper left corner at x,y (in units)
Specify the filename relative to the .jar files, e.g. ../images/xy.gif or (or simply xy.gif, if located in same directory)
Images can either move along an analytic path (see "Trajectory") or they follow dynamic simulation (see "Set Force")
The position x,y for the center (in units) is irrelevant in the latter case, because "Enable force" will set the initial position again.
Default mass is 1.
>>> tt >>>
Add image
s|name|image|HIDDEN
$
.|s|file|smile.gif|Add image:
.|d|x|0|at x:
.|d|y|0|y:
addObject|txtID
#FF707D
>>> tt >>>
Text followed by a calculated value. The calculation is expressed as a function string f(t,x,y,vx,vy,ax,ay), especially useful, if this text object is follows the motion of another shape (see "Animation slave).
>>> tt >>>
Add text
s|name|text|HIDDEN
$
.|s|text||Add text:
.|s|calc||and calculation:
.|d|x|0|at x:
.|d|y|0|y:
addConnectorLine|
#FF707D
>>> tt >>>
Draw a straight line connecting to objects.
>>> tt >>>
Conn. line
o|id||Add straight line between object:
o|id||and object:
addConnectorSpring|sprID
#FF707D
>>> tt >>>
Draw a spring connecting to objects.
Yet, there are no physical interactions through this (see "Enable force" and "Interaction")
The variable contains the ID of the spring to adjust the number of coils, see "Object size".
>>> tt >>>
Conn. spring
o|id||Add a spring line between object:
o|id||and object:
deleteObject|
#FF707D
>>> tt >>>
Deletes an object during runtime - for instance if a student presses a button (see field "Function:")
THIS METHOD IS NOT MEANT for the author when working in this scriptor:
Just delete the line "addObject" by hand!
>>> tt >>>
Delete object
o|id||Delete this object during runtime (see (i)!):
setDefault|
#FF707D
>>> tt >>>
Deletes all objects during runtime. Use this at the begin of a new function (for a new button).
Tip: Place a #-sign at the top of the script field, before clicking on "Set default". The new command line will then go there instead of at the end of the function.
THIS METHOD IS NOT MEANT for correcting the script in this scriptor:
Just delete lines like "document.Animator1.addObject(..." by hand!
Beware: This will also do the following:
- deletes all data connections!
- pixPerUnit= PARAM value, gridUnit= PARAM value,
time=0, shapeTrail=0, pixelOrigin=(0,0), caption=null, timeDisplay=true
(If this is not what you want, reset these values hereafter)
>>> tt >>>
Set default
setForce|
#FFDA92
>>> tt >>>
Make an object obey Newton's second law.
Set x- and y-components of an external force (functions of t, x, y, vx, vy, ax, ay, m)
and of the initial position and velocity (This may change the object's current position!)
This command is also necessary for every object that shall interact with others, see Interaction. In this case you can leave the external force to be zero.
Start the animation (clock t) with "forward".
>>> tt >>>
Set Force
o|id||Object:
s|xStr|0|Fx:
s|yStr|0|Fy:
d|x|0|x:
d|y|0|y:
d|vx|0|vx:
d|vy|0|vy:
addInteraction|
#FFDA92
>>> tt >>>
Create an interaction force between two dynamic objects.
NOTE: You need to make both objects dynamic first.
The interaction is a function: f(t,x,y,r), that uses relative coordinates.That is, x is the x separation between the objects. Etc.The mode determines if the force acts along x, y, or r.
>>> tt >>>
Interaction
o|id1||Object:
o|id2||interacts with object:
s|force|100/r/r|interaction force:
s|mode|r;x;y|direction:
setTrajectory|
#FFDA92
>>> tt >>>
Make an object follow a fixed trajectory x(t),y(t).
Start the animation (clock t) with "forward"
This "animation mode" is opposed to the "dynamic mode" where the object moves according to forces.
>>> tt >>>
Trajectory
o|id||Object:
s|xStr||follows curve x(t):
s|yStr||y(t):
setDragable|
#FFDA92
>>> tt >>>
Make the object with the given id dragable with the mouse.
>>> tt >>>
Dragable
o|id||Object:
b|canDrag|true|dragable by the mouse:
setAnimationSlave|
#FFDA92
>>> tt >>>
Force an object (slave) to follow another object (master) on the screen.
>>> tt >>>
Anim. slave
o|masterID||moving object:
o|slaveID||has got attached object:
setDisplayOffset|
#FFDA92
>>> tt >>>
Offset the display of an object on the screen.
>>> tt >>>
Display offset
o|id||Object:
i|xOff|10|displayed shifted by xOff:
i|yOff|10|(pixels) and yOff:
setTolerance|
#FFDA92
>>> tt >>>
Adjust the (relative) numerical tolerance of the ODE solver to make a dynamic simulation more exact or faster. Default is 1.0e-8.
>>> tt >>>
Tolerance
d|tol|1.0e-10|relative accuracy of numeric calculations:
setBouncy|
#FFDA92
>>> tt >>>
Make an dynamic object bounce off of other bouncy objects.
>>> tt >>>
Bouncy
o|id||Object:
b|bounce|true|bounces off of other bouncy objects:
setSticky|
#FFDA92
>>> tt >>>
Make the object "sticky", i.e. sensitive to collisions. A sticky object will stop the clock upon a collision with another sticky object and display a message. The sticky object must be moving under the action of forces (see "Set force").
Objects that have trajectories will not stick.
(see also"Collision message")
>>> tt >>>
Sticky
o|id||Object:
b|isSticky|true|stops animation in collision with other sticky objects:
getCollisionID|colID
#FFDA92
>>> tt >>>
Get the ID for collisions in a variable "col". This ID can be used to access the collision as a data source for values of "x", "y", "blocked".
>>> tt >>>
Collision ID
setCollisionMessage|
#FFDA92
>>> tt >>>
Display a message in the yellow message box when a collision occurs (see "Set sticky")
>>> tt >>>
Collis. Message
s|msg||Message displayed at collisions:
setMass|
#FFDA92
>>> tt >>>
Set the mass of a dynamic object.
>>> tt >>>
set mass
o|id||Object:
d|m|10| has Mass:
setVX|
#FFDA92
>>> tt >>>
Change the x component of the velocity of an object.
>>> tt >>>
set vx
o|id||Object:
d|vx|0|has horizontal velocity vx:
setVY|
#FFDA92
>>> tt >>>
Change the y component of the velocity of an object.
>>> tt >>>
set vy
o|id||Object:
d|vy|0|has vertical velocity vy:
setSpeed|
#FFDA92
>>> tt >>>
Change the speed of an object. Direction of motion remains unchanged.
>>> tt >>>
set speed
o|id||Object:
d|speed|0|has speed:
setXY|
#FFDA92
>>> tt >>>
Change the position of an object.
>>> tt >>>
set x,y
o|id||Object:
d|x|0|has position x:
d|y|0|(units), y:
setAnimationTime|
#FFDA92
>>> tt >>>
Set the animation time that is displayed inside the applet.
>>> tt >>>
set time
d|time|0|Set time to:
setReferenceFrame|
#FFDA92
>>> tt >>>
Set the reference frame for unit coordinates. The new reference frame is the frame in which the specified object is stationary.
>>> tt >>>
Refer. frame
o|id||Set system of coordinates (units) relative to object:
shiftPixOrigin|
#FFDA92
>>> tt >>>
Shift the origin for the entire drawing. Shift is specified in pixels.
>>> tt >>>
Pixel origin
i|xo|0|Shift origin of unit coordinates by xOff:
i|yo|0|(pixels) yOff:
setConstrainX|
#FFDA92
>>> tt >>>
Constrain the motion of the object to a path of constant x.
(See also: "Show Constraint")
>>> tt >>>
Constrain x
o|id||Constrain object:
d|x|0|to x:
d|min|0|(units) with ymin:
d|max|0|and ymax:
setConstrainY|
#FFDA92
>>> tt >>>
Constrain the motion of the object to a path of constant y.
(See also: "Show Constraint")
>>> tt >>>
Constrain y
o|id||Constrain object:
d|y|0|to y:
d|min|0|(units) with xmin:
d|max|0|and xmax:
setConstrainR|
#FFDA92
>>> tt >>>
Constrain the motion of the object to a circular path around point (x,y).
(See also: "Show Constraint")
>>> tt >>>
Constrain r
o|id||Constrain object:
d|r|0|to a circle with radius:
d|x|0|(units) around x:
d|y|0|and y:
setDampOnMousePressed|
#FFDA92
>>> tt >>>
Set the velocity of an object to zero if it is being dragged.
>>> tt >>>
Mouse damp.
b|damp|true|Mouse dragging sets velocity of objects to zero:
setRGB|
#FFFF99
>>> tt >>>
Set the red, green, and blue color values for an object.
color values must be in the range
0..255. Use color tables of other software to determine these values for the wanted color or try it out.
>>> tt >>>
Color
o|id||Paint object:
i|r|255|with intensities 0..255 for red:
i|g|0|green:
i|b|0|blue:
setVisibility|
#FFFF99
>>> tt >>>
Makes an object visible or invisible. The object is not destroyed; it is hidden and can be made visible at any time.
>>> tt >>>
Visibility
o|id||Object:
b|show|false|is visible:
swapZOrder|
#FFFF99
>>> tt >>>
Swap the drawing order (forground/background) of two objects on the screen.
>>> tt >>>
Fore/backgr.
o|id1||Swap object:
o|id2||with object:
setPaintBeforeGrid|
#FFFF99
>>> tt >>>
Draw an object before the grid is drawn.
That means it appears behind the grid (if true).
>>> tt >>>
Before grid
o|id||Paint object:
b|before|true|before the grid is painted:
setLabel|
#FFFF99
>>> tt >>>
Make a static black text string follow an object label. (see also "Set font").
More flexible is "Add text" in combination with "Animation slave")
>>> tt >>>
Object label
o|id||Attach to object:
s|label||a label with text:
setOnScreenSize|
#FFFF99
>>> tt >>>
Set a size parameter for an object. The effect of this parameter varies, or has no effect, depending on the object. For example, the number of coils of a spring or and the width of the walls of a box
>>> tt >>>
Object size
o|id||Object:
i|size|10|has size:
setFormat|
#FFFF99
>>> tt >>>
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.
>>> tt >>>
Number format
o|id||Numbers of object:
s|fstr|%6.3f|have display format (unix printf):
setObjectFont|
#FFFF99
>>> tt >>>
Sets the object's font if the object has text that can be displayed.
font family: Helvetica,Arial Times (doesn't work yet?).
style: 0=plain, 1=bold, 2=italic, 3=bold+italic
>>> tt >>>
Object font
o|id||Text of object:
s|family|Times|has font family:
i|style|0|style:
i|size|20|size:
addObject|capID
#FFFF99
>>> tt >>>
Set a title in the upper center of the applet. The resulting caption object (cap) can be associated with a moving object (use "Animation slave"). In this case the text can be followed by a calculated value, expressed as a function string f(t,x,y,vx,vy,ax,ay) that refers to quantities of the moving object.
>>> tt >>>
Caption
s|name|caption|HIDDEN
$
.|s|text||Set titel for applet:
.|s|calc||followed by calculation:
setShowFVector|
#CCFFCC
>>> tt >>>
Have the object show its net force vector (that scales with Mass m, see "Set mass").
Force components may be added as arrow objects and attached as "animation slaves".
>>> tt >>>
F vector
o|id||Object:
b|show|true|displays its net force vector:
setShowAVector|
#CCFFCC
>>> tt >>>
Have the object show its acceleration vector.
>>> tt >>>
a vector
o|id||Object:
b|show|true|displays its acceleration vector:
setShowVVector|
#CCFFCC
>>> tt >>>
Have the object show its velocity vector.
Force components may be added as arrow objects and attached as "animation slaves".
>>> tt >>>
v vector
o|id||Object:
b|show|true|displays its velocity vector:
setShowCoordinates|
#CCFFCC
>>> tt >>>
Have the object show its coordinates as attached black text strings (x=, y=) on screen.
>>> tt >>>
Show coord.
o|id||Object:
b|show|true|displays its coordinates:
setShowTime|
#CCFFCC
>>> tt >>>
Show the simulation time in the upper left corner.
>>> tt >>>
Show time
b|show|false|Show time in upper left corner:
setTrail|
#CCFFCC
>>> tt >>>
Draws a line as an object moves. Not all objects can show their path.
Parameters:
id of the object
number of points in trail. n=0 disables the trail.
the number of points to skip before the trail starts
(see also footprints and ghosts)
>>> tt >>>
Trail
o|id||Object:
i|n|300|leaves behind a trail with length (steps):
i|offset|0|starting after (steps):
setFootPrints|
#CCFFCC
>>> tt >>>
Changes the continous trail into marks every n steps. The trail must be set first.
>>> tt >>>
Footprints
o|id||Object:
i|n|3|leaves marks on its trail every n steps:
setGhost|
#CCFFCC
>>> tt >>>
Draw a pale copy on the screen around every footprint on a trail. (Set trail and footprints first!)
>>> tt >>>
Ghosts
o|id||Object:
b|ghost|true|leaves pale images behind at every footprint:
setShowConstraintPath|
#CCFFCC
>>> tt >>>
Show the objects trajectory constraint if it exists.
>>> tt >>>
Constr. path
o|id||Object:
b|sc|true|shows its constraint path:
getFx|fx
#B3EFFF
>>> tt >>>
Get a variable with the current x component of the net force acting on an object (= m*ax).
>>> tt >>>
get Fx
o|id||Get current Fx value for object:
getFy|fy
#B3EFFF
>>> tt >>>
Get a variable with the current y component of the net force acting an object (= m*ay).
>>> tt >>>
get Fy
o|id||Get current Fy value for object:
getVX|vx
#B3EFFF
>>> tt >>>
Get a variable with the current x component of an object's velocity (vx).
>>> tt >>>
get vx
o|id||Get current vx value for object:
getVY|vy
#B3EFFF
>>> tt >>>
Get a variable with the current y component of an object's velocity (vy).
>>> tt >>>
get vy
o|id||Get current vy value for object:
getXPos|x
#B3EFFF
>>> tt >>>
Get a variable with the current x component of an object (x).
>>> tt >>>
get x
o|id||Get current x value for object:
getYPos|y
#B3EFFF
>>> tt >>>
Get a variable with the current y component of an object (y).
>>> tt >>>
get y
o|id||Get current y value for object:
getAnimationTime|t
#B3EFFF
>>> tt >>>
Get a variable with the current animation time.
>>> tt >>>
get time
pause|
#E9D3FF
>>> tt >>>
Pause the animation.
>>> tt >>>
pause
stepForward|
#E9D3FF
>>> tt >>>
Step the time by dt.
Use then "forward" to continue the animation.
>>> tt >>>
step forward
stepBack|
#E9D3FF
>>> tt >>>
Step the time backward by dt.
Use then "forward" to continue the animation.
>>> tt >>>
step back
reverse|
#E9D3FF
>>> tt >>>
Reverse the direction of the time step in the animation.
>>> tt >>>
reverse
reset|
#E9D3FF
>>> tt >>>
Reset the animation time to 0 and clear data from all dataConnections.
See also "Animation time"
>>> tt >>>
reset
setOneShot|
#E9D3FF
>>> tt >>>
Set the applet to run once for a time interval from t=tmin to t=tmax, stop, and display a message. (see "End message")
See also: "Loop interval".
>>> tt >>>
One shot
d|min|0|Start animation at tmin:
d|max|0| stop at tmax:
s|msg||and display message:
setMessage|
#E9D3FF
>>> tt >>>
Change the default message when the animation ends. (see "One shot").
>>> tt >>>
End message
s|msg||Change the message at animation end to:
setTimeInterval|
#E9D3FF
>>> tt >>>
Set the applet to run in a loop in a time interval from t=tmin to t=tmax.
See also: "One shot".
>>> tt >>>
Loop interval
d|min|0|Loop animation between tmin:
d|max|0|and tmax:
setSketchMode|
#FFFFFF
>>> tt >>>
Enable drawing curves on the applet with the mouse.
>>> tt >>>
Sketch mode
b|sketch|true|Let the user draw sketches with the mouse pointer:
@physletName|DataGraph
@code|dataGraph.DataGraph.class
@archive|DataGraph4_.jar,STools4.jar
@appletSize|400|200
@scriptHeader|setAutoRefresh(false);
@scriptFooter|setAutoRefresh(true);
@embedParam|b|ShowControls|false|show controls:
@embedParam|b|AutoScaleX|true|AutoScaleX:
@embedParam|b|AutoScaleY|true|AutoScaleY:
getGraphID|graphID
#FF707D
>>> tt >>>
This command gives you a handle (ID) for the graph in this applet in a variable called "graph.."
You need this to establish a data connection with another physlet, in which this graph serves as data listener.
>>> tt >>>
Get graph
setDefault|
#FF707D
>>> tt >>>
Deletes all objects during runtime. Use this at the begin of a new function (for a new button).
Tip: Place a #-sign at the top of the script field, before clicking on "Set default". The new command line will then go there instead of at the end of the function.
THIS METHOD IS NOT MEANT for correcting the script in this scriptor:
Just delete lines like "document.Animator1.addObject(..." by hand!
Beware: This will also delete all data connections!
>>> tt >>>
Set default
addObject|funcID
#FFDA92
>>> tt >>>
Add a graph of an analytic function.
f - String of the function. Usually f(x) or f(x,t).
var - String the independent variable
Functions can be explicit functions of time. The function will animate if the clock is running.
xmin - minimum value for the independent variable
xmax - maximum value for the independent variable
A function will use the graph's current xmin and xmax values if the following are not specified.
n - int the number of evaluation points
>>> tt >>>
function
s|name|function|HIDDEN
$
.|s|f|sin(x)|function:
.|s|var|x|independent var:
.|d|xmin|0|
xmin:
.|d|xmax|10|xmax:
.|i|n|100|points:
setRGB|
#FFDA92
>>> tt >>>
Set the color of the object.
>>> tt >>>
color
o|id||id:
i|r|255|r:
i|g|0|g:
i|b|0|b:
setMinMaxX|
#FFFF99
>>> tt >>>
Set the x axis minimum and maximum values. No effect if AutoscaleX is true.
>>> tt >>>
x range
d|xmin|-10|xmin:
d|xmax|10|xmax:
setMinMaxY|
#FFFF99
>>> tt >>>
Set the y axis minimum and maximum values. No effect if autoscale is true.
>>> tt >>>
y range
d|ymin|-10|ymin:
d|ymax|10|ymax:
setAutoscaleX|
#FFFF99
>>> tt >>>
Default: X axis extends automatically when values get out of range.
Set AutoscaleY to false to fix the initial range limits.
>>> tt >>>
Autoscale x
b|autoOn|true|Autoscale on:
setAutoscaleY|
#FFFF99
>>> tt >>>
Default: Y axis extends automatically when values get out of range.
Set AutoscaleY to false to fix the initial range limits.
>>> tt >>>
Autoscale y
b|autoOn|true|Autoscale on:
clearAllSeries|
#CCFFCC
>>> tt >>>
Clear all data from the graph.
>>> tt >>>
clear
setSeriesRGB|
#CCFFCC
>>> tt >>>
Set the series line and marker color.
>>> tt >>>
series color
i|id|1|series number:
i|r|255|r:
i|g|0|g:
i|b|0|b:
setSeriesStyle|
#CCFFCC
>>> tt >>>
Set the series style.
points can be connected or not.
marker: 0 for no marker, 1 for crosses, 2 for squares (default), 3 for circles
>>> tt >>>
series style
i|id|1|series number:
b|conPts|true|connect points:
i|m|1|marker:
setAutoReplaceData|
#CCFFCC
>>> tt >>>
Disables the clearSeries function so that new data will replace a dataset when the addData method is called.
>>> tt >>>
AutoReplaceData
i|id|1|series number:
b|auto|true|auto:
setTitle|
#B3EFFF
>>> tt >>>
Set title.
>>> tt >>>
Title
s|title||text:
setLabelX|
#B3EFFF
>>> tt >>>
Set label of x axis.
>>> tt >>>
x label
s|xlabel||text:
setLabelY|
#B3EFFF
>>> tt >>>
Set label of y axis.
>>> tt >>>
Y label
s|ylabel||text:
setShowAxes|
#B3EFFF
>>> tt >>>
Show or hide the the X and Y axes on the graph.
>>> tt >>>
show axes
b|show|true|show:
setStripChart|
#B3EFFF
>>> tt >>>
Set strip chart mode (moving window of a given width) paced by the specified series.
>>> tt >>>
setStripChart
i|sid|1|series:
i|numPts|10|width (data points):
b|stripChart|true|enabled:
setAutoRefresh|
#E9D3FF
>>> tt >>>
Set the autoRefresh property. Automatic repaint if true.
>>> tt >>>
AutoRefresh
b|auto|true|Automatic repaint: