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 Ellipse2{
      int x, y;
      int w = 600;
      int h = 600;
      int turnaround = 16;
      int circleQuantity = 28;
      int circleSizeX = 40;
      int circleSizeY = 40;
      Rectangle area;
      BufferedImage displayImage;
      Graphics2D dispGc;
      boolean invert = false;
      Color colorOne = new Color(1,215,215);
      Color colorTwo = new Color(235,1,1);
      int changes[] = {6,4,2,1};
      public Ellipse2(){
      
      }

      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,600,600);
             dispGc.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        }
      }

      public BufferedImage doDraw(int changeOneField,
                       int changeTwoField,
                       int changeThreeField,
                       int changeFourField,
                       int circleSizeField,
                       int circleQuantityField,
                       int turnaroundField){
       	changes[0] = changeOneField;
       	changes[1] = changeTwoField;
       	changes[2] = changeThreeField;
        changes[3] = changeFourField;
        circleSizeX = circleSizeField;
       	circleSizeY = circleSizeField;
       	circleQuantity = (circleQuantityField*2);
       	turnaround = turnaroundField;
        displayImage = (imageDraw());
        return displayImage;
}
      public BufferedImage imageDraw(){
             createDisplayImage();
             int i,j;
             int xcurrent=20;
             int ycurrent=20;
             //int circleSizeX=circleSize;
             //int circleSizeY=circleSize;
             boolean pt = false;
             for(j=1;j<circleQuantity;j++){
                     int circletmp = circleSizeX;
                     for(i=1;i<circleQuantity;i++){
	                        if(i>=(turnaround-11) && i<(turnaround-7)){circleSizeX = circleSizeX-changes[0];}
                                if(i>=(turnaround-7) && i<(turnaround-5)){circleSizeX = circleSizeX-changes[1];}
                                if(i>=(turnaround-5) && i<(turnaround-3)){circleSizeX = circleSizeX-changes[2];}
                                if(i>=(turnaround-3) && i<(turnaround-1)){circleSizeX = circleSizeX-changes[3];}
                                if(i>=turnaround && i<(turnaround+2)){circleSizeX = circleSizeX+changes[3];}
                                if(i>=(turnaround+2) && i<(turnaround+4)){circleSizeX = circleSizeX+changes[2];}
                                if(i>=(turnaround+4) && i<(turnaround+6)){circleSizeX = circleSizeX+changes[1];}
                                if(i>=(turnaround+6) && i<(turnaround+10)){circleSizeX = circleSizeX+changes[0];}
                                if(circleSizeX<0)circleSizeX=0;
                                dispGc.setColor(colorOne       );
                                if (pt==false){
                                   dispGc.setColor(colorTwo);
                                }
		                //dispGC.fill(rect1(0+(5*i),0+(5*j),5,5));
                                dispGc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                                dispGc.fill(new Ellipse2D.Double(xcurrent,ycurrent,circleSizeX,circleSizeY));
                                if (pt==false){
                                              	pt = true;
                                }
                                else{
                                    	pt=false;
                                }
                                xcurrent = xcurrent + circleSizeX;

                     }
                     circleSizeX = circletmp;
                     ycurrent = ycurrent + circleSizeY;
                     if(j>=(turnaround-11) && j<(turnaround-7)){circleSizeY = circleSizeY-changes[0];}
                     if(j>=(turnaround-7) && j<(turnaround-5)){circleSizeY = circleSizeY-changes[1];}
                     if(j>=(turnaround-5) && j<(turnaround-3)){circleSizeY = circleSizeY-changes[2];}
                     if(j>=(turnaround-3) && j<(turnaround-1)){circleSizeY = circleSizeY-changes[3];}
                     if(j>=turnaround && j<(turnaround+2)){circleSizeY = circleSizeY+changes[3];}
                     if(j>=(turnaround+2) && j<(turnaround+4)){circleSizeY = circleSizeY+changes[2];}
                     if(j>=(turnaround+4) && j<(turnaround+6)){circleSizeY = circleSizeY+changes[1];}
                     if(j>=(turnaround+6) && j<(turnaround+10)){circleSizeY = circleSizeY+changes[0];}
                     if(circleSizeY<0)circleSizeY=0;
                     xcurrent = 20;

             }
             return displayImage;
        }

}
