update
This commit is contained in:
Binary file not shown.
@@ -2,23 +2,29 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.Polygon;
|
||||
import java.lang.Math;
|
||||
|
||||
public class Q5Main{
|
||||
public static void main(String[] args) {
|
||||
|
||||
int l = 1000;
|
||||
int m = 40;
|
||||
int detail = Integer.parseInt(args[0]);
|
||||
JFrame fenetre = new JFrame("Q1 Galerie");
|
||||
fenetre.setSize(300, 200);
|
||||
fenetre.setLocation(700, 300);
|
||||
fenetre.setSize(l+2*m, l+2*m);
|
||||
fenetre.setLocation(0, 0);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
Polygon etoile = new Polygon();
|
||||
etoile.addPoint(50,50);
|
||||
etoile.addPoint(300,140);
|
||||
etoile.addPoint(230,80);
|
||||
etoile.addPoint(10,330);
|
||||
fenetre.setVisible(true);
|
||||
|
||||
Q5Polygon dessinEtoile = new Q5Polygon(etoile);
|
||||
Q5Recursivite modele = new Q5Recursivite(etoile, fenetre);
|
||||
fenetre.add(dessinEtoile);
|
||||
fenetre.setVisible(true);
|
||||
|
||||
Q5Point g = new Q5Point(m+l/2, m);
|
||||
Q5Point c = new Q5Point(m+l-((int)(l*Math.sqrt(3))/2), m+(3*l)/4);
|
||||
Q5Point a = new Q5Point(2*m+((int)(l*Math.sqrt(3))/2), m+(3*l)/4);
|
||||
modele.nextStep(detail, a,c,g);
|
||||
modele.nextStep(detail, c,g,a);
|
||||
modele.nextStep(detail, g,a,c);
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV3.2/TP02_Recursivite/Q5Point.class
Normal file
BIN
DEV/DEV3.2/TP02_Recursivite/Q5Point.class
Normal file
Binary file not shown.
33
DEV/DEV3.2/TP02_Recursivite/Q5Point.java
Normal file
33
DEV/DEV3.2/TP02_Recursivite/Q5Point.java
Normal file
@@ -0,0 +1,33 @@
|
||||
public class Q5Point{
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
public Q5Point(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
public Q5Point() {
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
}
|
||||
|
||||
public static Q5Point tiers(Q5Point a, Q5Point b){
|
||||
Q5Point resultat = new Q5Point();
|
||||
resultat.x = (int) a.x + (b.x - a.x)/3;
|
||||
resultat.y = (int) a.y + (b.y - a.y)/3;
|
||||
return resultat;
|
||||
}
|
||||
public static Q5Point millieu(Q5Point a, Q5Point b){
|
||||
Q5Point resultat = new Q5Point();
|
||||
resultat.x = (int) a.x + (b.x - a.x)/2;
|
||||
resultat.y = (int) a.y + (b.y - a.y)/2;
|
||||
return resultat;
|
||||
}
|
||||
public static Q5Point pointe(Q5Point a, Q5Point b, Q5Point p){
|
||||
Q5Point i = Q5Point.millieu(a,b);
|
||||
Q5Point resultat = new Q5Point();
|
||||
resultat.x = (int) i.x - (p.x - i.x)/3;
|
||||
resultat.y = (int) i.y - (p.y - i.y)/3;
|
||||
return resultat;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -11,6 +11,6 @@ public class Q5Polygon extends JComponent {
|
||||
@Override
|
||||
protected void paintComponent(Graphics pinceau) {
|
||||
pinceau.setColor(Color.BLUE);
|
||||
pinceau.fillPolygon(this.etoile);
|
||||
pinceau.drawPolygon(this.etoile);
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV3.2/TP02_Recursivite/Q5Recursivite.class
Normal file
BIN
DEV/DEV3.2/TP02_Recursivite/Q5Recursivite.class
Normal file
Binary file not shown.
32
DEV/DEV3.2/TP02_Recursivite/Q5Recursivite.java
Normal file
32
DEV/DEV3.2/TP02_Recursivite/Q5Recursivite.java
Normal file
@@ -0,0 +1,32 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.Polygon;
|
||||
|
||||
public class Q5Recursivite{
|
||||
public Polygon etoile;
|
||||
public JFrame fenetre;
|
||||
|
||||
public Q5Recursivite(Polygon etoile, JFrame fenetre) {
|
||||
this.etoile = etoile;
|
||||
this.fenetre = fenetre;
|
||||
}
|
||||
public void nextStep(int i, Q5Point c, Q5Point g, Q5Point a){
|
||||
if (i<=0){
|
||||
this.etoile.addPoint(c.x,c.y);
|
||||
this.fenetre.repaint();
|
||||
}
|
||||
else{
|
||||
Q5Point b = Q5Point.tiers(c,a);
|
||||
Q5Point d = Q5Point.tiers(c,g);
|
||||
Q5Point e = Q5Point.pointe(c,g,a);
|
||||
Q5Point f = Q5Point.tiers(g,c);
|
||||
Q5Point h = Q5Point.tiers(g,a);
|
||||
this.nextStep(i-1, c, d, b);
|
||||
this.nextStep(i-1, d, e, f);
|
||||
this.nextStep(i-1, e, f, d);
|
||||
this.nextStep(i-1, f, g, h);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user