123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- /*
- * 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<float[]> 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<float[]>();
- 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<float[]> 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()
- {
- }
-
- }
|