generation infinie de ligne
This commit is contained in:
@@ -9,7 +9,6 @@ import java.util.ArrayList;
|
||||
public class Ligne extends ObjetGraphique {
|
||||
|
||||
protected int nbSegments = 400;
|
||||
protected double xCercle = 400;
|
||||
protected Segment SegCourant;
|
||||
|
||||
protected ArrayList<Segment> listeSegments = new ArrayList<Segment>();
|
||||
@@ -17,34 +16,61 @@ public class Ligne extends ObjetGraphique {
|
||||
protected double limiteHaut = 50;
|
||||
protected double limiteBas = 550;
|
||||
|
||||
protected Segment dernierSegment;
|
||||
private double decalageXDernierSegment = 0;
|
||||
|
||||
protected double noiseFrequence = 1/50f;
|
||||
|
||||
private NoiseGenerator noiseGenerator;
|
||||
|
||||
private double xActuel;
|
||||
|
||||
public Ligne(NoiseGenerator noiseGenerator) {
|
||||
double x = 0;
|
||||
double y = 200;
|
||||
double dx, dy;
|
||||
|
||||
Segment s;
|
||||
this.noiseGenerator = noiseGenerator;
|
||||
for (int i = 0; i < nbSegments; i++) {
|
||||
dx = 10;
|
||||
|
||||
dy = noiseGenerator.noise(x / 15) * 8;
|
||||
|
||||
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));
|
||||
Segment s = CreerSegment(x);
|
||||
|
||||
listeSegments.add(s);
|
||||
|
||||
x += dx;
|
||||
y += dy;
|
||||
if (i == nbSegments - 1)
|
||||
{
|
||||
dernierSegment = s;
|
||||
xActuel = x + s.xLong;
|
||||
}
|
||||
|
||||
x += s.xLong;
|
||||
}
|
||||
}
|
||||
|
||||
protected double GetLargeurSegment(){
|
||||
return (double)ZoneDessin.largeur / nbSegments;
|
||||
}
|
||||
|
||||
protected Segment CreerSegment(double x){
|
||||
double dx = GetLargeurSegment();
|
||||
double y = CalculerY(x);
|
||||
double dy = CalculerY(x + dx) - y;
|
||||
|
||||
Segment s = new Segment(x, y, dx, dy);
|
||||
|
||||
s.setCouleur(new Color(0.2f, 0.2f, 0.2f));
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
protected double CalculerY(double x){
|
||||
|
||||
double hauteur = limiteBas - limiteHaut;
|
||||
|
||||
double bruit = noiseGenerator.noise(x * noiseFrequence);
|
||||
bruit = (bruit + 1) / 2;
|
||||
|
||||
return limiteBas - bruit * hauteur;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Afficher(Graphics g) {
|
||||
Graphics2D g2D = (Graphics2D) g;
|
||||
@@ -53,12 +79,12 @@ public class Ligne extends ObjetGraphique {
|
||||
for (Segment s : listeSegments) {
|
||||
s.Afficher(g);
|
||||
if (SegCourant == null) {
|
||||
if (xCercle <= s.x + s.xLong && xCercle >= s.x) {
|
||||
if (Cercle.xCercle <= s.x + s.xLong && Cercle.xCercle >= s.x) {
|
||||
SegCourant = s;
|
||||
}
|
||||
} else {
|
||||
if ((SegCourant.x + SegCourant.xLong) < xCercle) {
|
||||
if (s.x <= xCercle && (s.x + s.xLong) >= xCercle) {
|
||||
if ((SegCourant.x + SegCourant.xLong) < Cercle.xCercle) {
|
||||
if (s.x <= Cercle.xCercle && (s.x + s.xLong) >= Cercle.xCercle) {
|
||||
SegCourant = s;
|
||||
}
|
||||
}
|
||||
@@ -72,6 +98,26 @@ public class Ligne extends ObjetGraphique {
|
||||
s.Animer();
|
||||
s.x -= 10;
|
||||
}
|
||||
|
||||
UpdateSegments();
|
||||
}
|
||||
|
||||
private void UpdateSegments(){
|
||||
|
||||
if (dernierSegment == null) throw new RuntimeException("dernierSegment n'existe pas");
|
||||
|
||||
for (int i = 0; i < listeSegments.size(); i++) {
|
||||
|
||||
Segment s = listeSegments.get(i);
|
||||
if (s.x + s.xLong < 0) {
|
||||
Segment nouveauSegment = CreerSegment(xActuel);
|
||||
nouveauSegment.x = dernierSegment.x + dernierSegment.xLong;
|
||||
listeSegments.set(i, nouveauSegment);
|
||||
|
||||
xActuel += GetLargeurSegment();
|
||||
dernierSegment = nouveauSegment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double GetHauteurPointCercle(){
|
||||
|
||||
Reference in New Issue
Block a user