import java.awt.Color;

/**
 * A driver that can be used to test PA2
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class PA2Driver
{
    /**
     * The entry point of the application
     *
     * @param args   The command line arguments
     */
    public static void main(String[] args)
    {
       FrameBuffer      fb;       
       GraphicsWindow   window;
       Rasterizer2D     rasterizer;
       

       window = new GraphicsWindow();

       fb = window.getFrameBuffer();

       rasterizer = new Rasterizer2D(fb);
       rasterizer.clear(Color.WHITE);
       rasterizer.setFillTechnique(Rasterizer2D.POINTWISE);

       // Fill and draw some polygons
       {
          boolean          yellow;       
          double           delta, size, x, xStart, y;       
          double[][]       q = new double[4][2];       
          size   = 50.0;
          delta  =  0.0;
          yellow = true;
          
          xStart = -100.0;          
          for (y=200.0; y>=-200.0; y-=size)
          {
             for (x=xStart; x<=xStart+300; x+=size)
             {
                q[0][0] = x + delta;
                q[0][1] = y;

                q[1][0] = x + size + delta;
                q[1][1] = y;

                q[2][0] = x + size;
                q[2][1] = y + size;

                q[3][0] = x;
                q[3][1] = y + size;

                yellow = !yellow;

                Color c;
             
                if (yellow)
                   c = Color.YELLOW;
                else
                   c = Color.WHITE;
             
                rasterizer.fillPolygon(c, q);
                rasterizer.drawPolygon(Color.YELLOW, q);
                
             }
             if (y <= - 50.0)   delta = -50.0;
             if (y <= -100.0)   xStart += delta;             
          }
          
       }
       

       
       // Fill and draw some triangles
       {          
          double[][] p = {{-30,30},
                          {115,135},
                          {-90,145},
                          {-180,-45},
                          {-85,-170},
                          {-30,-180},
                          {110,-190},
                          {165,-70},
                          {195,-5}
          };

          int[][] faces = {{0,1,2},
                           {0,2,3},
                           {0,3,5},
                           {0,5,7},
                           {0,7,1},
                           {3,4,5},
                           {5,6,7},
                           {1,7,8}
                           };

          int[][] colors = {{100,100,255},
                            {110,110,255},
                            {80,80,225},
                            {70,70,190},
                            {80,80,215},
                            {35,35,115},
                            {30,30,105},
                            {25,30,80}
                            };
           

          for (int i=0; i<faces.length; i++)
          {
             Color color = new Color(colors[i][0], colors[i][1], colors[i][2]);

             double[] a, b, c;
          
             a = p[faces[i][0]];
             b = p[faces[i][1]];
             c = p[faces[i][2]];
          
             rasterizer.fillTriangle(color, a, b, c);
             rasterizer.drawPolygon(color, a, b, c);
          }
       }
       
       
       fb.show();
    }
}
