diff --git a/DEV3.2/TP02/05_Flocon/Fenetre.class b/DEV3.2/TP02/05_Flocon/Fenetre.class new file mode 100644 index 0000000..2c99afa Binary files /dev/null and b/DEV3.2/TP02/05_Flocon/Fenetre.class differ diff --git a/DEV3.2/TP02/05_Flocon/JFlocon.class b/DEV3.2/TP02/05_Flocon/JFlocon.class new file mode 100644 index 0000000..12913be Binary files /dev/null and b/DEV3.2/TP02/05_Flocon/JFlocon.class differ diff --git a/DEV3.2/TP02/05_Flocon/JFlocon.java b/DEV3.2/TP02/05_Flocon/JFlocon.java index a4f6e3d..b1d7fc6 100644 --- a/DEV3.2/TP02/05_Flocon/JFlocon.java +++ b/DEV3.2/TP02/05_Flocon/JFlocon.java @@ -1,12 +1,17 @@ import java.awt.*; +import java.util.ArrayList; import javax.swing.*; public class JFlocon extends JComponent { private int ordre; + private ArrayList points; + private int[] coordX; + private int[] coordY; public JFlocon(int ordre) { this.ordre = ordre; + this.points = new ArrayList(); } @Override @@ -14,10 +19,66 @@ public class JFlocon extends JComponent { Graphics secondPinceau = pinceau.create(); if (this.isOpaque()) { - this.setColor(this.getBackgroundColor()); - this.fillRect(0, 0, this.getWidth(), this.getHeight()); + secondPinceau.setColor(this.getBackground()); + 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); + } + } } \ No newline at end of file diff --git a/DEV3.2/TP02/05_Flocon/Main.class b/DEV3.2/TP02/05_Flocon/Main.class new file mode 100644 index 0000000..717bdfa Binary files /dev/null and b/DEV3.2/TP02/05_Flocon/Main.class differ