Using the Graph class

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]

SinusGraph.java
public static void main(String args[]) {
   char[][] canvas = new char[24][60];
   Graph graph = new Graph(canvas);
   Function sin = new Function();

   graph.clear();
   graph.setPen('+');
   graph.setRangeX(-Math.PI, Math.PI);
   graph.setRangeY(-1, 1);
   graph.draw(sin);

   System.out.print(graph);
}

*Firstly, we construct an array of 24 arrays that consists of 60 char each.
 
*Then we pass it to the constructor of Graph. All subsequent operations on graph apply on this canvas.
 
*Until now, all characters of the two-dimensional array have the value '\0'. By using graph.clear() we replace them all by spaces.
 
*graph.setPen allows to set the character that will be used later to mark that cell of the two-dimensional array a function result was mapped to.
 
*Then we select the ranges for the x and y coordinates using the methods setRangeX and setRangeY.
 
*Finally, we draw it and print the result.
 

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]
Copyright © 2001, 2002 Andreas Borchert, converted to HTML on February 11, 2002