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 Fall{
      int w = 600;
      int h = 600;
      int wavelength = 250;
      int xtrans = 4;
      int waverep = 5;
      int wavedepth = 40;
      int wavewidth1 = wavelength/2;
      int wavewidth2 = wavelength/4;
      int decrement = wavelength/10;
      int x, y, redint, grnint, bluint,xt,yt;
      Rectangle area;
      BufferedImage displayImage;
      Graphics2D dispGc;
      Color colorOne = new Color(1,1,1);


      public Fall(){

      }

      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 wavelengthField,
        int xtransField,
        int waverepField,
        int wavedepthField) {
       	wavelength = wavelengthField;
	xtrans = xtransField;
       	waverep = waverepField;
       	wavedepth = wavedepthField;
       	displayImage = (imageDraw());
        return displayImage;
      }

      public void generate(){
        wavelength = 100;
        for(int i= 0; i<10; i++){
               wavelength = wavelength + 20;
               opart1.saveImageAsJPEG (imageDraw(), "opartgui/classes/opartgui/customanimation/" + Integer.toString(i)+".jpg");
        }
        wavelength = 250;
        imageDraw();
        }

      public BufferedImage imageDraw (){
             createDisplayImage();
             int i,j,k;
             int offset1 = 0;
	     int offset2 =  wavelength;
             int wavewidth1 = wavelength/2;
             int wavewidth2 = wavelength/4;
             int decrement = wavelength/10;
             int wavetmp = wavelength;
             for(j=1;j<waverep;j++){
                     for(i=1;i<250;i++){
	                        CubicCurve2D.Double fall = 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 = w-(xtrans*i);
                                s.setLocation(xt, offset1);
		                e.setLocation(xt, offset2);
		                a.setLocation((int)(s.x)+(wavedepth+(j*2)), (int)(s.y)+wavewidth1+2);
		                b.setLocation((int)(e.x)-(wavedepth+(j*2)), (int)(e.y)-wavewidth2);
                                fall.setCurve(s, a, b, e);
        	                dispGc.setColor(colorOne);
		                dispGc.setStroke(new BasicStroke(1.0f));
		                dispGc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                                dispGc.draw(fall);
                     }
                     offset1 = offset2;
		     wavelength=(int)(wavelength/2);
		     offset2 = offset1 + wavelength;
		     wavewidth1 = wavelength/2;
    		     wavewidth2 = wavelength/4;
		     if (wavelength<1){j=waverep;}
	     }
             wavelength = wavetmp;
      	     return displayImage;

        }

}
