package opartgui;
import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.lang.Math.*;
import java.awt.image.BufferedImage;

public class Orient{
      Rectangle area;
      BufferedImage displayImage;
      Graphics2D dispGc;
      int w = 600;
      int h = 600;
      int triQuantity = 25;
      int ypt = -1000;
      int xoffset = 1;
      Color colorOne = new Color(230,92,36);
      Color colorTwo = new Color(0,120,60);
      Color colorThree = new Color(160,0,130);

      protected void createDisplayImage(){
        displayImage = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
        setOffScrGc();
      }

      protected void setOffScrGc(){
             if (displayImage != null){
                dispGc = displayImage.createGraphics();
                dispGc.fillRect(0,0,w,h);
                dispGc.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
             }
      }


      public Orient(){
      }
      
       public void generate(){
        for(int i= 0; i<10; i++){
               triQuantity = triQuantity -1;
               opart1.saveImageAsJPEG (imageDraw(), "opartgui/classes/opartgui/customanimation/" + Integer.toString(i)+".jpg");
        }
        triQuantity = 25;
        imageDraw();
        }



      public BufferedImage doDraw(int yptField,
                       int triQuantityField,
                       int xOffsetField){
        ypt = 0-yptField;
       	triQuantity = (triQuantityField);
       	xoffset = xOffsetField;
        displayImage = (imageDraw());
        return displayImage;
      }

      public BufferedImage imageDraw(){
             createDisplayImage();
             int j;
             boolean increasing = true;
             int xcurrent = 0;
             int triwidth = 600/triQuantity;
             //String colour = "Color.orange";
             int ytmp = ypt;
             int xoffsettmp = xoffset;
             for (int i=0; i<6; i++){
                 if(i==0){
                        xoffset = xoffset * i;
                        dispGc.setColor(colorOne);
                 }
                 if (i==1){
                        xoffset = xoffset * i;
                        dispGc.setColor(colorTwo);
                        ypt = ypt-(ytmp/5);
                 }
                 if (i==2){
                        xoffset = xoffset * i;
                        dispGc.setColor(colorThree);
                        ypt = ypt-(ytmp/5);
                 }
                 if (i==3){
                        xoffset = (xoffset * i);//-(2*xoffset);
                        dispGc.setColor(colorOne);
                        ypt = ypt-(ytmp/5);
                 }
                 if (i==4){
                        xoffset = (xoffset * i);//-(xoffset);
                        dispGc.setColor(colorTwo);
                        ypt = ypt-(ytmp/5);
                 }
                 if (i==5){
                        xoffset = xoffset * i;
                        dispGc.setColor(Color.white);
                        ypt = ypt-(ytmp/5);
                 }
                 for(j=0;j<triQuantity;j++){
                                int x2Points[] = {xcurrent+xoffset,(triwidth/2)+xcurrent,xcurrent + triwidth-xoffset};
                                int y2Points[] = {h,ypt,h};
                                GeneralPath filledPolygon = new GeneralPath(
                                            GeneralPath.WIND_EVEN_ODD,
           	                            x2Points.length);

                                filledPolygon.moveTo (x2Points[0], y2Points[0]);

                                for (int index = 1; index < x2Points.length; index++){
 	                            filledPolygon.lineTo(x2Points[index],y2Points[index]);
                                };
                                dispGc.setStroke(new BasicStroke(1.0f));
		                dispGc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		                dispGc.fill(filledPolygon);
		                /* if(j<turnaround){
		                         ypt = ypt-ychange;
		                }
		                else{
		                    	ypt = ypt +ychange;
		                }
                                 */
                                 xcurrent = xcurrent+triwidth;
                 }
                 xcurrent = 0;
                 xoffset = xoffsettmp;
             }
             return displayImage;
      }
}
