prototype
This commit is contained in:
57
linea/Ligne.java
Normal file
57
linea/Ligne.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package linea;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Ligne extends ObjetGraphique{
|
||||
|
||||
private int nbSegments = 400;
|
||||
private double xCercle = 400;
|
||||
private Segment SegCourant;
|
||||
|
||||
// liste des segments
|
||||
private ArrayList<Segment> segments = new ArrayList<Segment>();
|
||||
|
||||
public Ligne(){
|
||||
double x = 800;
|
||||
double y = 300;
|
||||
double dx,dy;
|
||||
|
||||
Segment s;
|
||||
for (int i=0; i<nbSegments; i++){
|
||||
dx = Math.random()*20+80;
|
||||
dy = Math.random()*40-20;
|
||||
s = new Segment(x,y,dx,dy);
|
||||
s.setCouleur(new Color(0.2f,0.2f,0.2f));
|
||||
|
||||
segments.add(s);
|
||||
|
||||
x+=dx;
|
||||
y+=dy;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Afficher(Graphics g){
|
||||
Graphics2D g2D = (Graphics2D) g;
|
||||
g2D.setStroke(new BasicStroke(3.0f));
|
||||
|
||||
for (Segment seg : segments) {
|
||||
seg.Afficher(g);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Animer() {
|
||||
// déplace tous les segments vers la gauche
|
||||
double delta = 5.0; // vitesse de déplacement
|
||||
for (Segment seg : segments) {
|
||||
seg.x -= delta;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user