import java.awt.*;

/**
 * Diese Klasse zeichnet Juliamengen. Sie erweitert die Klasse
 * Fractal und implementiert die draw-Methode.
 */
public class Julia
extends Fractal {

  /**
   * inc gibt die Schrittweite an, mit der durch die imaginaere Ebene
   * gegangen wird.
   */
  protected double inc;

  /**
   * a und b repraesentieren den Real- bzw. den Imaginaerteil von c
   * dar. Die Iteration lautet ja z = z^2 + c
   */ 
  protected double a, b;

  /**
   * Konstruktor fuer Julia-Objekte.
   * Die Schrittweite inc berechnet sich aus dem Verhaeltnis von
   * der hoehe des mathematischen Bereichs zur hoehe des zur
   * Verfuegung stehenden Fensterbereichs.
   */
  public Julia(FCanvas screen,
	       int x, int y, int w, int h,
	       double fx, double fy, double fw, double fh,
	       double a, double b) {
    this.canvas = screen;
    this.inc = fh/screen.height();
    this.a = a; this.b = b;
    this.cx = x; this.cy = y;
    this.cw = w; this.ch = h;
    this.fx = fx - inc; this.fy = fy - inc;
    this.fw = fw; this.fh = fh;
  }

  /**
   * zeichnet eine Juliamenge. Die Iterationsformel lautet dabei
   * z = z^2 + c, wobei z und c komplexe Zahlen sind.
   * Bei Juliamengen wird z ueber die komplexe Zahlenebene verschoben
   * und die Itertion jedesmal neu durchlaufen, bis die Distanz von
   * z bis 0+i0 grosser als 2 ist, oder aber nach 200 Iterationsschritten
   * 2 noch nicht ueberschritten hat.
   **/
  public void draw() {
    int i, j, k, n;            // Indexvariablen
    Color color;

    double t, xx, x, y;        // temporaere Variablen

    t = fy;                    // urspruengliche Basislinie merken
    for(j = 1; j <= cw; j++) {
      // hier kommt Ihr Programmcode
      //

	// Faerben gemaess der Geschwindigkeit, mit der sich der
	// Punkt vom Startpunkt entfernt.
 	     if (n < 2)   { canvas.dot(col[0], cx + j, cy + i); }
	else if (n < 4)   { canvas.dot(col[1], cx + j, cy + i); }
	else if (n < 8)   { canvas.dot(col[2], cx + j, cy + i); }
 	else if (n < 16)  { canvas.dot(col[3], cx + j, cy + i); }
 	else if (n < 32)  { canvas.dot(col[4], cx + j, cy + i); }
 	else if (n < 64)  { canvas.dot(col[5], cx + j, cy + i); }
 	else if (n < 96)  { canvas.dot(col[6], cx + j, cy + i); }
 	else if (n < 144) { canvas.dot(col[7], cx + j, cy + i); }
 	else if (n < 200) { canvas.dot(col[8], cx + j, cy + i); }
	else              { canvas.dot(col[9], cx + j, cy + i); }
       }
  }
}












