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 Entice{
      int wavelength = 150;
      int ytransdown = 25;
      int ytransup = 10;
      int xtransdown = 20;
      int xtrans;
      int ytrans;
      int xtransup = 25;
      int waverep = 15;
      int wavedepth = 30;
      int wavewidth = 65;
      int turnaround = 10;
      int linequantity = 25;
      int x, y;
      int w = 600;
      int h = 600;
      Rectangle area;
      BufferedImage displayImage;
      Graphics2D dispGc;


      public Entice(){

      }

      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 BufferedImage doDraw(int wavelengthField,
                       int ytransupField,
                       int xtransupField,
                       int ytransdownField,
                       int xtransdownField,
                       int waverepField,
                       int wavedepthField,
                       int lineQuantityField,
                       int wavewidthField){
       	wavelength = wavelengthField;
       	ytransup = ytransupField;
       	xtransup = xtransupField;
        ytransdown = ytransdownField;
       	xtransdown = xtransdownField;
       	waverep = waverepField;
       	wavedepth = wavedepthField;
       	linequantity = lineQuantityField;
        wavewidth = wavewidthField;
        displayImage = (imageDraw());
        return displayImage;
      }

      public BufferedImage imageDraw(){
             createDisplayImage();
             int i,j,k,offset1, offset2;
             Color redcolor = Color.red;
             Color bluecolor = Color.blue;
             Color greencolor = Color.green;
             Color graycolor = Color.gray;
             Color whitecolor = Color.white;
             int xcurrent = 0;
             int ycurrent = 0;
             CubicCurve2D.Double Entice = new CubicCurve2D.Double();
             Point2D.Double s, e, a, b;
             s = new Point2D.Double();
	     a = new Point2D.Double();
	     b = new Point2D.Double();
	     e = new Point2D.Double();
             for(k=0;k<waverep;k++){
                        for(i=0;i<15;i++){
	                        int xtmp = xcurrent;
                                      xcurrent = xcurrent + 4;
                                      dispGc.setColor(redcolor);
                                      s.setLocation(xcurrent, ycurrent);
		                      e.setLocation(xcurrent, ycurrent+wavelength);
		                      a.setLocation((int)(s.x)+wavedepth, (int)(s.y)+wavewidth);
		                      b.setLocation((int)(e.x)-wavedepth, (int)(e.y)-wavewidth);
		                      Entice.setCurve(s, a, b, e);
                                      dispGc.setStroke(new BasicStroke(8.0f));
		                      dispGc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		                      dispGc.draw(Entice);
		                      xcurrent = xtmp;

		                for(j =0;j<3;j++){
                                      int x1 = 6;
                                      int x2 = 14;
                                      int x3 = 16;
                                      if(j==0)xcurrent = xcurrent + x1;
                                      if(j==1)xcurrent = xcurrent + x2;
                                      if(j==2)xcurrent = xcurrent + x3;
                                      dispGc.setColor(bluecolor);
                                      s.setLocation(xcurrent, ycurrent);
		                      e.setLocation(xcurrent, ycurrent+wavelength);
		                      a.setLocation((int)(s.x)+wavedepth, (int)(s.y)+wavewidth);
		                      b.setLocation((int)(e.x)-wavedepth, (int)(e.y)-wavewidth);
		                      Entice.setCurve(s, a, b, e);
                                      if(j==0){dispGc.setStroke(new BasicStroke(4.0f));}
		                      else{
                                           dispGc.setStroke(new BasicStroke(8.0f));
                                      }
                                      dispGc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		                      dispGc.draw(Entice);

                                }
		                xcurrent = xtmp;
                                for(j=0;j<2;j++){
                                        int x1 = 22;
                                        int x2 = 12;
                                        if(j==0)xcurrent = xcurrent + x1;
                                        if(j==1)xcurrent = xcurrent + x2;
                                        dispGc.setColor(greencolor);
                                        s.setLocation(xcurrent, ycurrent);
		                        e.setLocation(xcurrent, ycurrent+wavelength);
		                        a.setLocation((int)(s.x)+wavedepth, (int)(s.y)+wavewidth);
		                        b.setLocation((int)(e.x)-wavedepth, (int)(e.y)-wavewidth);
		                        Entice.setCurve(s, a, b, e);
                                        dispGc.setStroke(new BasicStroke(4.0f));
		                        dispGc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		                        dispGc.draw(Entice);
                                }
                                xcurrent = xtmp + 44;
                                dispGc.setColor(graycolor);
                                s.setLocation(xcurrent, ycurrent);
		                e.setLocation(xcurrent, ycurrent+wavelength);
		                a.setLocation((int)(s.x)+wavedepth, (int)(s.y)+wavewidth);
		                b.setLocation((int)(e.x)-wavedepth, (int)(e.y)-wavewidth);
		                Entice.setCurve(s, a, b, e);
                                dispGc.setStroke(new BasicStroke(8.0f));
		                dispGc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		                dispGc.draw(Entice);
		                System.out.println(xcurrent);
                        }
                        xcurrent = 0;
                        ycurrent = ycurrent +(wavelength);
                }
                return displayImage;
      }
}
