
import java.awt.*;
public class SineWave {
  double wavelength;
  double amplitude;
  double phase;

  public SineWave(double wavelength, double amplitude, double phase) {
    this.wavelength = wavelength;
    this.amplitude = amplitude;
    this.phase = phase;
  }

  public void advance(double phaseIncrement) {
    // note: this advances the initial phase, so a positive value
    // moves the wave form to the left, negative to the right.
    this.phase += phaseIncrement;
  }

  public void setPhase(double phase) {
    this.phase = phase;
  }

  public float getPhase()
  {   return (float)this.phase;
  }
  
  public void setAmplitude(double amplitude) {
    this.amplitude = amplitude;
  }

  public float getAmplitude()
  {   return (float)this.amplitude;
  }
   
  public void setWavelength(double wavelength) {
    this.wavelength = wavelength;
  }

  public float getWavelength()
  {   return (float)this.wavelength;
  }

  public int getY(int x) {
    double degreesPerPixel = 360.0 / wavelength;
    double degrees = phase + x*degreesPerPixel;
    return (int)(amplitude*Math.sin(degrees*Math.PI/180.0));
  }

  public void drawThick(Graphics g, int x, int y, int width) {
    double degreesPerPixel = 360.0 / wavelength;
    int yOffset = (int)(amplitude/2.0)+2;
    double degrees;
    int xloc;
    int yloc;
    for (int i=0; i<width; i++) {
      degrees = phase + i*degreesPerPixel;
      xloc=x+i;
      yloc=(int)(y+yOffset+amplitude*Math.sin(degrees*Math.PI/180.0));
      
      g.drawLine(xloc,yloc-1,xloc,yloc+1);
      
      
    }
  }
  
  public void draw(Graphics g, int x, int y, int length)
  {   for (int i=1; i<=length; i++)
      {  Point p1 = new Point(x+i, y+getY(i));
         Point p2 = new Point(x+i+1, y+getY(i+1));
         
         g.drawLine(p1.x, p1.y, p2.x, p2.y);
       }
  }
  
  public void draw(Graphics g, Point start, Point stop)
  {   float angle = (float)MyMath.getAngle(start, stop);
      float length = MyMath.Length(start.x, start.y, stop.x, stop.y);
      
      for (int i=1; i<=length; i++)
      {  Point p1 = new Point(start.x+i, start.y+getY(i));
         Point p2 = new Point(start.x+i+1, start.y+getY(i+1));
         Point p3 = MyMath.translate(start, p1, angle);
         Point p4 = MyMath.translate(start, p2, angle);
         
         g.drawLine(p3.x, p3.y, p4.x, p4.y);
         
       }
  }
  
  // return phase in degrees when x = length.
  public float getPhase(float length) 
  {   return (float)(360*(length/wavelength) + phase);
  }
    
}



