import java.awt.*;
import java.applet.Applet;
public class Sierrek extends Applet { 
//
//
// Hier die Sache rekursiv. 
//
//
public void triangle(Graphics g, Point a, Point b, Point c, int level){
//
//
if (level <= 0) return;
//
// In das uebergebene Dreieck der Punkte a, b, c wird ein auf dem
// Kopf stehendes eingetragen. Die Punkte a, b, c sind offensichtlich
// Elemente einer Klasse mit Instanzvariablen x und y.
//
//
int xCoords[] = {c.x, (c.x + b.x)/2, (a.x+c.x)/2};
int yCoords[] = {b.y, (c.y+b.y)/2, (c.y + a.y)/2};
//
g.drawPolygon(xCoords, yCoords, 3); 
//
// Jetzt werden die drei neuen Dreiecke bestimmt.
//
Point a1, b1, c1, a2, b2, c2, a3, b3, c3;
//
//
a1= a;
b1 = new Point(c.x, b.y);
c1 = new Point((a.x + c.x)/2, (c.y +a.y) /2);
triangle(g, a1, b1, c1, level-1);
//
//
a2 = new Point(c.x, b.y);
b2 = b;
c2 = new Point((c.x + b.x)/2, (c.y +a.y)/2);
triangle(g,a2, b2, c2, level -1);
//
//
//
a3 = new Point((a.x +c.x)/2, (c.y +a.y)/2);
b3 = new Point((c.x +b.x)/2, (c.y + b.y)/2);
c3 = c;
triangle(g, a3, b3, c3, level-1);

}
//
//
// Hier das Hauptprogramm.
// 
   
    public  void paint (Graphics g){
        int xCoords[] = {210, 590, 400};
        int yCoords[] = {490, 490,  110};
	int level= 15;         //Hier sozusagen die Eingabe. Bei 0 bekommen wir
	                      // nur ein Dreieck. 20 dauert sehr lange. 
//
//
//
//      
        g.drawPolygon(xCoords, yCoords, 3);  // Zeichnet Dreieck. 
//
//      Jetzt der Aufruf.
//       
        triangle(g, new Point(210, 490), new Point(590,490), new Point(400,110), level);
	     	
	}
}
