import garten.view.FlaecheBeet; | import garten.view.FlaecheBeet; | ||||
import garten.view.FlaechePflanzen; | import garten.view.FlaechePflanzen; | ||||
import garten.view.FlaecheWeg; | import garten.view.FlaecheWeg; | ||||
import java.awt.event.MouseEvent; | |||||
import java.awt.event.MouseListener; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
/** | /** | ||||
* | * | ||||
* @author Jan | * @author Jan | ||||
*/ | */ | ||||
public class Gaertner | |||||
public class Gaertner implements MouseListener | |||||
{ | { | ||||
private Garten meinGarten; | private Garten meinGarten; | ||||
private Fenster fenster; | private Fenster fenster; | ||||
private FlaecheBeet flbeet; | private FlaecheBeet flbeet; | ||||
private FlaecheWeg flweg; | private FlaecheWeg flweg; | ||||
private FlaechePflanzen flpfl; | private FlaechePflanzen flpfl; | ||||
private ArrayList<Pflanze> pflanzen; | private ArrayList<Pflanze> pflanzen; | ||||
private ArrayList<Beet> beete; | private ArrayList<Beet> beete; | ||||
Pflanze1 pfl; | |||||
Pflanze1 pfl2; | |||||
Pflanze1 pfl1; | |||||
Pflanze2 pfl2; | |||||
Pflanze3 pfl3; | |||||
int height; | int height; | ||||
int width; | int width; | ||||
int[] randomwertex; | int[] randomwertex; | ||||
int[] randomwertey; | int[] randomwertey; | ||||
public Gaertner(Fenster fenster, FlaecheBeet flbeet, FlaecheWeg flweg,FlaechePflanzen flpfl) | |||||
{ | |||||
meinGarten = new Garten(flbeet,flweg,flpfl); | |||||
public Gaertner(Fenster fenster, FlaecheBeet flbeet, FlaecheWeg flweg, | |||||
FlaechePflanzen flpfl) | |||||
{ | |||||
meinGarten = new Garten(flbeet, flweg, flpfl); | |||||
this.fenster = fenster; //Zur späteren Steuerung Pop up usw. | this.fenster = fenster; //Zur späteren Steuerung Pop up usw. | ||||
this.flpfl = flpfl; | this.flpfl = flpfl; | ||||
pflanzen = new ArrayList<>(); | pflanzen = new ArrayList<>(); | ||||
beete = new ArrayList<>(); | beete = new ArrayList<>(); | ||||
//Initialisierung der Wege/Beete | //Initialisierung der Wege/Beete | ||||
height = fenster.getHeight(); | height = fenster.getHeight(); | ||||
width = fenster.getWidth(); | width = fenster.getWidth(); | ||||
randomwertey[0] = 10; | randomwertey[0] = 10; | ||||
randomwertex[3] = width - 50; | randomwertex[3] = width - 50; | ||||
randomwertey[3] = height - 50; | randomwertey[3] = height - 50; | ||||
for (int i = 1; i < 3; i++) //erstelle Random Punkte für Wege + Beete | for (int i = 1; i < 3; i++) //erstelle Random Punkte für Wege + Beete | ||||
{ | { | ||||
int wegendex = (int) (Math.random() * (170*i) + (200*i)); | |||||
int wegendey = (int) (Math.random() * (170*i) + (200*i)); | |||||
int wegendex = (int) (Math.random() * (170 * i) + (200 * i)); | |||||
int wegendey = (int) (Math.random() * (170 * i) + (200 * i)); | |||||
randomwertex[i] = wegendex; | randomwertex[i] = wegendex; | ||||
randomwertey[i] = wegendey; | randomwertey[i] = wegendey; | ||||
} | } | ||||
for (int i = 0; i < randomwertex.length; i++) //Garten Wege hinzufügen | for (int i = 0; i < randomwertex.length; i++) //Garten Wege hinzufügen | ||||
{ | { | ||||
meinGarten.hinzufuegenWeg(randomwertex[i], randomwertey[0], randomwertex[i], randomwertey[3]); | meinGarten.hinzufuegenWeg(randomwertex[i], randomwertey[0], randomwertex[i], randomwertey[3]); | ||||
{ | { | ||||
for (int j = 0; j < randomwertey.length - 1; j++) | for (int j = 0; j < randomwertey.length - 1; j++) | ||||
{ | { | ||||
meinGarten.hinzufuegenBeet(randomwertex[i] + 10, randomwertey[j] + 10, randomwertex[i + 1]-randomwertex[i]-20,randomwertey[j+1] - randomwertey[j]-20); | |||||
meinGarten.hinzufuegenBeet(randomwertex[i] + 10, randomwertey[j] + 10, randomwertex[i + 1] - randomwertex[i] - 20, randomwertey[j + 1] - randomwertey[j] - 20); | |||||
} | } | ||||
} | } | ||||
meinGarten.zeichneWeg(); | meinGarten.zeichneWeg(); | ||||
meinGarten.zeichneBeete(); | meinGarten.zeichneBeete(); | ||||
beete = meinGarten.getBeete(); | beete = meinGarten.getBeete(); | ||||
for(Beet b : beete) | |||||
{ | |||||
Boolean bepflanzung = true; | |||||
Boolean versetzt = true; | |||||
int[] temp = b.getKoordinaten(); | |||||
int tempx = temp[0]+20; | |||||
int tempy = temp[1]+40; | |||||
int tempxrand = temp [2]; | |||||
int tempyrand = temp [3]; | |||||
do | |||||
{ | |||||
System.out.println("Test"); | |||||
pfl = new Pflanze1(tempx,tempy,3); | |||||
meinGarten.hinzufuegenPflanze(pfl); | |||||
tempx = tempx +50; | |||||
if(tempx > tempxrand -10) | |||||
{ | |||||
if(versetzt) | |||||
{ | |||||
tempx = temp[0]+40; | |||||
versetzt = false; | |||||
} | |||||
else | |||||
{ | |||||
tempx = temp[0]+20; | |||||
versetzt = true; | |||||
} | |||||
tempy = tempy+60; | |||||
} | |||||
if(tempy > tempyrand -10) | |||||
{ | |||||
bepflanzung = false; | |||||
} | |||||
} | |||||
while (bepflanzung); | |||||
break; //Da bei gesamten zu viel Rechenaufwand :( müssen die wirklich einzelen auswählen | |||||
// gibt noch Verbesserungen beim zeichnen aber mach ich später ;) | |||||
} | |||||
meinGarten.randomBepflanzung(); | |||||
meinGarten.zeichnePflanzen(); | meinGarten.zeichnePflanzen(); | ||||
} | } | ||||
/* | |||||
public Pflanze getPflanze(int x,int y) | |||||
@Override | |||||
public void mouseClicked(MouseEvent e) | |||||
{ | |||||
} | |||||
@Override | |||||
public void mousePressed(MouseEvent e) | |||||
{ | |||||
} | |||||
@Override | |||||
public void mouseReleased(MouseEvent e) | |||||
{ | { | ||||
return meinGarten.naechstePflanze(x,y); | |||||
}*/ | |||||
} | |||||
@Override | |||||
public void mouseEntered(MouseEvent e) | |||||
{ | |||||
} | |||||
@Override | |||||
public void mouseExited(MouseEvent e) | |||||
{ | |||||
} | |||||
} | } |
private ArrayList<Weg> wege; | private ArrayList<Weg> wege; | ||||
private ArrayList<Beet> beete; | private ArrayList<Beet> beete; | ||||
private ArrayList<Pflanze> pflanzen; | private ArrayList<Pflanze> pflanzen; | ||||
private Pflanze1 pfl1; | |||||
private Pflanze2 pfl2; | |||||
private Pflanze3 pfl3; | |||||
FlaecheBeet flbeet; | FlaecheBeet flbeet; | ||||
FlaecheWeg flweg; | FlaecheWeg flweg; | ||||
FlaechePflanzen flpfl; | FlaechePflanzen flpfl; | ||||
{ | { | ||||
flpfl.setPflanzen(pflanzen); | flpfl.setPflanzen(pflanzen); | ||||
} | } | ||||
public void randomBepflanzung() | |||||
{ | |||||
for (Beet b : beete) | |||||
{ | |||||
int randomAlter = (int) (Math.random() * 3 + 1); | |||||
int randomTyp = (int) (Math.random() * 3 + 1); | |||||
Boolean bepflanzung = true; | |||||
Boolean versetzt = true; | |||||
int[] temp = b.getKoordinaten(); | |||||
int tempx = temp[0]+10; | |||||
int tempy = temp[1]+20; | |||||
int tempxrand = temp[2] + temp[0]; | |||||
int tempyrand = temp[3] + temp[1]; | |||||
int deltax = (temp[2]-40)/((temp[2]-40)/40); | |||||
int deltay = (temp[3]-40)/((temp[3]-40)/50); | |||||
System.out.println("Rand y" + tempyrand); | |||||
do | |||||
{ | |||||
if (randomTyp == 1) | |||||
{ | |||||
pfl1 = new Pflanze1(tempx, tempy, randomAlter); | |||||
hinzufuegenPflanze(pfl1); | |||||
} | |||||
else if (randomTyp == 2) | |||||
{ | |||||
pfl2 = new Pflanze2(tempx, tempy, randomAlter); | |||||
hinzufuegenPflanze(pfl2); | |||||
} | |||||
else if (randomTyp == 3) | |||||
{ | |||||
pfl3 = new Pflanze3(tempx, tempy, randomAlter); | |||||
hinzufuegenPflanze(pfl3); | |||||
} | |||||
tempx += deltax; | |||||
if (tempx > tempxrand ) | |||||
{ | |||||
if (versetzt) | |||||
{ | |||||
tempx = temp[0] +30; | |||||
versetzt = false; | |||||
} | |||||
else | |||||
{ | |||||
tempx = temp[0]+20; | |||||
versetzt = true; | |||||
} | |||||
System.out.println(tempy); | |||||
tempy += deltay; | |||||
} | |||||
if (tempy > tempyrand) | |||||
{ | |||||
bepflanzung = false; | |||||
} | |||||
} | |||||
while (bepflanzung); | |||||
} | |||||
} | |||||
/* | /* | ||||
public Pflanze naechstePflanze(int x, int y) | public Pflanze naechstePflanze(int x, int y) | ||||
{ | { |
public void createLSystem() | public void createLSystem() | ||||
{ | { | ||||
grammar = new StochasticGrammar(axiom); | grammar = new StochasticGrammar(axiom); | ||||
grammar.addRule('F', "F[+F]F[-F]F", (float) 0.1); // add rule, and weight | |||||
grammar.addRule('F', "F[+F]F", (float) 0.45); | |||||
grammar.addRule('F', "F[-F]F", (float) 0.45); | |||||
grammar.addRule('F',"F[+F]F[-F]F", (float) 0.1); // add rule, and weight | |||||
grammar.addRule('F',"F[+F]F", (float) 0.45); | |||||
grammar.addRule('F',"F[-F]F", (float) 0.45); | |||||
grammar.generateGrammar(generations); | grammar.generateGrammar(generations); | ||||
drawLength =(float) (startLength * Math.pow(0.7, (double) generations)); | drawLength =(float) (startLength * Math.pow(0.7, (double) generations)); | ||||
} | } | ||||
} | } |
public void createLSystem() | public void createLSystem() | ||||
{ | { | ||||
grammar = new StochasticGrammar(axiom); | grammar = new StochasticGrammar(axiom); | ||||
grammar.addRule('F', "F[+FF][-FF]F[-F][+F]F",(float) 0.1); // add rule, and weight | |||||
grammar.addRule('F', "F[+FF][-FF]F[+F][+F]F",(float) 0.3); | |||||
grammar.addRule('F', "F[+F][+FF]F[+F][-F]F",(float) 0.2); | |||||
grammar.addRule('F',"F[+FF][-FF]F[-F][+F]F",(float) 0.1); // add rule, and weight | |||||
grammar.addRule('F',"F[+FF][-FF]F[+F][+F]F",(float) 0.3); | |||||
grammar.addRule('F',"F[+F][+FF]F[+F][-F]F",(float) 0.2); | |||||
grammar.generateGrammar(generations); | grammar.generateGrammar(generations); | ||||
drawLength = (float) (startLength * Math.pow(0.6, (double) generations)); | drawLength = (float) (startLength * Math.pow(0.6, (double) generations)); | ||||
} | } |
public void createLSystem() | public void createLSystem() | ||||
{ | { | ||||
grammar = new StochasticGrammar(axiom); | grammar = new StochasticGrammar(axiom); | ||||
grammar.addRule('F', " FF+[+F-F-F]-[-F+F+F]",(float) 0.1); // add rule, and weight | |||||
grammar.addRule('F', "FF+[+F-F]-[-F+F]",(float) 0.45); | |||||
grammar.addRule('F', "FF+[+F+F+F]-[-F+F]",(float) 0.3); | |||||
grammar.addRule('F',"FF+[+F-F-F]-[-F+F+F]",(float) 0.1); // add rule, and weight | |||||
grammar.addRule('F',"FF+[+F-F]-[-F+F]",(float) 0.45); | |||||
grammar.addRule('F',"FF+[+F+F+F]-[-F+F]",(float) 0.3); | |||||
grammar.generateGrammar(generations); | grammar.generateGrammar(generations); | ||||
drawLength = (float) (startLength * Math.pow(0.5, (double) generations)); | drawLength = (float) (startLength * Math.pow(0.5, (double) generations)); | ||||
} | } |
* | * | ||||
* @author Jan | * @author Jan | ||||
*/ | */ | ||||
import java.awt.BasicStroke; | |||||
import java.text.CharacterIterator; | import java.text.CharacterIterator; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import javax.swing.JComponent; | import javax.swing.JComponent; | ||||
protected int flaeche; | protected int flaeche; | ||||
//Position(); | //Position(); | ||||
TurtleStack ts; | TurtleStack ts; | ||||
//public Line2D.Float Gerade; | |||||
private BasicStroke pinsel; | |||||
public PflanzeImpl(int Xstart, int Ystart, int Generation) | public PflanzeImpl(int Xstart, int Ystart, int Generation) | ||||
{ | { | ||||
positiony = Ystart; | positiony = Ystart; | ||||
generations = Generation; | generations = Generation; | ||||
pts = new ArrayList<float[]>(); | pts = new ArrayList<float[]>(); | ||||
ts = new TurtleStack(); //PApplet | |||||
pinsel = new BasicStroke(2f); | |||||
//Gerade = new Line2D.Float(); | |||||
ts = new TurtleStack(); | |||||
} | } | ||||
public void translateRules() | public void translateRules() | ||||
} | } | ||||
} | } | ||||
/* | |||||
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() | public ArrayList<float[]> getPoints() | ||||
{ | { | ||||
return pts; | return pts; |
this.setTitle("Garten von Paul und Jan"); | this.setTitle("Garten von Paul und Jan"); | ||||
this.pack(); | this.pack(); | ||||
this.setDefaultCloseOperation(EXIT_ON_CLOSE); | this.setDefaultCloseOperation(EXIT_ON_CLOSE); | ||||
this.setSize(900, 900); | |||||
this.setSize(900,900); | |||||
this.setVisible(true); | this.setVisible(true); | ||||
} | } | ||||