/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package garten.model; /** * * @author Jan */ import java.awt.BasicStroke; import java.text.CharacterIterator; import java.util.ArrayList; import javax.swing.JComponent; import lsystem.Grammar; import lsystem.collection.TurtleStack; import lsystem.turtle.Turtle; public class PflanzeImpl extends JComponent implements Pflanze { ArrayList pts; protected float DELTA; // 18 degrees protected Grammar grammar; final protected String axiom = "F"; protected int generations; //protected String rule; protected float startLength; protected float drawLength; protected float theta; protected float xpos; protected float ypos; protected int positionx; protected int positiony; protected int flaeche; //Position(); TurtleStack ts; //public Line2D.Float Gerade; private BasicStroke pinsel; public PflanzeImpl(int Xstart, int Ystart, int Generation) { positionx = Xstart; positiony = Ystart; generations = Generation; pts = new ArrayList(); ts = new TurtleStack(); //PApplet pinsel = new BasicStroke(2f); //Gerade = new Line2D.Float(); } public void translateRules() { float x_temp, y_temp; Turtle turtle = new Turtle(positionx, positiony, (float) ((Math.PI)/2)); CharacterIterator it = grammar.getIterator(); for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) { switch (ch) { case 'F': x_temp = turtle.getX(); y_temp = turtle.getY(); turtle.setX((float) (x_temp + drawLength * Math.cos((turtle.getTheta())))); turtle.setY((float) (y_temp - drawLength * Math.sin((turtle.getTheta())))); float[] temp = { x_temp, y_temp, turtle.getX(), turtle.getY() }; pts.add(temp); break; case '+': turtle.setTheta(turtle.getTheta() + DELTA); break; case '-': turtle.setTheta(turtle.getTheta() - DELTA); break; case '[': ts.push(new Turtle(turtle)); // Uncomment this (and comment previous line to avoid using clone) break; case ']': turtle = ts.pop(); break; default: System.err.println("character " + ch + " not in grammar"); } } } /* public void draw() { Graphics2D g3 = (Graphics2D) this.getGraphics(); for (float[] pt : pts) { g3.draw(new Line2D.Float(pt[0], pt[1], pt[2], pt[3])); } g3.dispose(); } */ public ArrayList getPoints() { return pts; } public int getPositionx() { return positionx; } public int getPositiony() { return positiony; } public void setPositionx(int x) { positionx = x; } public void setPositiony(int y) { positiony = y; } public int getflaeche() { return flaeche; } public void setPosition() { } }