Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Commit last experimental bits (dated December 6th, 2013).
[graphlib.git] / test / hello.cpp
index d98d2a6..615b3ca 100644 (file)
@@ -2,14 +2,14 @@
  * Pour compiler
  * =============
  *
- * 1. Créer le fichier hello.pro :
- *      +------------------------------------------------------------+
- *      |TARGET = hello                                              |
- *      |CONFIG += qt debug                                          |
- *      |SOURCES += hello.cc                                         |
- *      +------------------------------------------------------------+
+ * 1. Créer le fichier hello.pro :
+ *    ,----
+ *    |TARGET = hello
+ *    |CONFIG += qt debug
+ *    |SOURCES += hello.cpp
+ *    `-----
  *
- * 2. Créer le fichier Makefile avec la commande :
+ * 2. Créer le fichier Makefile avec la commande :
  *      $ qmake -makefile hello.pro
  *    ou tout simplement :
  *      $ qmake -makefile
 
 void flip(DrawingWindow &w)
 {
-    std::cout << "[ " << w.width() << " x " << w.height() << " ]\n";
+    std::cout << "[ " << w.width << " x " << w.height << " ]\n";
 
     int c = 0;
     int y = 0;
-//     int h = w.height();
-//     int w = w.width();
     int count = 50;//1 << 31;
     while (1) {
-//         std::cerr << "loooooooooooooooooooooop "
-//                   << y << " (" << c << ")\n";
         w.setColor(c, c, c);
-        for (int yy = y; yy < y + 10; yy++)
-            for (int x = 0; x < w.width(); x++)
+        for (int yy = y; yy < y + 10; yy++) {
+            for (int x = 0; x < w.width; x++)
                 w.drawPoint(x, yy);
-        if ((y += 10) >= w.height()) {
+        }
+        if ((y += 10) >= w.height) {
+            w.sync();
             y = 0;
             c = !c;
             if (!--count) break;
-//             std::cerr << "loooooooooooooooooooooop "
-//                       << y << " (" << c << ")\n";
         }
     }
 }
 
 void mandel(DrawingWindow &w)
 {
-    /* paramètres par défaut */
-    int larg = w.width();
-    int haut = w.height();
+    /* paramètres par défaut */
+    int larg = w.width;
+    int haut = w.height;
     float Rmin = -2.05;
     float Rmax = 0.55;
     float Imin = -1.3;
@@ -64,7 +60,7 @@ void mandel(DrawingWindow &w)
 
     int maxiter = 100;
 
-    int x, y;                   /* le pixel considéré */
+    int x, y;                   /* le pixel considéré */
     float cr, ci;               /* le complexe correspondant */
     float zr, zi;               /* pour calculer la suite */
     float zr2, zi2;
@@ -93,7 +89,7 @@ void mandel(DrawingWindow &w)
                 zi = 2*zr*zi + ci;
                 zr = zr2 - zi2 + cr;
             }
-                /* on est sorti trop tôt du for(...):
+                /* on est sorti trop tôt du for(...):
                    on affiche le pixel d'un couleur en fonction 
                    de i */
                  if (i <= maxiter / 2) {
@@ -114,14 +110,16 @@ void mandel(DrawingWindow &w)
             ci += pi;
         }
         cr += pr;
+//         if (x % 10 == 0)
+//             w.sync();
     }
 }
 
 void lines(DrawingWindow &w)
 {
     int n = 100000;
-    int xmax = w.width();
-    int ymax = w.height();
+    int xmax = w.width;
+    int ymax = w.height;
     while (n-- > 0) {
         double r = rand() / (float )RAND_MAX;
         double g = rand() / (float )RAND_MAX;
@@ -132,19 +130,28 @@ void lines(DrawingWindow &w)
         int y2 = rand() % ymax;
         w.setColor(r, g, b);
         w.drawLine(x1, y1, x2, y2);
+        //if (n % 100 == 0)
+            w.sync();
+    }
+}
+
+void rectangles(DrawingWindow &w)
+{
+    int d = 5;
+    int z = (w.width > w.height ? w.height : w.width) / 2;
+    z = d * (z / d);
+    while (z > 0) {
+        w.drawRect(z, z, w.width - 1 - z, w.height - 1 - z);
+        z -= d;
     }
 }
 
 int main(int argc, char *argv[])
 {
-    const int w = 1000;
+    const int w = 700;
     const int h = 700;
     QApplication application(argc, argv);
 
-    DrawingWindow dd(lines, w, h);
-    dd.show();
-//     return application.exec();
-
     const int nf = 1;
     const int nm = 1;
     DrawingWindow *dw[nf + nm];
@@ -157,5 +164,11 @@ int main(int argc, char *argv[])
     for (int i = 0; i < nf + nm; ++i)
         dw[i]->show();
 
+    DrawingWindow dr(rectangles, w, h);
+    dr.show();
+
+    DrawingWindow dl(lines, w, h);
+    dl.show();
+
     return application.exec();
 }