This commit is contained in:
2024-03-18 13:54:22 +01:00
parent eb581c8a31
commit a28bef01d7
69 changed files with 855 additions and 5 deletions

Binary file not shown.

View File

@@ -0,0 +1,26 @@
import java.awt.Point;
public class Etoile implements ProducteurDePoints {
private static final int xCentre = 100;
private static final int yCentre = 100;
private static final double rayon = 90.0;
private static final double angleDepart = Math.PI/4.0;
private static final double angleIncrement = (4.0*Math.PI)/5.0;
private double numero;
public Etoile() {
this.numero = 0.0;
}
public Point suivant() {
Point p = null;
if (this.numero < 6.0) {
double angle = Etoile.angleDepart+this.numero*Etoile.angleIncrement;
p = new Point((int) (Etoile.rayon*Math.cos(angle)),
(int) (Etoile.rayon*Math.sin(angle)));
p.translate(Etoile.xCentre, Etoile.yCentre);
this.numero++;
} else {
this.numero = 0.0;
}
return p;
}
}

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,44 @@
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
public class Polyligne extends JFrame {
private ProducteurDePoints producteurDePoints;
public Polyligne(ProducteurDePoints producteurDePoints) {
this.producteurDePoints = producteurDePoints;
setTitle("Polyligne");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 300);
setLocationRelativeTo(null);
JPanel panel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLACK);
Point dernierPoint = null;
Point pointActuel = producteurDePoints.suivant();
while (pointActuel != null) {
if (dernierPoint != null) {
g2d.draw(new Line2D.Double(dernierPoint, pointActuel));
}
dernierPoint = pointActuel;
pointActuel = producteurDePoints.suivant();
}
}
};
add(panel);
setVisible(true);
}
public static void main(String[] args) {
ProducteurDePoints producteur = new Etoile(); // Changez ici pour utiliser votre propre fournisseur
new Polyligne(producteur);
}
}

Binary file not shown.

View File

@@ -0,0 +1,5 @@
import java.awt.Point;
public interface ProducteurDePoints {
Point suivant();
}