plus de probleme de la ligne qui sort de l'écran

This commit is contained in:
tit-exe
2026-02-23 08:57:26 +01:00
parent 28b64db07a
commit d8a93def31
2 changed files with 30 additions and 20 deletions

View File

@@ -14,41 +14,51 @@ public class Ligne extends ObjetGraphique {
protected ArrayList<Segment> listeSegments = new ArrayList<Segment>(); protected ArrayList<Segment> listeSegments = new ArrayList<Segment>();
public Ligne(){ protected double limiteHaut = 50;
protected double limiteBas = 550;
public Ligne() {
double x = 0; double x = 0;
double y = 200; double y = 200;
double dx,dy; double dx, dy;
Segment s; Segment s;
for (int i=0; i<nbSegments; i++){ for (int i = 0; i < nbSegments; i++) {
dx = Math.random()*20+80; dx = Math.random() * 20 + 80;
dy = Math.random()*40-20; dy = Math.random() * 40 - 20;
s = new Segment(x,y,dx,dy);
s.setCouleur(new Color(0.2f,0.2f,0.2f)); 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));
listeSegments.add(s); listeSegments.add(s);
x+=dx; x += dx;
y+=dy; y += dy;
} }
} }
@Override @Override
public void Afficher(Graphics g){ public void Afficher(Graphics g) {
Graphics2D g2D = (Graphics2D) g; Graphics2D g2D = (Graphics2D) g;
g2D.setStroke(new BasicStroke(3.0f)); g2D.setStroke(new BasicStroke(3.0f));
for(Segment s : listeSegments) { for (Segment s : listeSegments) {
s.Afficher(g); s.Afficher(g);
if(SegCourant==null){ if (SegCourant == null) {
if(xCercle<s.x + s.xLong && xCercle>s.x){ if (xCercle < s.x + s.xLong && xCercle > s.x) {
SegCourant=s; SegCourant = s;
} }
} } else {
else{ if ((SegCourant.x + SegCourant.xLong) < xCercle) {
if((SegCourant.x + SegCourant.xLong)<xCercle){ if (s.x <= xCercle && (s.xLong) >= xCercle) {
if(s.x<=xCercle && (s.xLong)>=xCercle){ SegCourant = s;
SegCourant=s;
} }
} }
} }
@@ -57,7 +67,7 @@ public class Ligne extends ObjetGraphique {
@Override @Override
public void Animer() { public void Animer() {
for(Segment s : listeSegments) { for (Segment s : listeSegments) {
s.Animer(); s.Animer();
s.x -= 10; s.x -= 10;
} }