Plotting functions

exercise No. 160

A simple character based plotting application

Q:

Implement a class to plot e.g. sin(x) and other functions in a terminal like e.g.:

                 ******
               **      **
              *          **
             *             *
            *               *
           *                 *
          *                   *
         *                     *
        *
       *                        *
                                 *
      *                           *
     *
    *                              *
                                    *
   *
  *                                  *
                                      *
 *
*                                      *                                       *
                                        *
                                                                              *
                                         *
                                          *                                  *
                                                                            *
                                           *
                                            *                              *
                                                                          *
                                             *                           *
                                              *
                                               *                        *
                                                                       *
                                                *                     *
                                                 *                   *
                                                  *                 *
                                                   *               *
                                                    *             *
                                                     **          *
                                                       **      **
                                                         ******

A:

The current solution is not yet very flexible: The intended plot function is hard coded within the PlotSine class:

	static void plotSine() {
		init();
		
		for (int xTics = 0; xTics < numTicsX; xTics++) {
			double x = xMin + xTics * xStepWidth;
			double sinOfX = Math.sin(x);
			
...
		}
	}

You'll find a more sophisticated approach using interfaces in upcoming the section called “An interface based plotter”.