Compare commits
2 Commits
029fcc3b74
...
8c90b46b1a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c90b46b1a | ||
|
|
74b214e89c |
@@ -21,14 +21,16 @@ public class Cercle extends ObjetGraphique { // il s'agit plutôt d'arcs de cerc
|
||||
protected double pas = 0.2;
|
||||
protected double impulsion = 35;
|
||||
|
||||
public static int xCercle = 400;
|
||||
|
||||
public Cercle() {
|
||||
x = 400;
|
||||
y = 200;
|
||||
x = xCercle;
|
||||
y = (double)ZoneDessin.hauteur / 2;
|
||||
}
|
||||
|
||||
public Cercle(double debutArc, double finArc) {
|
||||
x = 400;
|
||||
y = 200;
|
||||
x = xCercle;
|
||||
y = (double)ZoneDessin.hauteur / 2;
|
||||
debut = debutArc;
|
||||
fin = finArc;
|
||||
}
|
||||
|
||||
@@ -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,32 +16,59 @@ 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
|
||||
@@ -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(){
|
||||
|
||||
@@ -18,9 +18,12 @@ public class ZoneDessin extends JPanel {
|
||||
|
||||
protected boolean estArrete = false;
|
||||
|
||||
public static int largeur = 800;
|
||||
public static int hauteur = 600;
|
||||
|
||||
public ZoneDessin() {
|
||||
setLayout(new BorderLayout());
|
||||
setPreferredSize(new Dimension(800, 600));
|
||||
setPreferredSize(new Dimension(largeur, hauteur));
|
||||
setBackground(new Color(0, 73, 220));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user