sims.experimental.GraphCalc2App

previous next

This demonstrates using the myPhysicsLab library to draw graphs. The equation of the graph can be entered as JavaScript in the Terminal command line interface.

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:

  graphLine.reset();

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. The "b" value is set by the slider control below the graph.

  plot("b*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:

  graphLine.setColor("red");
  plot("-b*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:

  graphLine.setLineWidth(2);
  plot("x", -10, 10);
  graphLine.setDrawingMode("dots");
  graphLine.setColor("black");
  plot("-x", -10, 10);

To redraw the entire GraphLine with a different style:

  graphLine.setColor('blue');
  graphLine.resetStyle();
  graph.reset();
Valid HTML 4.01