2026-02-02 11:40:03 +01:00
|
|
|
package linea;
|
2026-02-02 11:19:18 +01:00
|
|
|
|
|
|
|
|
import java.awt.BasicStroke;
|
|
|
|
|
import java.awt.Color;
|
|
|
|
|
import java.awt.Graphics;
|
|
|
|
|
import java.awt.Graphics2D;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
2026-02-10 15:48:46 +01:00
|
|
|
public class Ligne extends ObjetGraphique {
|
2026-02-02 11:19:18 +01:00
|
|
|
|
|
|
|
|
protected int nbSegments = 400;
|
2026-02-10 15:48:46 +01:00
|
|
|
protected double xCercle = 400;
|
2026-02-02 11:19:18 +01:00
|
|
|
protected Segment SegCourant;
|
2026-02-10 15:48:46 +01:00
|
|
|
|
|
|
|
|
protected ArrayList<Segment> listeSegments = new ArrayList<Segment>();
|
|
|
|
|
|
2026-02-23 08:57:26 +01:00
|
|
|
protected double limiteHaut = 50;
|
|
|
|
|
protected double limiteBas = 550;
|
|
|
|
|
|
|
|
|
|
public Ligne() {
|
2026-02-10 16:24:44 +01:00
|
|
|
double x = 0;
|
2026-02-02 11:19:18 +01:00
|
|
|
double y = 200;
|
2026-02-23 08:57:26 +01:00
|
|
|
double dx, dy;
|
2026-02-10 15:48:46 +01:00
|
|
|
|
2026-02-02 11:19:18 +01:00
|
|
|
Segment s;
|
2026-02-23 08:57:26 +01:00
|
|
|
for (int i = 0; i < nbSegments; i++) {
|
|
|
|
|
dx = Math.random() * 20 + 80;
|
|
|
|
|
dy = Math.random() * 40 - 20;
|
|
|
|
|
|
|
|
|
|
if (y + dy > limiteBas) {
|
|
|
|
|
dy = limiteBas - y;
|
|
|
|
|
}
|
|
|
|
|
if (y + dy < limiteHaut) {
|
|
|
|
|
dy = limiteHaut - y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s = new Segment(x, y, dx, dy);
|
|
|
|
|
s.setCouleur(new Color(0.2f, 0.2f, 0.2f));
|
2026-02-10 15:48:46 +01:00
|
|
|
|
|
|
|
|
listeSegments.add(s);
|
|
|
|
|
|
2026-02-23 08:57:26 +01:00
|
|
|
x += dx;
|
|
|
|
|
y += dy;
|
2026-02-02 11:19:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2026-02-23 08:57:26 +01:00
|
|
|
public void Afficher(Graphics g) {
|
2026-02-02 11:19:18 +01:00
|
|
|
Graphics2D g2D = (Graphics2D) g;
|
|
|
|
|
g2D.setStroke(new BasicStroke(3.0f));
|
2026-02-10 15:48:46 +01:00
|
|
|
|
2026-02-23 08:57:26 +01:00
|
|
|
for (Segment s : listeSegments) {
|
2026-02-10 15:48:46 +01:00
|
|
|
s.Afficher(g);
|
2026-02-23 08:57:26 +01:00
|
|
|
if (SegCourant == null) {
|
|
|
|
|
if (xCercle < s.x + s.xLong && xCercle > s.x) {
|
|
|
|
|
SegCourant = s;
|
2026-02-10 16:24:44 +01:00
|
|
|
}
|
2026-02-23 08:57:26 +01:00
|
|
|
} else {
|
|
|
|
|
if ((SegCourant.x + SegCourant.xLong) < xCercle) {
|
|
|
|
|
if (s.x <= xCercle && (s.xLong) >= xCercle) {
|
|
|
|
|
SegCourant = s;
|
2026-02-10 16:24:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-10 15:48:46 +01:00
|
|
|
}
|
2026-02-02 11:19:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void Animer() {
|
2026-02-23 08:57:26 +01:00
|
|
|
for (Segment s : listeSegments) {
|
2026-02-10 15:48:46 +01:00
|
|
|
s.Animer();
|
2026-02-10 16:24:44 +01:00
|
|
|
s.x -= 10;
|
2026-02-10 15:48:46 +01:00
|
|
|
}
|
2026-02-02 11:19:18 +01:00
|
|
|
}
|
2026-02-10 15:48:46 +01:00
|
|
|
}
|