import java.lang.*;
import java.io.*;
import java.util.*; 

import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;

class Demo extends Frame{

    private static final String VersionsDatum = "29. September 2004";
    
    private int xMax = 1000;   // Anfangs-Breite
    private int yMax = 710;    // Anfangs-Höhe
    private int yOffset = 40;  // oberer Rand
    private int Yh;            // Mittlepunkt ( y Koordinate )
    private int Xh;            // Mittlepunkt ( x Koordinate )
    private float radius;           // Nutzbarer Radius
    
    private static final Font FontMono  = new Font("Monospaced", Font.PLAIN, 18);
    private static final Font FontSansSerif = new Font("SansSerif", Font.PLAIN, 14);
    private static final Font BigItalicSansSerif = new Font("SansSerif", Font.ITALIC, 16);
       
    private static MenuBar MainMenuBar = new MenuBar();
    private static Menu DateiMenu = new Menu("Datei");
    private static MenuItem Beenden = new MenuItem("Beenden");
        
    private static Menu GrafikDemoMenu1 = new Menu("GrafikDemos1");
    private static Menu GrafikDemoMenu2 = new Menu("GrafikDemos2");
    
    private static MenuItem Baum = new MenuItem("Baum");
    private static MenuItem Bsp1 = new MenuItem("Beispiel L");
    private static MenuItem Koch0 = new MenuItem("Koch 0");
    private static MenuItem Koch1 = new MenuItem("Koch 1");
    private static MenuItem Koch2 = new MenuItem("Koch 2");
    private static MenuItem Koch3 = new MenuItem("Koch 3");
    private static MenuItem Koch4 = new MenuItem("Koch 4");
    private static MenuItem Snow0 = new MenuItem("Snow 0");
    private static MenuItem Snow1 = new MenuItem("Snow 1");
    private static MenuItem Snow2 = new MenuItem("Snow 2");
    private static MenuItem Snow3 = new MenuItem("Snow 3");
    private static MenuItem Snow4 = new MenuItem("Snow 4");
    private static MenuItem Snow5 = new MenuItem("Snow 5");
    
    private static MenuItem Dragon = new MenuItem("Dragon");
    private static MenuItem Sierpinski = new MenuItem("Sierpinski");
    private static MenuItem Gosper = new MenuItem("Gosper");
    private static MenuItem EKurve = new MenuItem("EKurve");
    private static MenuItem QS = new MenuItem("QS");
    private static MenuItem Islands = new MenuItem("Islands");
    
    private static Menu HilfeMenu = new Menu("Hilfe");
    private static MenuItem Hilfe = new MenuItem("Es gibt keine Hilfe...");
    private static MenuItem AboutBox = new MenuItem("About");
        
  
    private static String Titel = "Grafik2d Kapitel 4";
        
    //// Constructor.
     
