previous next

This demonstrates using the myPhysicsLab library to draw graphs with JavaScript in the Terminal command line.

NOTE: This will only work on simple-compiled versions of this app; advanced-compiled versions cannot execute JavaScript.

This graph shows a single GraphLine. However, you can change the style (color, line width, dots vs. lines) at any time, so it can look like there are several different graphs being drawn.

To clear all points from the GraphLine:


To plot a new graph use the "plot" command. This adds points to the GraphLine, with the value for "x" going between the two given numbers.

  plot("x*x", -5, 5);

You can specify the number of points plotted as the 4th argument to plot (the default is 200). To add points to the GraphLine in a new color:

  plot("-x*x", -5, 5, 50);

To change the area being shown (arguments are left, bottom, top, right)

  simView.setSimRect(new DoubleRect(-6, -30, 6, 30));

To change line width or drawing mode:

  plot("x", -10, 10);
  plot("-x", -10, 10);

To redraw the entire GraphLine with a different style:


To create a URL with a script that draws an equation: you can provide any of the above commands in the "query" portion of the URL (after the question mark) for this web page. Example:


Valid HTML 4.01