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


public class Accident{

      int wavelength = 250;
      int ytrans = 6;
      int xtrans = 0;
      int waverep = 15;
      int wavedepth = 50;
      int wavewidth = wavelength/4;
      int x, y, redint, grnint, bluint,xt,yt;
      int w = 600;
      int h = 600;
      Rectangle area;
      BufferedImage displayImage;
      Graphics2D dispGc;
      boolean firstDraw = true;
      Color colorOne = new Color(1,1,1);


      public Accident(){
             //setBackground(Color.white);
      }
      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 ytransField,
                       int xtransField,
                       int waverepField,
                       int wavedepthField){
       	wavelength = wavelengthField;
       	ytrans = ytransField;
       	xtrans = xtransField;
       	waverep = waverepField;
       	wavedepth = wavedepthField;
       	wavewidth = wavelength/4;
        displayImage = (imageDraw());
        return displayImage;
      }
      public BufferedImage imageDraw(){
             createDisplayImage();
             int i,j,k;
             int offset1 = 0;
	     int offset2 =  wavelength;
	     int wavetmp = wavelength;
             for(j=0;j<waverep;j++){
                     //System.out.println("j = " +j);
                     for(i=1;i<150;i++){
                                //System.out.println("i = " +i);
	                        CubicCurve2D.Double accident = 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();
                                xt = xtrans*i;
                                yt = (h-(ytrans*i));
                                s.setLocation(yt, offset1-xt);
		                e.setLocation(yt, offset2-xt);
		                a.setLocation((int)(s.y)+wavedepth, (int)(s.y)-wavewidth);
		                b.setLocation((int)(e.y)-wavedepth, (int)(e.y)+wavewidth);
                                accident.setCurve(s, a, b, e);
        	                dispGc.setColor(colorOne);
		                dispGc.setStroke(new BasicStroke(1.5f));
		                dispGc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                                dispGc.draw(accident);
                     }
                     offset1 = offset2;
		     wavelength=(int)(wavelength/1.7);
		     offset2 = offset1 + wavelength;
		     wavewidth = wavelength/4;
		     if (wavelength<1){j=waverep;}
	     }
	     wavelength = wavetmp;
             return displayImage;
      }
}