    public Demo () {
	super(Titel);
	
	setFont(FontMono);
	DateiMenu.setFont(FontSansSerif);
	Beenden.setFont(FontSansSerif);
	
	GrafikDemoMenu1.setFont(FontSansSerif);
	Baum.setFont(FontSansSerif);
	Bsp1.setFont(FontSansSerif);
	Koch0.setFont(FontSansSerif);
	Koch1.setFont(FontSansSerif);
	Koch2.setFont(FontSansSerif);
	Koch3.setFont(FontSansSerif);
	Koch4.setFont(FontSansSerif);
	Snow0.setFont(FontSansSerif);
	Snow1.setFont(FontSansSerif);
	Snow2.setFont(FontSansSerif);
	Snow3.setFont(FontSansSerif);
	Snow4.setFont(FontSansSerif);
	Snow5.setFont(FontSansSerif);
	
	GrafikDemoMenu2.setFont(FontSansSerif);
	Dragon.setFont(FontSansSerif);
	Sierpinski.setFont(FontSansSerif);
    Gosper.setFont(FontSansSerif);
    EKurve.setFont(FontSansSerif);
    QS.setFont(FontSansSerif);
    Islands.setFont(FontSansSerif);
		
	HilfeMenu.setFont(FontSansSerif);
	Hilfe.setFont(FontSansSerif);
	AboutBox.setFont(FontSansSerif);
	setLayout(null);

	
	//// Menüs
	setMenuBar(MainMenuBar);
	
	MainMenuBar.add(DateiMenu);
	DateiMenu.addSeparator();
	DateiMenu.add(Beenden);
	
	MainMenuBar.add(GrafikDemoMenu1);
	GrafikDemoMenu1.add(Baum);
	GrafikDemoMenu1.add(Bsp1);
	GrafikDemoMenu1.add(Koch0);
	GrafikDemoMenu1.add(Koch1);
	GrafikDemoMenu1.add(Koch2);
	GrafikDemoMenu1.add(Koch3);
	GrafikDemoMenu1.add(Koch4);
	GrafikDemoMenu1.add(Snow0);
	GrafikDemoMenu1.add(Snow1);
	GrafikDemoMenu1.add(Snow2);
	GrafikDemoMenu1.add(Snow3);
	GrafikDemoMenu1.add(Snow4);
	GrafikDemoMenu1.add(Snow5);
	
	MainMenuBar.add(GrafikDemoMenu2);
	GrafikDemoMenu2.add(Dragon);
	GrafikDemoMenu2.add(Sierpinski);
	GrafikDemoMenu2.add(Gosper);
	GrafikDemoMenu2.add(QS);
	GrafikDemoMenu2.add(EKurve);
	GrafikDemoMenu2.add(Islands);
		
	MainMenuBar.add(HilfeMenu);
	HilfeMenu.add(Hilfe);
	HilfeMenu.addSeparator();
	HilfeMenu.add(AboutBox);
	
	//// Allgemeine Initialisierung
	
	
	//// Menü Listener
	    
	Beenden.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ FensterBeenden(); }
	    });
	    
	Baum.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ 
	        doBaum();
	        }
	    });
	    
	Bsp1.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ 
	        doBsp1();
	        }
	    });
	        
	    
	Koch0.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ 
	        doKoch0();
	        }
	    });    
	    
	Koch1.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ 
	        doKoch1();
	        }
	    });
	    
	Koch2.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ 
	        doKoch2();
	        }
	    });
	    
	Koch3.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ 
	        doKoch3();
	        }
	    });
	    
	Koch4.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ 
	        doKoch4();
	        }
	    });
	    
	Snow0.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ 
	        doSnow0();
	        }
	    });     
	
	Snow1.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ 
	        doSnow1();
	        }
	    }); 
	    
	Snow2.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ 
	        doSnow2();
	        }
	    }); 
	    
	Snow3.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ 
	        doSnow3();
	        }
	    }); 
	    
	Snow4.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ 
	        doSnow4();
	        }
	    }); 
	    
	Snow5.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ 
	        doSnow5();
	        }
	    }); 
	    
	Dragon.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ 
	        doDragon();
	        }
	    });
	    
	Sierpinski.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ 
	        doSierp();
	        }
	    });
	    
	Gosper.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ 
	        doGosper();
	        }
	    });  
	    
	EKurve.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ 
	        doEKurve();
	        }
	    });
	    
	QS.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ 
	        doQS();
	        }
	    });
	    
	Islands.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ 
	        doIslands();
	        }
	    });        
	    
	    
	AboutBox.addActionListener(new ActionListener(){
	    public void actionPerformed(ActionEvent e){ showAboutBox(); }
	    });         
	
	//// Window Listener
	addWindowListener(new WindowAdapter() {    
        public void windowClosing(WindowEvent e) { FensterBeenden(); }
	    });
	    
	//// Jetzt Fenster zeigen!
	setBackground(Color.white);    
	setSize(xMax,yMax);
    setVisible(true);
    doMinMax(); // Vorberechnungen
    }
 //// Ende des Konstruktors  
       
 //// Implementierung der Menübefehle    
    
      
   void doBaum(){
		float yAnfang = yOffset + 2*radius;
		float xAnfang = xMax/2;
		float laenge  = 4*radius/5;
		Turtle mTurtle = new Turtle(xAnfang, yAnfang);
		baum(mTurtle, laenge);
		GeneralPath p = mTurtle.getPath();
		Graphics2D g = (Graphics2D) getGraphics();
		loeschen(g);
		g.draw(p);	
		}
		
	void baum(Turtle mTurtle, float s){
		if (s < 1) return;
		Point2D.Float P = mTurtle.getStiftPosition();
		float w = mTurtle.getStiftRichtung();
		mTurtle.dreheLinks(45);
		mTurtle.vor(s);
		baum(mTurtle, s/2);
		mTurtle.setStiftPosition(P);
		mTurtle.setStiftRichtung(w);
		mTurtle.dreheRechts(45);
		mTurtle.vor(s);
		baum(mTurtle, s/2);
		}
    
    void doBsp1(){
	    doMinMax(); // Vorberechnungen
	    float yAnfang = yOffset + yMax - yMax/10;
	    float xAnfang = xMax/10;
	    float laenge  = radius/2;
	    Turtle mTurtle = new Turtle(xAnfang, yAnfang, 0, laenge, 90 );
	    String st = "FFF-FF-F-F+F+FF-F-FFF";
	    lInterpreter1(mTurtle, st);
	    GeneralPath p = mTurtle.getPath();
      Graphics2D g = (Graphics2D) getGraphics();
    	loeschen(g);
       g.draw(p);	
        }

    void doKoch0(){
	    doMinMax(); // Vorberechnungen
	    float yAnfang = yOffset + yMax - yMax/4;
        float xAnfang = xMax/4;
        float laenge  = radius;
        Turtle mTurtle = new Turtle(xAnfang, yAnfang, 0, laenge, 90);
        String st = L1Generation("F-F-F-F", "F-F+F+FF-F-F+F", "f", 0);
        Graphics2D g = (Graphics2D) getGraphics(); loeschen(g);
        g.drawString(st, 10, 2*yOffset);
        lInterpreter1(mTurtle, st);
        GeneralPath p = mTurtle.getPath();
        g.draw(p);
        } 
        
    void doKoch1(){
    	doMinMax(); // Vorberechnungen
    	float yAnfang = yOffset + yMax - yMax/4;
    	float xAnfang = xMax/4;
    	float laenge  = radius / 4;
    	Turtle mTurtle = new Turtle(xAnfang, yAnfang, 0, laenge, 90);
    	String st = L1Generation("F-F-F-F", "F-F+F+FF-F-F+F", "f", 1);
    	Graphics2D g = (Graphics2D) getGraphics(); loeschen(g);
    	g.drawString(st, 10, yOffset*2);
        lInterpreter1(mTurtle, st);
        GeneralPath p = mTurtle.getPath();
        g.draw(p);
        }
        
    void doKoch2(){
    	doMinMax(); // Vorberechnungen
    	float yAnfang = yOffset + yMax - yMax/4;
    	float xAnfang = xMax/4;
    	float laenge  = radius / 16;
    	Turtle mTurtle = new Turtle(xAnfang, yAnfang, 0, laenge, 90);
    	String st = L1Generation("F-F-F-F", "F-F+F+FF-F-F+F", "f", 2);
    	Graphics2D g = (Graphics2D) getGraphics(); loeschen(g);
    	g.drawString(st, 10, yOffset*2);
        lInterpreter1(mTurtle, st);
        GeneralPath p = mTurtle.getPath();
        g.draw(p);
        }

    void doKoch3(){
    	doMinMax(); // Vorberechnungen
    	float yAnfang = yOffset + yMax - yMax/4;
    	float xAnfang = xMax/4;
    	float laenge  = radius / 64;
    	if (laenge < 1) laenge = 1;
    	Turtle mTurtle = new Turtle(xAnfang, yAnfang, 0, laenge, 90);
    	String st = L1Generation("F-F-F-F", "F-F+F+FF-F-F+F", "f", 3);
    	Graphics2D g = (Graphics2D) getGraphics(); loeschen(g);
    	g.drawString(st, 10, yOffset*2);
        lInterpreter1(mTurtle, st); 
        GeneralPath p = mTurtle.getPath();
        g.draw(p);
        }

    void doKoch4(){
    	doMinMax(); // Vorberechnungen
    	float yAnfang = yOffset + yMax - yMax/4;
    	float xAnfang = xMax/4;
    	float laenge  = radius / 128;
    	if (laenge < 1) laenge = 1;
    	Turtle mTurtle = new Turtle(xAnfang, yAnfang, 0, laenge, 90);
    	String st = L1Generation("F-F-F-F", "F-F+F+FF-F-F+F", "f", 4);
    	Graphics2D g = (Graphics2D) getGraphics(); loeschen(g);
    	g.drawString(st, 10, yOffset*2);
        lInterpreter1(mTurtle, st); 
        GeneralPath p = mTurtle.getPath();
        g.draw(p);
        } 
        
    void doSnow0(){
    	doMinMax(); // Vorberechnungen
			float yAnfang = yOffset + yMax - yMax/4;
			float xAnfang = xMax/4;
			float laenge  = (Math.min(xMax/2, yMax/2));
			Turtle mTurtle = new Turtle(xAnfang,yAnfang,0,laenge,60);
			String st = "F--F--F";
			Graphics2D g = (Graphics2D) getGraphics(); loeschen(g);
			g.drawString(st, 10, yOffset*2);
			lInterpreter1(mTurtle, st);
			GeneralPath p = mTurtle.getPath();
			g.draw(p);
			}
			
    void doSnow1(){
    	doMinMax(); // Vorberechnungen
	    float yAnfang = yOffset + yMax - yMax/4;
    	float xAnfang = xMax/4;
    	float Laenge  = (Math.min(xMax/2, yMax/2)) / 4;
    	Turtle mTurtle = new Turtle(xAnfang, yAnfang, 0, Laenge, 60);
    	String st = L1Generation("F--F--F", "F+F--F+F", "f", 1);
    	Graphics2D g = (Graphics2D) getGraphics(); loeschen(g);
    	g.drawString(st, 10, yOffset*2);
        lInterpreter1(mTurtle, st); 
        GeneralPath p = mTurtle.getPath();
        g.draw(p);
        }

    void doSnow2(){
    	doMinMax(); // Vorberechnungen
	    float yAnfang = yOffset + yMax - yMax/4;
    	float xAnfang = xMax/4;
    	float Laenge  = (Math.min(xMax/2, yMax/2)) / 8;
    	Turtle mTurtle = new Turtle(xAnfang, yAnfang, 0, Laenge, 60);
    	String st = L1Generation("F--F--F", "F+F--F+F", "f", 2);
    	Graphics2D g = (Graphics2D) getGraphics(); loeschen(g);
    	g.drawString(st, 10, yOffset*2);
        lInterpreter1(mTurtle, st); 
        GeneralPath p = mTurtle.getPath();
        g.draw(p);
        }


    void doSnow3(){
    	doMinMax(); // Vorberechnungen
	    float yAnfang = yOffset + yMax - yMax/4;
    	float xAnfang = xMax/4;
    	float Laenge  = (Math.min(xMax/2, yMax/2)) / 20;
    	Turtle mTurtle = new Turtle(xAnfang, yAnfang, 0, Laenge, 60);
    	String st = L1Generation("F--F--F", "F+F--F+F", "f", 3);
    	Graphics2D g = (Graphics2D) getGraphics(); loeschen(g);
    	g.drawString(st, 10, yOffset*2);
        lInterpreter1(mTurtle, st); 
        GeneralPath p = mTurtle.getPath();
        g.draw(p);
        }

    void doSnow4(){
    	doMinMax(); // Vorberechnungen
	    float yAnfang = yOffset + yMax - yMax/4;
    	float xAnfang = xMax/4;
    	float Laenge  = (Math.min(xMax/2, yMax/2)) / 60;
    	Turtle mTurtle = new Turtle(xAnfang, yAnfang, 0, Laenge, 60);
    	String st = L1Generation("F--F--F", "F+F--F+F", "f", 4);
    	Graphics2D g = (Graphics2D) getGraphics(); loeschen(g);
    	g.drawString(st, 10, yOffset*2);
        lInterpreter1(mTurtle, st);
        GeneralPath p = mTurtle.getPath();
        g.draw(p);
        }

    void doSnow5(){
    	doMinMax(); // Vorberechnungen
	    float yAnfang = yOffset + yMax - yMax/4;
    	float xAnfang = xMax/4;
    	float Laenge  = (Math.min(xMax/2, yMax/2)) / 160;
    	Turtle mTurtle = new Turtle(xAnfang, yAnfang, 0, Laenge, 60);
    	String st = L1Generation("F--F--F", "F+F--F+F", "f", 5);
    	Graphics2D g = (Graphics2D) getGraphics(); loeschen(g);
    	g.drawString(st, 10, yOffset*2);
        lInterpreter1(mTurtle, st);
        GeneralPath p = mTurtle.getPath();
        g.draw(p);
        }


    void doDragon(){
    	doMinMax(); // Vorberechnungen
	    float yAnfang = yOffset + yMax/2;
    	float xAnfang = xMax/2;
    	float Laenge  = (Math.min(xMax/2, yMax/2)) / 32;
    	Turtle mTurtle = new Turtle(xAnfang, yAnfang, 0, Laenge, 90);
    	String st = L2Generation("l", "l+r+", "-l-r", "f", 10);
    	Graphics2D g = (Graphics2D) getGraphics(); loeschen(g);
    	g.drawString(st, 10, yOffset*2);
        lInterpreter1(mTurtle, st); 
        GeneralPath p = mTurtle.getPath();
        g.draw(p);
        }

    void doSierp(){
    	doMinMax(); // Vorberechnungen
	    float yAnfang = yOffset + yMax - yMax/4;
    	float xAnfang = xMax/4;
    	float Laenge  = (Math.min(xMax/2, yMax/2)) / 40;
    	Turtle mTurtle = new Turtle(xAnfang, yAnfang, 90, Laenge, 60);
    	String st = L2Generation("r", "r+l+r", "l-r-l", "f", 6);
    	Graphics2D g = (Graphics2D) getGraphics(); loeschen(g);
    	g.drawString(st, 10, yOffset*2);
        lInterpreter1(mTurtle, st);
        GeneralPath p = mTurtle.getPath();
        g.draw(p);
        }

    void doGosper(){
    	doMinMax(); // Vorberechnungen
	    float yAnfang = yOffset + radius;
    	float xAnfang = xMax - xMax/4;
    	float Laenge  = (Math.min(xMax/2, yMax/2)) / 40;
    	Turtle mTurtle = new Turtle(xAnfang, yAnfang, 0, Laenge, 60);
    	String st = L2Generation("l", "l+r++r-l--ll-r+", "-l+rr++r+l--l-r", "f", 4);
    	Graphics2D g = (Graphics2D) getGraphics(); loeschen(g);
    	g.drawString(st, 10, yOffset*2);
        lInterpreter1(mTurtle, st);
        GeneralPath p = mTurtle.getPath();
        g.draw(p);
        }


    void doEKurve(){
    	doMinMax(); // Vorberechnungen
	    float yAnfang = yOffset + yMax - yMax/4;
    	float xAnfang = xMax/4;
    	float Laenge  = (Math.min(xMax/2, yMax/2)) / 100;
    	Turtle mTurtle = new Turtle(xAnfang, yAnfang, 0, Laenge, 90);
    	String st = L2Generation("-r", "ll-r-r+l+l-r-rl+r+llr-l+r+ll+r-lr-r-l+l+rr-", 
    		                    "+ll-r-r+l+lr+l-rr-l-r+lrr-l-rl+l+r-r-l+l+rr", 
    							"f", 3);
    	Graphics2D g = (Graphics2D) getGraphics(); loeschen(g);
    	g.drawString(st, 10, yOffset*2);
        lInterpreter1(mTurtle, st); 
        GeneralPath p = mTurtle.getPath();
        g.draw(p);
        } 
        
    void doQS(){
	    doMinMax(); // Vorberechnungen
	    float yAnfang = yOffset + yMax - yMax/4;
    	float xAnfang = xMax/16;
    	float Laenge  = (Math.min(xMax/2, yMax/2)) / 32;
    	Turtle mTurtle = new Turtle(xAnfang, yAnfang, 0, Laenge, 90);
    	String st = L1Generation("-F", "F+F-F-F+F", "f", 4);
    	Graphics2D g = (Graphics2D) getGraphics(); loeschen(g);
    	g.drawString(st, 10, yOffset*2);
        lInterpreter1(mTurtle, st); 
        GeneralPath p = mTurtle.getPath();
        g.draw(p);
        }
               

    void doIslands(){
	    doMinMax(); // Vorberechnungen
	    float yAnfang = yOffset + 1.6f*radius;
    	float xAnfang = xMax/4;
    	float Laenge  = radius / 36;
    	Turtle mTurtle = new Turtle(xAnfang, yAnfang, 0, Laenge, 90);
    	String st = L1Generation("F-F-F-F", "F+f-FF+F+FF+Ff+FF-f+FF-F-FF-Ff-FFF", "ffffff", 2);
    	Graphics2D g = (Graphics2D) getGraphics(); loeschen(g);
    	g.drawString(st, 10, yOffset*2);
        lInterpreter1(mTurtle, st);
        GeneralPath p = mTurtle.getPath();
        g.draw(p);
        }    
                
    
    void lInterpreter1(Turtle tur, String s){
		int l = s.length();
		for (int i = 0; i < l; i++)
			switch (s.charAt(i)) {
				case 'F' : { tur.vor(); break;}
				case 'f' : { tur.vorUp(); break;}
				case '+' : { tur.dreheLinks();  break;}
				case '-' : { tur.dreheRechts(); break;}
				}
		}

    String L1Generation(String Start, String FRegel, 
											String fRegel, int n){
	String res = Start;
	for (int ng = 0; ng < n; ng++){
		String neu = "";
		int l = res.length();
		for (int i = 0; i < l; i++){
			char c = res.charAt(i);
			switch (c) {
				case 'F' : { neu += FRegel; break;}
				case 'f' : { neu += fRegel; break;}
				default  : { neu += c;  break;}
				}
			}// for i
		res = neu;
		}// for ng
	return res;
	}

    String L2Generation(String Start, String FlRegel, String FrRegel, String fRegel, int n){
	String res = Start;
	for (int ng = 0; ng < n; ng++){
		String neu = "";
		int l = res.length();
		for (int i = 0; i < l; i++){
			char c = res.charAt(i);
			switch (c) {
			  case 'l' : { neu += FlRegel; break;}
              case 'r' : { neu += FrRegel; break;}
			  case 'f' : { neu += fRegel; break;}
			  default  : { neu += c;  break;}
			  }
		   }// for i
		res = neu;
	   }// for ng

    res = res.replace('l', 'F');
    res = res.replace('r', 'F');
	return res;
	}

