Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
.
[graphlib.git] / chateaux / chateaux.cpp
index 16f10e2..875fa4b 100644 (file)
@@ -22,6 +22,8 @@ const float hauteurMax = 130;
 const float largeurMin = 40;
 const float largeurMax = 150;
 
+const float ventMax = 30;
+
 const float largeurChateau = 8.5;
 const float hauteurChateau = 7;
 
@@ -40,8 +42,8 @@ float largeurMont;
 float hauteurMont;
 float wnd;
 
-/* Retourne un nombre pseudo-aléatoire compris entre 0 et le paramètre
- * 'max' (exclus)
+/* Retourne un nombre pseudo-aléatoire compris entre le paramètre
+ * 'min' (inclus) et le paramètre 'max' (exclus)
  */
 float frand(float min, float max)
 {
@@ -61,23 +63,23 @@ float deg2rad(float deg)
 // conversion coordonnées réelles -> coordonnées fenêtre
 int rtowX(const DrawingWindow& w, float rx)
 {
-    return (int )roundf(w.width * (rx - rXMin) / (rXMax - rXMin + 1.0));
+    return (int )roundf((w.width - 1) * (rx - rXMin) / (rXMax - rXMin));
 }
 
 int rtowY(const DrawingWindow& w, float ry)
 {
-    return (int )roundf(w.height * (rYMax - ry) / (rYMax - rYMin + 1.0));
+    return (int )roundf((w.height - 1) * (rYMax - ry) / (rYMax - rYMin));
 }
 
-// conversion coordonnées réelles -> coordonnées fenêtre
+// conversion coordonnées fenêtre -> coordonnées réelles
 float wtorX(const DrawingWindow& w, int wx)
 {
-    return (rXMax - rXMin + 1.0) * wx / w.width + rXMin;
+    return (rXMax - rXMin) * wx / (w.width - 1) + rXMin;
 }
 
 float wtorY(const DrawingWindow& w, int wy)
 {
-    return -(rYMax - rYMin + 1.0) * wy / w.height - rYMax;
+    return -(rYMax - rYMin) * wy / (w.height - 1) + rYMax;
 }
 
 float hauteurMontagne(float largeur, float hauteur, float x)
@@ -202,7 +204,7 @@ void initialise(DrawingWindow& w)
 {
     largeurMont = frand(largeurMin, largeurMax);
     hauteurMont = frand(hauteurMin, hauteurMax);
-    wnd = frand(-30, 30);
+    wnd = frand(-ventMax, ventMax);
     w.setBgColor("skyblue");
     w.clearGraph();
     dessineTerrain(w, largeurMont, hauteurMont);