One dimensional motion with constant velocity.



Write the equation of motion for the red ball in the box below. Your equation will look something like:
x + v*t
Then click on the button to make the blue ball follow your equation of motion. If the two balls do not move together, check you calculations of initial position and velocity of the red ball.

Code

Changes needed to include the graph are highlighted in red.
<html>
<head>
<title>Animator NCSU Example</title>
<script language="JavaScript">
var ball_1 = 0;
var ball_2 = 0;
function initialize(){       
        document.myGraph.setAutoRefresh(false);  
        document.myAnimator.setAutoRefresh(false);  
        document.myAnimator.setShapeRGB(255,0,0);
        ball_1 = document.myAnimator.addObject("circle", "x=-22+(12*t),y=-2,r=10");
        eq = "-20";
        document.myAnimator.setShapeRGB(0,0,255);
        ball_2 = document.myAnimator.addObject("circle", "x="+eq+", y=2,r=10");
        document.myAnimator.setTimeOneShot(5,"End");
        document.myAnimator.setTrail(ball_1,300);
        document.myAnimator.setFootPrints(ball_1,20);
        document.myAnimator.setGhost(ball_1,true);
        document.myAnimator.setTrail(ball_2,300);
        document.myAnimator.setFootPrints(ball_2,20);
        document.myAnimator.setGhost(ball_2,true);
        document.myAnimator.setAutoRefresh(true);  

        document.myGraph.setAutoscaleX(false);
        document.myGraph.setAutoscaleY(false);
        document.myGraph.clearSeries(1);
        document.myGraph.setSeriesStyle(1,true,0);
        document.myGraph.setSeriesRGB(1,255,0,0);
        document.myGraph.clearSeries(2);
        document.myGraph.setSeriesStyle(2,true,0);
        document.myGraph.setSeriesRGB(2,0,0,255);
        document.myGraph.setLabelY("Ball position"); 
        document.myGraph.setLabelX("Time"); 
        document.myGraph.setTitle("Ball Position vs Time"); 
        gid=document.myGraph.getGraphID();
        document.myGraph.setAutoRefresh(true);   
        document.myAnimator.deleteDataConnections();
        document.myAnimator.makeDataConnection(ball_1,gid,1,"t","x");
        document.myAnimator.makeDataConnection(ball_2,gid,2,"t","x"); 
        document.myAnimator.updateDataConnections();

        document.myAnimator.forward();
}
function prob1()
{         document.myAnimator.reset();
          eq = document.myform.equation.value;
        document.myAnimator.setTrajectory(ball_2, eq, "2");
        document.myAnimator.forward();
}
</script>
</head>

<body onload="JavaScript:initialize()">
<h2>One dimensional motion with constant velocity.</h2>
<form name=myform>
<center>
        <applet codebase="../classes/" archive="Animator4_.jar,DataGraph4_.jar,STools4.jar"
        code="dataGraph.DataGraph.class" name="myGraph" width="550" height="160" hspace="0"
        vspace="0" align="middle" mayscript>
          <param name="Function">
          <param name="XMin" value="0">
          <param name="XMax" value="5">
          <param name="YMin" value="-25">
          <param name="YMax" value="25">
          <param name="DataFile">
          <param name="AutoScaleX" value="false">
          <param name="AutoScaleY" value="false">
          <param name="ShowControls" value="false">
        </applet>
<br>
    <applet code="animator4.Animator.class"
    codebase="../classes" id="myAnimator" name="myAnimator"
    archive="Animator4_.jar,DataGraph4_.jar,STools4.jar"
    width="500" height="200">
      <param name="FPS" value="10">
      <param name="dt" value="0.02">
      <param name="pixPerUnit" value="10">
      <param name="gridUnit" value="1.0">
      <param name="showControls" value="false">
    </applet>
<br>
<input type=button value="Run" onClick="Javascript:document.myAnimator.forward()">
<input type=button value ="Step Forward" onClick="Javascript:document.myAnimator.stepTimeForward()">
<input type=button value ="Step Backward" onClick="Javascript:document.myAnimator.stepTimeBack()">
<input type=button value="Pause" onclick=Javascript:document.myAnimator.pause()>
<input type=button value="Reset" onclick="Javascript:document.myAnimator.reset()">
</center>
Write the equation of motion for the red ball in the box below.  Your equation will look 
something like:
<blockquote><i>x</i> + <i>v</i>*t <br>
<input type=text name=equation value="0 + 0*t ">
<input type=button value="Run with new equation" onClick="JavaScript:prob1()">
</blockquote>
Then click on the button to make the blue ball follow your equation of motion.  If the two balls do not move together, check you calculations of initial position and velocity of the red ball.</li>
</ol>
<p></form>
</body>
</html>