////  About Box
	
    void showAboutBox(){	
	final Frame f = new Frame("About Box");
	final Button Ok = new Button("Ok");

	f.addWindowListener(new WindowAdapter() {
	    public void windowClosing(WindowEvent e) {
		f.dispose();
		}
	    });
	    
	 Ok.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e) {
		f.dispose();
		}
	    });
	
	f.setFont(BigItalicSansSerif);
	f.setLayout(new GridLayout(0, 1));

	f.add(new Label(" ", Label.CENTER));
	f.add(new Label("Universität Marburg - Fachbereich Mathematik und Informatik", Label.CENTER));
	f.add(new Label("Turtle Grafik, L-Systeme etc...", Label.CENTER));
	f.add(new Label("Datum der letzten Änderung: " + VersionsDatum, Label.CENTER));
	f.add(new Label("Autor: Prof. Dr. Manfred Sommer", Label.CENTER));
	f.add(new Label(" ", Label.CENTER));
	
	f.add(Ok);
	f.pack(); 
	f.setVisible(true);
	}	
	
////  Programm Beenden
    
    void FensterBeenden() {		        
			dispose();
			System.exit(0);
			}	

////  Programm Arcten

    public static void main(String args[]) {
    new Demo();
    }
    
////  Grafik Algorithmen 

    java.util.Random RGen = new java.util.Random();
	
	int random(int max){
	    int i = Math.abs(RGen.nextInt());
	    return i % max;
	    }
	  
	Point ZufallsPunkt(int xm, int ym){
        return new Point(random(xm), random(ym));
        } 
        

    Color ZufallsFarbe(){ 
        return new Color(random(256), random(256), random(256) );
        }
        
    Rectangle ZufallsRechteck(int xm, int ym){
        int x = random(xm-2);
        int y = random(ym-2);
        int w = random(xm - (x+2));
        int h = random(ym - (y+2));
        return new Rectangle(x, y, w, h);
        }     
	  
	void SetPixel(Graphics g, Point P, Color f){
      g.setColor(f);
	  g.drawLine(P.x,P.y,P.x,P.y);
      }
      
    void doMinMax(){
      Dimension d = getSize();
	    xMax = d.width-1;
	    yMax = d.height-1;
	    Xh = (xMax-1)/2;
      int Ya = 40; // oberer Rand
      Yh = Ya + (yMax-(Ya+1))/2;
      int ir =  Math.min(Xh, Yh-Ya);
      if (ir > 10) ir -= 10; else ir = 3;
      radius = (float) ir;
	    }
	    
	void loeschen(Graphics g){
        g.clearRect(0, 0, xMax, yMax);
	    }
}

