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 Crest{
      int w = 600;
      int h = 600;
      int x, y;
      int wavewidth[] = {250,50,100,200};
      int wavedepth[] = {20,150,180,20};
      int xtrans = 5;
      Rectangle area;
      BufferedImage displayImage;
      Graphics2D dispGc;
      Color colorOne = new Color(1,1,1);

      public Crest(){

      }

      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 wavewidthOneField,
        int wavewidthTwoField,
        int wavewidthThreeField,
        int wavewidthFourField,
        int wavedepthOneField,
        int wavedepthTwoField,
        int wavedepthThreeField,
        int wavedepthFourField,
        int xtransField){
       	wavewidth[0] = wavewidthOneField;
	wavewidth[1] = wavewidthTwoField;
	wavewidth[2] = wavewidthThreeField;
	wavewidth[3] = wavewidthFourField;
        xtrans = xtransField;
       	wavedepth[0] = wavedepthOneField;
	wavedepth[1] = wavedepthTwoField;
	wavedepth[2] = wavedepthThreeField;
	wavedepth[3] = wavedepthFourField;
       	displayImage = (imageDraw());
        return displayImage;
      }

      public BufferedImage imageDraw (){
             createDisplayImage();
             int i,j,k;
             int wavelength= 300;
             int offset1 = 0;
	     int offset2 =  wavelength;
             for(j=0;j<2;j++){
                     for(i=1;i<(w/xtrans);i++){
	                        CubicCurve2D.Double crest = 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();
                                int xt = xtrans*i;
                                s.setLocation(xt, offset1);
		                e.setLocation(xt, offset2);
		                a.setLocation((int)(s.x)+(wavedepth[j]), (int)(s.y)+(wavewidth[j]));
		                b.setLocation((int)(e.x)-(wavedepth[j+1]), (int)(e.y)-(wavewidth[j+1]));
                                crest.setCurve(s, a, b, e);
        	                dispGc.setColor(colorOne);
		                dispGc.setStroke(new BasicStroke(1.0f));
		                dispGc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                                int x1Points[] = {300, 580, 300, 20};
                                int y1Points[] = {20, 300, 580, 300};
                                GeneralPath polygon = new GeneralPath(GeneralPath.WIND_EVEN_ODD,
                                		     x1Points.length);
                                polygon.moveTo(x1Points[0], y1Points[0]);

                                for (int index = 1; index < x1Points.length; index++) {
                                polygon.lineTo(x1Points[index],y1Points[index]);
                                };
                                polygon.closePath();
                                dispGc.setClip(polygon);
                                dispGc.draw(crest);

                     }
                     offset1= offset1 + wavelength;
                     offset2= offset2 + wavelength;
             }
      	     return displayImage;

        }

}
