package opartgui;
import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.applet.Applet;
import java.awt.geom.*;
import java.awt.image.*;
import java.awt.image.BufferedImage;

public class Rect{
      int x, y;
      int w = 600;
      int h = 600;
      int turnaround = 16;
      int rectQuantity = 28;
      int rectSize = 40;
      Rectangle area;
      BufferedImage displayImage;
      Graphics2D dispGc;
      int changes[] = {6,4,2,1};
      Color colorOne = new Color(254,254,254);
      Color colorTwo = new Color(1,1,1);


      public Rect(){

      }

      public BufferedImage doDraw(int changeOneField,
                       int changeTwoField,
                       int changeThreeField,
                       int changeFourField,
                       int rectSizeField,
                       int rectQuantityField,
                       int turnaroundField){
       	changes[0] = changeOneField;
       	changes[1] = changeTwoField;
       	changes[2] = changeThreeField;
        changes[3] = changeFourField;
       	rectSize = rectSizeField;
       	rectQuantity = (rectQuantityField*2);
       	turnaround = turnaroundField;
        displayImage = (imageDraw());
        return displayImage;
      }

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

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

      public BufferedImage imageDraw(){
             createDisplayImage();
             int i,j;
             int xcurrent=20;
             boolean pt = false;
             for(j=1;j<(rectQuantity/2);j++){
                     int recttmp = rectSize;
                     for(i=1;i<rectQuantity;i++){
	                        if(i>=(turnaround-11) && i<(turnaround-7)){rectSize = rectSize-changes[0];}
                                if(i>=(turnaround-7) && i<(turnaround-5)){rectSize = rectSize-changes[1];}
                                if(i>=(turnaround-5) && i<(turnaround-3)){rectSize = rectSize-changes[2];}
                                if(i>=(turnaround-3) && i<(turnaround-1)){rectSize = rectSize-changes[3];}
                                if(i>=turnaround && i<(turnaround+2)){rectSize = rectSize+changes[3];}
                                if(i>=(turnaround+2) && i<(turnaround+4)){rectSize = rectSize+changes[2];}
                                if(i>=(turnaround+4) && i<(turnaround+6)){rectSize = rectSize+changes[1];}
                                if(i>=(turnaround+6) && i<(turnaround+10)){rectSize = rectSize+changes[0];}
                                if(rectSize<0)rectSize=0;
                                if(rectSize>recttmp)rectSize=recttmp;
                                dispGc.setColor(colorOne);
                                if (pt==false){
                                   dispGc.setColor(colorTwo);
                                }
		                dispGc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                                dispGc.fill(new Rectangle2D.Double(xcurrent,20+(recttmp*j),rectSize,recttmp));
                                if (pt==false){
                                              	pt = true;
                                }
                                else{
                                    	pt=false;
                                }
                                xcurrent = xcurrent + rectSize;
                     }
                     rectSize = recttmp;
                     xcurrent = 20;
             }
             return displayImage;
        }

}
