// Calculate Sin(X) and draw a graph in ASCII art
// hussein suleman
// CSC1015F
// 19 March 2007

class Sine
{
   public static void main ( String [] args )
	{
	   /// define a constant value for PI
	   float PI = 3.14159265f;
		
		// iterate over all rows of the graph
		for ( float yaxis = 1.1f; yaxis>=-1.1f; yaxis-=0.1f )
	   {
	  
	      // iterate over all x axis positions on the graph
			for ( float x=-2.0f*PI; x<=2.0f*PI; x+=PI/10.0f )
   		{
		      // set up variables for Taylor series    
				float y = 0;
			   float ynum = x;
			   float yden = 1;
			   float ydennum = 1;
			   float sign = 1;
			   float quotient = ynum / yden;

   	      // calculate terms until Taylor series converges		
				while (quotient*quotient > 0.00000001f)
			   {
   			   y += sign * quotient;
				   ynum *= x*x;
				   ydennum += 2;
				   yden *= ydennum * (ydennum-1.0f);
				   sign *= -1;
			      quotient = ynum / yden;	
			   }
			
//	  	 	   System.out.println ("sin ("+x+") = "+y);
            
				// output x axis
				if (yaxis*yaxis < 0.001)
			      System.out.print ("-");
  		      // output y axis	   
				else if (x*x < 0.001)
			      System.out.print ("|");
            // draw point if close enough
		      else if ((y-yaxis)*(y-yaxis) <= 0.05f*0.05f)
				     System.out.print ("O");
		      // draw blank space    
				else
			      System.out.print (" ");
		   }
		   
			// move cursor to next line
		   System.out.println ("");
      }
	}
}
