.
This commit is contained in:
parent
3333785517
commit
60ff8db8ad
31
Garten/src/garten/model/Beet.java
Normal file
31
Garten/src/garten/model/Beet.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
class Beet extends Gartenkomponente
|
||||||
|
{
|
||||||
|
int positionx2;
|
||||||
|
int positiony2;
|
||||||
|
|
||||||
|
Beet(int x, int y,int x2, int y2)
|
||||||
|
{
|
||||||
|
positionx = x;
|
||||||
|
positiony = y;
|
||||||
|
positionx2 = x2;
|
||||||
|
positiony2 = y2;
|
||||||
|
}
|
||||||
|
public int [] getKoordinaten()
|
||||||
|
{
|
||||||
|
int[] temp = {positionx,positiony,positionx2,positiony2};
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
103
Garten/src/garten/model/Gaertner.java
Normal file
103
Garten/src/garten/model/Gaertner.java
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import garten.view.Fenster;
|
||||||
|
import garten.view.FlaecheBeet;
|
||||||
|
import garten.view.FlaechePflanzen;
|
||||||
|
import garten.view.FlaecheWeg;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jan
|
||||||
|
*/
|
||||||
|
public class Gaertner
|
||||||
|
{
|
||||||
|
private Garten meinGarten;
|
||||||
|
private Fenster fenster;
|
||||||
|
private FlaecheBeet flbeet;
|
||||||
|
private FlaecheWeg flweg;
|
||||||
|
private FlaechePflanzen flpfl;
|
||||||
|
|
||||||
|
private ArrayList<Pflanze> pflanzen;
|
||||||
|
|
||||||
|
Pflanze1 pfl;
|
||||||
|
Pflanze1 pfl2;
|
||||||
|
int height;
|
||||||
|
int width;
|
||||||
|
|
||||||
|
int[] randomwertex;
|
||||||
|
int[] randomwertey;
|
||||||
|
|
||||||
|
public Gaertner(Fenster fenster, FlaecheBeet flbeet, FlaecheWeg flweg,FlaechePflanzen flpfl)
|
||||||
|
{
|
||||||
|
meinGarten = new Garten(flbeet,flweg,flpfl);
|
||||||
|
this.flbeet = flbeet;
|
||||||
|
this.fenster = fenster;
|
||||||
|
this.flweg = flweg;
|
||||||
|
pflanzen = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
height = fenster.getHeight();
|
||||||
|
width = fenster.getWidth();
|
||||||
|
|
||||||
|
randomwertex = new int[4];
|
||||||
|
randomwertey = new int[4];
|
||||||
|
randomwertex[0] = 10;
|
||||||
|
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));
|
||||||
|
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]);
|
||||||
|
meinGarten.hinzufuegenWeg(randomwertex[0], randomwertey[i], randomwertex[3], randomwertey[i]);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < randomwertex.length - 1; i++) //Garten Beete hinzufügen
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Beet * Weg zeichen, muss noch in Garten (geht halt so recht schön)
|
||||||
|
flbeet.setBeet(randomwertex,randomwertey);
|
||||||
|
flweg.setWeg(randomwertex,randomwertey);
|
||||||
|
|
||||||
|
pfl = new Pflanze1(100,100,3);
|
||||||
|
//pfl2 = new Pflanze1(200,400,2);
|
||||||
|
pflanzen.add(pfl);
|
||||||
|
//pflanzen.add(pfl2);
|
||||||
|
|
||||||
|
flpfl.setPflanzen(pflanzen);
|
||||||
|
//meinGarten.hinzufuegenPflanze(pfl);
|
||||||
|
// meinGarten.hinzufuegenPflanze(pfl2);
|
||||||
|
meinGarten.zeichnePflanzen();
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
public Pflanze getPflanze(int x,int y)
|
||||||
|
{
|
||||||
|
return meinGarten.naechstePflanze(x,y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zeichnen()
|
||||||
|
{
|
||||||
|
//meinGarten.zeichnen();
|
||||||
|
pfl.draw();
|
||||||
|
System.out.println("??");
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
}
|
106
Garten/src/garten/model/Garten.java
Normal file
106
Garten/src/garten/model/Garten.java
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import garten.view.FlaecheBeet;
|
||||||
|
import garten.view.FlaechePflanzen;
|
||||||
|
import garten.view.FlaecheWeg;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jan
|
||||||
|
*/
|
||||||
|
public class Garten extends Kompositum
|
||||||
|
{
|
||||||
|
private ArrayList<Weg> wege;
|
||||||
|
private ArrayList<Beet> beete;
|
||||||
|
private ArrayList<Pflanze> pflanzen;
|
||||||
|
FlaecheBeet flbeet;
|
||||||
|
FlaecheWeg flweg;
|
||||||
|
FlaechePflanzen flpfl;
|
||||||
|
|
||||||
|
public Garten(FlaecheBeet flbeet,FlaecheWeg flweg,FlaechePflanzen flpfl)
|
||||||
|
{
|
||||||
|
wege = new ArrayList();
|
||||||
|
beete = new ArrayList();
|
||||||
|
pflanzen = new ArrayList();
|
||||||
|
|
||||||
|
this.flbeet = flbeet;
|
||||||
|
this.flweg = flweg;
|
||||||
|
this.flpfl = flpfl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hinzufuegenBeet(int x, int y, int a, int b)
|
||||||
|
{
|
||||||
|
Beet neuesBeet = new Beet(x, y, a, b);
|
||||||
|
beete.add(neuesBeet);
|
||||||
|
}
|
||||||
|
public ArrayList<Beet> liefeBeete()
|
||||||
|
{
|
||||||
|
return beete;
|
||||||
|
}
|
||||||
|
public void zeichneBeete()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public void zeichnePflanzen()
|
||||||
|
{
|
||||||
|
flpfl.setPflanzen(pflanzen);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hinzufuegenWeg(int sx, int sy, int ex, int ey)
|
||||||
|
{
|
||||||
|
Weg neuerWeg = new Weg(sx, sy, ex, ey);
|
||||||
|
wege.add(neuerWeg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hinzufuegenPflanze(Pflanze pflanze)
|
||||||
|
{
|
||||||
|
pflanzen.add(pflanze);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
public Pflanze naechstePflanze(int x, int y)
|
||||||
|
{
|
||||||
|
Pflanze diePflanze = null;
|
||||||
|
int abstand = 1000;
|
||||||
|
for(int i = 0; i < pflanzen.size(); i++)
|
||||||
|
{
|
||||||
|
if(pflanzen.get(i).getPositionx()-x + pflanzen.get(i).getPositiony()-y < abstand)
|
||||||
|
{
|
||||||
|
print(pflanzen.size());
|
||||||
|
diePflanze = pflanzen.get(i);
|
||||||
|
abstand = Math.abs(x-pflanzen.get(i).getPositionx()) + Math.abs(y-pflanzen.get(i).getPositiony()) ;
|
||||||
|
print(pflanzen.get(i).getPositionx());
|
||||||
|
print(pflanzen.get(i).getPositiony());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(abstand < 20)
|
||||||
|
{
|
||||||
|
return diePflanze;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zeichnen()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < wege.size(); i++)
|
||||||
|
{
|
||||||
|
wege.get(i).zeichnen();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < beete.size(); i++)
|
||||||
|
{
|
||||||
|
beete.get(i).zeichnen();
|
||||||
|
}
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
}
|
49
Garten/src/garten/model/Gartenkomponente.java
Normal file
49
Garten/src/garten/model/Gartenkomponente.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.awt.Graphics;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jan
|
||||||
|
*/
|
||||||
|
public class Gartenkomponente implements Position
|
||||||
|
{
|
||||||
|
int flaeche = 50;
|
||||||
|
public int positionx = 0;
|
||||||
|
public int positiony = 0;
|
||||||
|
|
||||||
|
public void setflaeche(int flaeche)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public void setPositionx(int x)
|
||||||
|
{
|
||||||
|
positionx = x;
|
||||||
|
}
|
||||||
|
public void setPositiony(int y)
|
||||||
|
{
|
||||||
|
positiony = y;
|
||||||
|
}
|
||||||
|
public int getflaeche()
|
||||||
|
{
|
||||||
|
return flaeche*flaeche;
|
||||||
|
}
|
||||||
|
public int getPositionx()
|
||||||
|
{
|
||||||
|
return positionx;
|
||||||
|
}
|
||||||
|
public int getPositiony()
|
||||||
|
{
|
||||||
|
return positiony;
|
||||||
|
}
|
||||||
|
public void paintComponent(Graphics g)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
19
Garten/src/garten/model/Kompositum.java
Normal file
19
Garten/src/garten/model/Kompositum.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public class Kompositum
|
||||||
|
{
|
||||||
|
public Kompositum()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
24
Garten/src/garten/model/Pflanze.java
Normal file
24
Garten/src/garten/model/Pflanze.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jan
|
||||||
|
*/
|
||||||
|
public interface Pflanze
|
||||||
|
{
|
||||||
|
Position eigenePosition = null;
|
||||||
|
|
||||||
|
void setPosition();
|
||||||
|
//Position lieferePosition();
|
||||||
|
//TurtleStack ts = new TurtleStack();
|
||||||
|
//public void draw();
|
||||||
|
public ArrayList<float[]> getPoints();
|
||||||
|
|
||||||
|
}
|
35
Garten/src/garten/model/Pflanze1.java
Normal file
35
Garten/src/garten/model/Pflanze1.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* 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 lsystem.StochasticGrammar;
|
||||||
|
|
||||||
|
class Pflanze1 extends PflanzeImpl
|
||||||
|
{
|
||||||
|
Pflanze1(int Xstart, int Ystart, int Generation)
|
||||||
|
{
|
||||||
|
super(Xstart,Ystart,Generation);
|
||||||
|
DELTA = (float) ((Math.PI)/10);
|
||||||
|
startLength = 30;
|
||||||
|
createLSystem();
|
||||||
|
translateRules();
|
||||||
|
}
|
||||||
|
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.generateGrammar(generations);
|
||||||
|
drawLength =(float) (startLength * Math.pow(0.7, (double) generations));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
36
Garten/src/garten/model/Pflanze2.java
Normal file
36
Garten/src/garten/model/Pflanze2.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* 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 lsystem.StochasticGrammar;
|
||||||
|
|
||||||
|
class Pflanze2 extends PflanzeImpl
|
||||||
|
{
|
||||||
|
Pflanze2(int Xstart, int Ystart, int Generation)
|
||||||
|
{
|
||||||
|
super(Xstart,Ystart,Generation);
|
||||||
|
|
||||||
|
DELTA = (float) ((Math.PI)/5);
|
||||||
|
startLength = 10;
|
||||||
|
createLSystem();
|
||||||
|
translateRules();
|
||||||
|
}
|
||||||
|
|
||||||
|
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.generateGrammar(generations);
|
||||||
|
drawLength = (float) (startLength * Math.pow(0.6, (double) generations));
|
||||||
|
}
|
||||||
|
}
|
36
Garten/src/garten/model/Pflanze3.java
Normal file
36
Garten/src/garten/model/Pflanze3.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* 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 lsystem.StochasticGrammar;
|
||||||
|
|
||||||
|
class Pflanze3 extends PflanzeImpl
|
||||||
|
{
|
||||||
|
Pflanze3(int Xstart, int Ystart, int Generation)
|
||||||
|
{
|
||||||
|
super(Xstart,Ystart,Generation);
|
||||||
|
|
||||||
|
DELTA = (float) ((Math.PI)/5);
|
||||||
|
startLength = 10;
|
||||||
|
createLSystem();
|
||||||
|
translateRules();
|
||||||
|
}
|
||||||
|
|
||||||
|
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.generateGrammar(generations);
|
||||||
|
drawLength = (float) (startLength * Math.pow(0.5, (double) generations));
|
||||||
|
}
|
||||||
|
}
|
146
Garten/src/garten/model/PflanzeImpl.java
Normal file
146
Garten/src/garten/model/PflanzeImpl.java
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
/*
|
||||||
|
* 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()
|
||||||
|
};
|
||||||
|
System.out.println("Punkte :" +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 void setflaeche(int flaeche)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getflaeche()
|
||||||
|
{
|
||||||
|
return flaeche;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPosition()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
25
Garten/src/garten/model/Position.java
Normal file
25
Garten/src/garten/model/Position.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public interface Position
|
||||||
|
{
|
||||||
|
int flaeche = 0;
|
||||||
|
public int positionx = 0;
|
||||||
|
public int positiony = 0;
|
||||||
|
|
||||||
|
public void setflaeche(int flaeche);
|
||||||
|
public void setPositionx(int x);
|
||||||
|
public void setPositiony(int y);
|
||||||
|
public int getflaeche();
|
||||||
|
public int getPositionx();
|
||||||
|
public int getPositiony();
|
||||||
|
|
||||||
|
}
|
36
Garten/src/garten/model/Weg.java
Normal file
36
Garten/src/garten/model/Weg.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
class Weg extends Gartenkomponente
|
||||||
|
{
|
||||||
|
|
||||||
|
int startpositionx,startpositiony,endpositionx,endpositiony;
|
||||||
|
Weg(int sx, int sy, int ex, int ey)
|
||||||
|
{
|
||||||
|
startpositionx = sx;
|
||||||
|
startpositiony = sy;
|
||||||
|
endpositionx = ex;
|
||||||
|
endpositiony = ey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zeichnen()
|
||||||
|
{/*
|
||||||
|
fill(105,105,105);
|
||||||
|
strokeWeight(10);
|
||||||
|
strokeCap(PROJECT);
|
||||||
|
line(startpositionx,startpositiony,endpositionx,endpositiony);
|
||||||
|
strokeWeight(1);
|
||||||
|
noFill();
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
54
Garten/src/garten/start.java
Normal file
54
Garten/src/garten/start.java
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import garten.model.Gaertner;
|
||||||
|
import garten.view.Fenster;
|
||||||
|
import garten.view.FlaecheBeet;
|
||||||
|
import garten.view.FlaechePflanzen;
|
||||||
|
import garten.view.FlaecheWeg;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Container;
|
||||||
|
import javax.swing.OverlayLayout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder Class
|
||||||
|
* @author Jan
|
||||||
|
*/
|
||||||
|
public class start
|
||||||
|
{
|
||||||
|
public start()
|
||||||
|
{
|
||||||
|
|
||||||
|
Color hintergrund = new Color(34, 139, 34);
|
||||||
|
Fenster view = new Fenster();
|
||||||
|
FlaecheBeet flbeet = new FlaecheBeet();
|
||||||
|
FlaecheWeg flweg = new FlaecheWeg();
|
||||||
|
FlaechePflanzen flpflanzen = new FlaechePflanzen();
|
||||||
|
flpflanzen.setOpaque(false);
|
||||||
|
flweg.setOpaque(false);
|
||||||
|
flbeet.setOpaque(false);
|
||||||
|
|
||||||
|
|
||||||
|
Container hauptkiste = view.getContentPane();
|
||||||
|
hauptkiste.setLayout(new OverlayLayout(hauptkiste));
|
||||||
|
hauptkiste.setBackground(hintergrund);
|
||||||
|
hauptkiste.add(flpflanzen);
|
||||||
|
hauptkiste.add(flbeet);
|
||||||
|
hauptkiste.add(flweg);
|
||||||
|
|
||||||
|
Gaertner ga = new Gaertner(view,flbeet,flweg,flpflanzen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param args the command line arguments
|
||||||
|
*/
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
new start();
|
||||||
|
}
|
||||||
|
}
|
71
Garten/src/garten/view/Fenster.java
Normal file
71
Garten/src/garten/view/Fenster.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* 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.view;
|
||||||
|
|
||||||
|
import java.awt.BasicStroke;
|
||||||
|
import java.awt.Container;
|
||||||
|
import java.awt.geom.Line2D;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.OverlayLayout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author nobody
|
||||||
|
*/
|
||||||
|
public class Fenster extends JFrame
|
||||||
|
{
|
||||||
|
private Line2D.Float Gerade;
|
||||||
|
private BasicStroke pinsel;
|
||||||
|
private static final float DICKE = 2f;
|
||||||
|
private JButton btnnl;
|
||||||
|
private JButton btnnr;
|
||||||
|
public Fenster()
|
||||||
|
{
|
||||||
|
pinsel = new BasicStroke(DICKE);
|
||||||
|
Gerade = new Line2D.Float();
|
||||||
|
btnnl = new JButton(" > ");
|
||||||
|
btnnr = new JButton(" < ");
|
||||||
|
|
||||||
|
Container hauptkiste = this.getContentPane();
|
||||||
|
hauptkiste.setLayout(new OverlayLayout(hauptkiste));
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
JPopupMenu popup = new JPopupMenu();
|
||||||
|
JMenuItem menuItem = new JMenuItem("Hallo");
|
||||||
|
JRadioButtonMenuItem radioButtonItem = new JRadioButtonMenuItem("Ich bin ein JRadionButtonMenuItem",true);
|
||||||
|
popup.add(menuItem);
|
||||||
|
popup.add(radioButtonItem);
|
||||||
|
popup.setLocation(200,200);
|
||||||
|
popup.setVisible(true);
|
||||||
|
hauptkiste.add(popup);
|
||||||
|
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
|
||||||
|
popup.setVisible(true);
|
||||||
|
*/
|
||||||
|
this.setTitle("Garten von Paul und Jan");
|
||||||
|
this.pack();
|
||||||
|
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
|
this.setSize(900, 900);
|
||||||
|
this.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paintComponent()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||||
|
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
|
||||||
|
|
||||||
|
Gerade.setLine(200, 200, 400, 400);
|
||||||
|
g2.setStroke(pinsel);
|
||||||
|
g2.setPaint(Color.BLACK);
|
||||||
|
//g2.draw(Kreis);
|
||||||
|
g2.draw(Gerade);
|
||||||
|
this.repaint();
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
51
Garten/src/garten/view/FlaecheBeet.java
Normal file
51
Garten/src/garten/view/FlaecheBeet.java
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* 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.view;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jan
|
||||||
|
*/
|
||||||
|
public class FlaecheBeet extends JPanel
|
||||||
|
{
|
||||||
|
int[] randomwertex;
|
||||||
|
int[] randomwertey;
|
||||||
|
|
||||||
|
Color colorBeet;
|
||||||
|
|
||||||
|
public FlaecheBeet()
|
||||||
|
{
|
||||||
|
randomwertex = new int[4];
|
||||||
|
randomwertey = new int[4];
|
||||||
|
colorBeet = new Color(153, 102, 51);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paintComponent(Graphics g)
|
||||||
|
{
|
||||||
|
super.paintComponent(g);
|
||||||
|
g.setColor(colorBeet);
|
||||||
|
|
||||||
|
for (int i = 0; i < randomwertex.length - 1; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < randomwertey.length - 1; j++)
|
||||||
|
{
|
||||||
|
g.fillRect(randomwertex[i] + 10, randomwertey[j] + 10, randomwertex[i + 1] - randomwertex[i] - 20, randomwertey[j + 1] - randomwertey[j] - 20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBeet(int[] x, int[] y)
|
||||||
|
{
|
||||||
|
randomwertex = x;
|
||||||
|
randomwertey = y;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
}
|
64
Garten/src/garten/view/FlaechePflanzen.java
Normal file
64
Garten/src/garten/view/FlaechePflanzen.java
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* 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.view;
|
||||||
|
|
||||||
|
import garten.model.Pflanze;
|
||||||
|
import java.awt.BasicStroke;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.geom.Line2D;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jan
|
||||||
|
*/
|
||||||
|
public class FlaechePflanzen extends JPanel
|
||||||
|
{
|
||||||
|
ArrayList<Pflanze> pflanzen = new ArrayList<>();
|
||||||
|
Color colorPflanzen;
|
||||||
|
private Line2D.Float Gerade;
|
||||||
|
private BasicStroke pinsel;
|
||||||
|
public FlaechePflanzen()
|
||||||
|
{
|
||||||
|
colorPflanzen = new Color(50, 205, 50);
|
||||||
|
pflanzen = new ArrayList<>();
|
||||||
|
Gerade = new Line2D.Float();
|
||||||
|
pinsel = new BasicStroke(1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paintComponent(Graphics g)
|
||||||
|
{
|
||||||
|
|
||||||
|
super.paintComponent(g);
|
||||||
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
|
|
||||||
|
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||||
|
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
|
||||||
|
g.setColor(colorPflanzen);
|
||||||
|
|
||||||
|
System.out.println(pflanzen);
|
||||||
|
for(Pflanze p : pflanzen)
|
||||||
|
{
|
||||||
|
ArrayList<float[]> pts = p.getPoints();
|
||||||
|
System.out.println("Return points" + pts);
|
||||||
|
for(float[] pt : pts)
|
||||||
|
{
|
||||||
|
Gerade.setLine(pt[0], pt[1], pt[2], pt[3]);
|
||||||
|
g2.draw(Gerade);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void setPflanzen(ArrayList<Pflanze> temppflanzen)
|
||||||
|
{
|
||||||
|
pflanzen.addAll(0, temppflanzen);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
}
|
53
Garten/src/garten/view/FlaecheWeg.java
Normal file
53
Garten/src/garten/view/FlaecheWeg.java
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* 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.view;
|
||||||
|
|
||||||
|
import java.awt.BasicStroke;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jan
|
||||||
|
*/
|
||||||
|
public class FlaecheWeg extends JPanel
|
||||||
|
{
|
||||||
|
int[] randomwertex;
|
||||||
|
int[] randomwertey;
|
||||||
|
private BasicStroke pinsel;
|
||||||
|
Color colorWeg;
|
||||||
|
|
||||||
|
public FlaecheWeg()
|
||||||
|
{
|
||||||
|
randomwertex = new int[4];
|
||||||
|
randomwertey = new int[4];
|
||||||
|
pinsel = new BasicStroke(6f);
|
||||||
|
colorWeg = new Color(190, 190, 190);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paintComponent(Graphics g)
|
||||||
|
{
|
||||||
|
super.paintComponent(g);
|
||||||
|
|
||||||
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
|
g2.setColor(colorWeg);
|
||||||
|
g2.setStroke(pinsel);
|
||||||
|
for (int i = 0; i < randomwertex.length; i++)
|
||||||
|
{
|
||||||
|
g2.drawLine(randomwertex[i], randomwertey[0], randomwertex[i], randomwertey[3]);
|
||||||
|
g2.drawLine(randomwertex[0], randomwertey[i], randomwertex[3], randomwertey[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWeg(int[] x, int[] y)
|
||||||
|
{
|
||||||
|
randomwertex = x;
|
||||||
|
randomwertey = y;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user