flocon
This commit is contained in:
BIN
DEV3.2/TP02/05_Flocon/Fenetre.class
Normal file
BIN
DEV3.2/TP02/05_Flocon/Fenetre.class
Normal file
Binary file not shown.
BIN
DEV3.2/TP02/05_Flocon/JFlocon.class
Normal file
BIN
DEV3.2/TP02/05_Flocon/JFlocon.class
Normal file
Binary file not shown.
@@ -1,12 +1,17 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
public class JFlocon extends JComponent {
|
public class JFlocon extends JComponent {
|
||||||
|
|
||||||
private int ordre;
|
private int ordre;
|
||||||
|
private ArrayList<Point> points;
|
||||||
|
private int[] coordX;
|
||||||
|
private int[] coordY;
|
||||||
|
|
||||||
public JFlocon(int ordre) {
|
public JFlocon(int ordre) {
|
||||||
this.ordre = ordre;
|
this.ordre = ordre;
|
||||||
|
this.points = new ArrayList<Point>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -14,10 +19,66 @@ public class JFlocon extends JComponent {
|
|||||||
Graphics secondPinceau = pinceau.create();
|
Graphics secondPinceau = pinceau.create();
|
||||||
|
|
||||||
if (this.isOpaque()) {
|
if (this.isOpaque()) {
|
||||||
this.setColor(this.getBackgroundColor());
|
secondPinceau.setColor(this.getBackground());
|
||||||
this.fillRect(0, 0, this.getWidth(), this.getHeight());
|
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
secondPinceau.setColor(Color.BLUE);
|
||||||
|
this.calculCoordonnees();
|
||||||
|
|
||||||
|
int[] coordX = new int[this.points.size()];
|
||||||
|
int[] coordY = new int[this.points.size()];
|
||||||
|
|
||||||
|
for (int i = 0; i != this.points.size(); i++) {
|
||||||
|
coordX[i] = points.get(i).x;
|
||||||
|
coordY[i] = points.get(i).y;
|
||||||
|
}
|
||||||
|
|
||||||
|
Polygon p = new Polygon(coordX, coordY, this.points.size());
|
||||||
|
|
||||||
|
secondPinceau.drawPolygon(p);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void calculCoordonnees() {
|
||||||
|
Point a = new Point(this.getWidth()/4, this.getHeight()/4);
|
||||||
|
Point b = new Point(this.getWidth()/4*3, this.getHeight()/4);
|
||||||
|
Point c = new Point(
|
||||||
|
this.getWidth()/2,
|
||||||
|
this.getHeight()/4*3
|
||||||
|
);
|
||||||
|
segment(a, b, this.ordre);
|
||||||
|
segment(b, c, this.ordre);
|
||||||
|
segment(c, a, this.ordre);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void segment(Point debut, Point fin, int ordre) {
|
||||||
|
if (ordre == 0) {
|
||||||
|
this.points.add(debut);
|
||||||
|
this.points.add(fin);
|
||||||
|
} else {
|
||||||
|
Point p2 = new Point(
|
||||||
|
(2 * debut.x + fin.x) / 3,
|
||||||
|
(2 * debut.y + fin.y) / 3
|
||||||
|
);
|
||||||
|
|
||||||
|
Point p3 = new Point(
|
||||||
|
(debut.x + fin.x) / 2 - (int) (Math.sqrt(3) * (debut.y - fin.y) / 6),
|
||||||
|
(debut.y + fin.y) / 2 - (int) (Math.sqrt(3) * (fin.x - debut.x) / 6)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Point p4 = new Point(
|
||||||
|
(debut.x + 2 * fin.x) / 3,
|
||||||
|
(debut.y + 2 * fin.y) / 3
|
||||||
|
);
|
||||||
|
|
||||||
|
segment(debut, p2, ordre-1);
|
||||||
|
segment(p2, p3, ordre-1);
|
||||||
|
segment(p3, p4, ordre-1);
|
||||||
|
segment(p4, fin, ordre-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
BIN
DEV3.2/TP02/05_Flocon/Main.class
Normal file
BIN
DEV3.2/TP02/05_Flocon/Main.class
Normal file
Binary file not shown.
Reference in New Issue
Block a user