class Turtle{
	protected float   xKoord = 0;
	protected float   yKoord = 0;
	protected float   richtungWin = 0;
	protected float   richtungRad = 0;
	protected boolean stiftOben  = false;
	protected Color   stiftFarbe = Color.black;
	protected int     stiftDicke = 1;
	protected float   defaultVor = 10;
	protected 	float   	defaultWin = 90;
	private GeneralPath turtleGr;
	Turtle(){ turtleGr = new GeneralPath(); }   
	Turtle(float xpos, float ypos){
		turtleGr = new GeneralPath();
		setStiftPosition(xpos, ypos);
		}  
	Turtle(float xpos, float ypos, int w){
		this(xpos, ypos);
		setStiftRichtung(w);
		}    
	Turtle(float xpos, float ypos, int w, float dV, float dW){
		this(xpos, ypos, w);
		defaultVor = dV;
		defaultWin = dW;
		} 	
	GeneralPath getPath(){return turtleGr;}
	void zurueck(){ vor(-defaultVor);}
	void zurueck(float s){ vor(-s);}
	void vor(){ vor(defaultVor);}
	void vor(float s){
		xKoord += s*Math.sin(richtungRad);
		yKoord -= s*Math.cos(richtungRad);
		if (! stiftOben) turtleGr.lineTo(xKoord, yKoord);
		else turtleGr.moveTo( xKoord, yKoord);
		}
	void vorUp(){ vorUp(defaultVor);}  	
	void vorUp(float s){ stiftHoch(); vor(s); stiftRunter();}  
	void dreheLinks() { dreheLinks(defaultWin);}
	void dreheLinks(float w) { neuerWinkel(richtungWin - w);}
	void dreheRechts() { dreheRechts(defaultWin);}
	void dreheRechts(float w){ neuerWinkel(richtungWin + w);}
	void stiftHoch(){ stiftOben = true;}
	void stiftRunter(){ stiftOben = false;}
	Point2D.Float getStiftPosition(){ 
		return new Point2D.Float(xKoord, yKoord);}  
	void setStiftPosition(Point2D.Float P){ 
		xKoord = P.x; yKoord = P.y; 
		turtleGr.moveTo( xKoord, yKoord);}
	void setStiftPosition(float x, float y){ 
		xKoord = x; yKoord = y; 
		turtleGr.moveTo( xKoord, yKoord);}
	float getStiftRichtung(){ return richtungWin;}	
	void setStiftRichtung(float w){ neuerWinkel(w); }
	Color getStiftFarbe(){ return stiftFarbe;}
	void  setStiftFarbe(Color F){stiftFarbe = F;}
	int  getStiftDicke(){ return stiftDicke;}
	void setStiftDicke(int D){ stiftDicke = D; }
  	void neuerWinkel(float w){ 
		richtungWin = w % 360; 
		richtungRad = toRad(richtungWin);
		}
	float toRad(double rad){ 
		double d = 2.0*Math.PI*rad/360.0;
		return (float) d; 
		} 
	}//Turtle