This commit is contained in:
2023-10-23 13:23:36 +02:00
parent 667dae6f1a
commit 322b22f9bf
5711 changed files with 72953 additions and 0 deletions

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;
}
}

View File

@@ -0,0 +1,27 @@
import javax.swing.JComponent;
import java.awt.*;
public class Graphe extends JComponent {
public ProducteurDePoints graphe;
public Graphe(ProducteurDePoints graphe){
this.graphe = graphe;
}
@Override
protected void paintComponent(Graphics pinceau) {
Graphics secondPinceau = pinceau.create();
if (this.isOpaque()) {
secondPinceau.setColor(this.getBackground());
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
}
secondPinceau.setColor(Color.BLACK);
Point point1 = this.graphe.suivant();
Point point2 = this.graphe.suivant();
while (point2 != null){
secondPinceau.drawLine(point1.x, point1.y, point2.x, point2.y);
point1 = point2;
point2 = this.graphe.suivant();
}
}
}

View File

@@ -0,0 +1,23 @@
import java.awt.Point;
import java.util.*;
public class LigneAleatoire implements ProducteurDePoints {
private int numero;
public LigneAleatoire() {
this.numero = 0;
}
public Point suivant() {
Point p = null;
if (this.numero < 10) {
p = new Point(((int) (Math.random()*200)+50),
((int) (Math.random()*200)+50));
this.numero++;
} else {
this.numero = 0;
}
System.out.println(p);
return p;
}
}

View File

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

View File

@@ -0,0 +1,18 @@
import javax.swing.*;
import java.awt.*;
public class Q3Main{
public static void main(String[] args){
JFrame fenetre = new JFrame();
fenetre.setSize(500, 300);
fenetre.setLocation(0, 0);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ProducteurDePoints producteur = new LigneAleatoire();
//ProducteurDePoints producteur = new Etoile();
Graphe dessin = new Graphe(producteur);
fenetre.add(dessin);
fenetre.setVisible(true);
}
}

View File

@@ -0,0 +1,17 @@
import javax.swing.*;
import java.awt.*;
public class Q3Main{
public static void main(String[] args){
JFrame fenetre = new JFrame();
fenetre.setSize(500, 300);
fenetre.setLocation(0, 0);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ProducteurDePoints producteurEtoile = new Etoile();
Graphe dessinEtoile = new Graphe(producteurEtoile);
fenetre.add(dessinEtoile);
fenetre.setVisible(true);
}
}