@@ -9,39 +9,43 @@ import garten.view.Fenster; | |||
import garten.view.FlaecheBeet; | |||
import garten.view.FlaechePflanzen; | |||
import garten.view.FlaecheWeg; | |||
import java.awt.event.MouseEvent; | |||
import java.awt.event.MouseListener; | |||
import java.util.ArrayList; | |||
/** | |||
* | |||
* @author Jan | |||
*/ | |||
public class Gaertner | |||
public class Gaertner implements MouseListener | |||
{ | |||
private Garten meinGarten; | |||
private Fenster fenster; | |||
private FlaecheBeet flbeet; | |||
private FlaecheWeg flweg; | |||
private FlaechePflanzen flpfl; | |||
private ArrayList<Pflanze> pflanzen; | |||
private ArrayList<Beet> beete; | |||
Pflanze1 pfl; | |||
Pflanze1 pfl2; | |||
Pflanze1 pfl1; | |||
Pflanze2 pfl2; | |||
Pflanze3 pfl3; | |||
int height; | |||
int width; | |||
int[] randomwertex; | |||
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.flpfl = flpfl; | |||
pflanzen = new ArrayList<>(); | |||
beete = new ArrayList<>(); | |||
//Initialisierung der Wege/Beete | |||
height = fenster.getHeight(); | |||
width = fenster.getWidth(); | |||
@@ -51,15 +55,15 @@ public class Gaertner | |||
randomwertey[0] = 10; | |||
randomwertex[3] = width - 50; | |||
randomwertey[3] = height - 50; | |||
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; | |||
randomwertey[i] = wegendey; | |||
} | |||
for (int i = 0; i < randomwertex.length; i++) //Garten Wege hinzufügen | |||
{ | |||
meinGarten.hinzufuegenWeg(randomwertex[i], randomwertey[0], randomwertex[i], randomwertey[3]); | |||
@@ -69,59 +73,40 @@ public class Gaertner | |||
{ | |||
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.zeichneBeete(); | |||
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(); | |||
} | |||
/* | |||
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) | |||
{ | |||
} | |||
} |
@@ -19,6 +19,11 @@ public class Garten extends Kompositum | |||
private ArrayList<Weg> wege; | |||
private ArrayList<Beet> beete; | |||
private ArrayList<Pflanze> pflanzen; | |||
private Pflanze1 pfl1; | |||
private Pflanze2 pfl2; | |||
private Pflanze3 pfl3; | |||
FlaecheBeet flbeet; | |||
FlaecheWeg flweg; | |||
FlaechePflanzen flpfl; | |||
@@ -66,6 +71,68 @@ public class Garten extends Kompositum | |||
{ | |||
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) | |||
{ |
@@ -25,11 +25,10 @@ class Pflanze1 extends PflanzeImpl | |||
public void createLSystem() | |||
{ | |||
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); | |||
drawLength =(float) (startLength * Math.pow(0.7, (double) generations)); | |||
} | |||
} |
@@ -27,9 +27,9 @@ class Pflanze2 extends PflanzeImpl | |||
public void createLSystem() | |||
{ | |||
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); | |||
drawLength = (float) (startLength * Math.pow(0.6, (double) generations)); | |||
} |
@@ -27,9 +27,9 @@ class Pflanze3 extends PflanzeImpl | |||
public void createLSystem() | |||
{ | |||
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); | |||
drawLength = (float) (startLength * Math.pow(0.5, (double) generations)); | |||
} |
@@ -9,7 +9,6 @@ package garten.model; | |||
* | |||
* @author Jan | |||
*/ | |||
import java.awt.BasicStroke; | |||
import java.text.CharacterIterator; | |||
import java.util.ArrayList; | |||
import javax.swing.JComponent; | |||
@@ -37,8 +36,6 @@ public class PflanzeImpl extends JComponent implements Pflanze | |||
protected int flaeche; | |||
//Position(); | |||
TurtleStack ts; | |||
//public Line2D.Float Gerade; | |||
private BasicStroke pinsel; | |||
public PflanzeImpl(int Xstart, int Ystart, int Generation) | |||
{ | |||
@@ -46,10 +43,7 @@ public class PflanzeImpl extends JComponent implements Pflanze | |||
positiony = Ystart; | |||
generations = Generation; | |||
pts = new ArrayList<float[]>(); | |||
ts = new TurtleStack(); //PApplet | |||
pinsel = new BasicStroke(2f); | |||
//Gerade = new Line2D.Float(); | |||
ts = new TurtleStack(); | |||
} | |||
public void translateRules() | |||
@@ -91,18 +85,6 @@ public class PflanzeImpl extends JComponent implements Pflanze | |||
} | |||
} | |||
/* | |||
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; |
@@ -33,7 +33,7 @@ public class Fenster extends JFrame | |||
this.setTitle("Garten von Paul und Jan"); | |||
this.pack(); | |||
this.setDefaultCloseOperation(EXIT_ON_CLOSE); | |||
this.setSize(900, 900); | |||
this.setSize(900,900); | |||
this.setVisible(true); | |||
} | |||