// add header comments here
import acm.graphics.*;
import java.awt.*;

public class JuliaSet extends DualSliderProgram {

  public void init() {
    setSize(700, 700);
    super.init();
    setRangeA(-75, 75);
    setRangeB(0, 100);
  }

  public void run() {
    // the a and b of F_a,b(x,y)
    double a = getA() / 100.0;
    double b = getB() / 100.0;
    GPoint JuliaCoef = new GPoint(a, b);

   // add code to draw Julia blocks here

      
    }
  }  // constants
  public static final double ScreenSize = 700;    // Size of graphics window
  public static final double WorldSize = 4.0;     // Size of the "window" in the real world
  public static final GPoint WorldCenter = new GPoint(0.0, 0.0);// Center of the world region
  public static final int GridSize = 350;         // Number of blocks in screen grid
  public static final double BlockSize = ScreenSize / GridSize; // size of squares
  public static final int MaxColors = 11;         // Number of colors used for the display
  public static final int MaxIterations = 40;     // Maximum number of iterations before a
                                                  //   number is declared in the Julia set
  public static final double Threshold = 2.0;     // Distance from beyond which a point will
                                                  //  not return

  // calculate distance from point p to the origin
  public double Norm(GPoint p) {
    double x = p.getX();
    double y = p.getY();
    return Math.sqrt(x * x + y * y);
  }
  
  // next iteration of the Julia map
  public GPoint NextPoint(GPoint p, GPoint JuliaCoef) {
    double x = p.getX();
    double y = p.getY();
    return new GPoint(x * x - y * y + JuliaCoef.getX(),
        2.0 * x * y + JuliaCoef.getY());
  }
  
  // returns the color of the point x, y, indicating how quickly it
  // "escapes" under iterations of the Julia map
  public Color JuliaColor(GPoint p, GPoint JuliaCoef) {
    GPoint Z = new GPoint(p.getX(), p.getY());
    int Iterations = 0;

    while ((Norm(Z) < Threshold) && (Iterations < MaxIterations)) {
      Z = NextPoint(Z, JuliaCoef);
      Iterations++;
    }

    if (Iterations >= MaxIterations) {
      return Color.BLACK;
    } else {
      switch (1 + Iterations % (MaxColors - 1)) {
        case 1:
          return Color.BLUE;
        case 2:
          return Color.CYAN;
        case 3:
          return Color.GREEN;
        case 4:
          return Color.RED;
        case 5:
          return Color.YELLOW;
        case 6:
          return Color.ORANGE;
        case 7:
          return Color.MAGENTA;
        case 8:
          return Color.PINK;
        case 9:
          return Color.WHITE;
        case 10:
          return Color.DARK_GRAY;
        default:
          return Color.GREEN;
      }
    }
  }
  
  // the position of the world point corresponding to the screen point
  public GPoint ScreenToWorld(GPoint p) {
    // replace this code
    return new GPoint(0.0, 0.0);
  }
  
  // position of block at row, col
  public GPoint BlockCorner(int row, int col) {
    // replace this code
    return new GPoint(0.0, 0.0);
  }
}