package opartgui;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.image.BufferedImage.*;
import java.util.*;
import java.beans.*;
import javax.swing.*;
import java.awt.geom.*;
import com.sun.image.codec.jpeg.*;

public class Brittania{

protected BufferedImage displayImage;
protected Graphics2D dispGc;
boolean firstDraw = true;
int x, y;
int w = 600;
int h = 600;
int lineThickness = 40;
int lineULHC = 0;
int lineChange = 2;
int circleULHCStartX = 100;
int circleULHCStartY;
int circleSizeStart = 400;
int circleSizeChange = 50;
int circleOffsetX = 20;
int circleOffsetY = 20;
int lineQuantity = 29;
int circleQuantity = 14;
int ycentre;
boolean yCentreOverride = false;
Rectangle area;
      Color colorOne = new Color(254,254,254);
      Color colorTwo = new Color(1,1,1);


public Brittania(){

}

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

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

public BufferedImage doDraw(int lineQuantityField,
                       int circleSizeField,
                       int circleSizeChangeField,
                       int circleQuantityField,
                       int circleOffsetXField,
                       int circleOffsetYField,
                       int circleULHCStartXField,
                       int circleULHCStartYField,
                       int lineThicknessField,
                       int lineChangeField, boolean yOverride){
       	lineQuantity = lineQuantityField;
       	lineThickness = lineThicknessField;
       	lineChange = lineChangeField;
       	circleSizeChange = circleSizeChangeField;
       	circleSizeStart = circleSizeField;
       	circleQuantity = circleQuantityField;
       	circleOffsetX = circleOffsetXField;
       	circleOffsetY = circleOffsetYField;
       	circleULHCStartX = circleULHCStartXField;
       	circleULHCStartY = circleULHCStartYField;
        displayImage = (imageDraw(yOverride));
        return displayImage;
}

public BufferedImage imageDraw(boolean yOverride){
        yCentreOverride = yOverride;
        createDisplayImage();
        boolean pt = false;
        //int lineThickness = 40;
        int lineULHC = 0;
        //int lineChange = 2;
        //int circleULHCStartX = 100;
        //int circleULHCStartY = 200;
        //int circleSizeStart = 400;
        //int circleSizeChange = 50;
        //int circleOffsetX = 15;
        //int circleOffsetY = 20;
        //int lineQuantity = 29;
        //int circleQuantity = 14;
        for(int j=1;j<lineQuantity;j++){
                int firstHalf = (int)(lineQuantity/2);
                if(j<firstHalf){lineThickness = lineThickness-lineChange;}
                if(j==firstHalf){ycentre = lineULHC-(lineThickness/2);}
                if(j>=(firstHalf+1)){lineThickness = lineThickness+lineChange;}
                dispGc.setColor(colorOne);
                if (pt==false){
                   dispGc.setColor(colorTwo);
                }
                dispGc.fill(new Rectangle2D.Double(0,lineULHC,w,lineThickness));
                if (pt==false){
                   pt = true;
                }
                else{
                   pt=false;
                }
                lineULHC = lineULHC + lineThickness;
        }
        for(int j=0;j<circleQuantity;j++){
                dispGc.setColor(colorOne);
                dispGc.setXORMode(colorTwo);
                if (!yCentreOverride){
                   circleULHCStartY = (ycentre-(circleSizeStart/2));
                   yCentreOverride = true;
                }
                dispGc.fill(new Ellipse2D.Double((circleULHCStartX+((circleSizeChange/2)*j)+(circleOffsetX*j)),
                                                 (circleULHCStartY+((circleSizeChange/2)*j)+(circleOffsetY*j)),
                                                 circleSizeStart-(circleSizeChange*j),
                                                 circleSizeStart-(circleSizeChange*j)));
                lineULHC = lineULHC + lineThickness;
        }
        return displayImage;
}


}
