Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
.
[graphlib.git] / test / hello.cpp
index 4143590..40432e3 100644 (file)
 
 #include <iostream>
 
-int flip(DrawingWindow &w)
+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 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 x = 0; x < w.width; x++)
                 w.drawPoint(x, yy);
-        if ((y += 10) >= w.height()) {
+        if ((y += 10) >= w.height) {
             y = 0;
             c = !c;
             if (!--count) break;
@@ -50,14 +50,13 @@ int flip(DrawingWindow &w)
 //                       << y << " (" << c << ")\n";
         }
     }
-    return 0;
 }
 
-int mandel(DrawingWindow &w)
+void mandel(DrawingWindow &w)
 {
     /* paramètres par défaut */
-    int larg = w.width();
-    int haut = w.height();
+    int larg = w.width;
+    int haut = w.height;
     float Rmin = -2.05;
     float Rmax = 0.55;
     float Imin = -1.3;
@@ -116,16 +115,51 @@ int mandel(DrawingWindow &w)
         }
         cr += pr;
     }
-    return 0;
+}
+
+void lines(DrawingWindow &w)
+{
+    int n = 100000;
+    int xmax = w.width;
+    int ymax = w.height;
+    while (n-- > 0) {
+        double r = rand() / (float )RAND_MAX;
+        double g = rand() / (float )RAND_MAX;
+        double b = rand() / (float )RAND_MAX;
+        int x1 = rand() % xmax;
+        int y1 = rand() % ymax;
+        int x2 = rand() % xmax;
+        int y2 = rand() % ymax;
+        w.setColor(r, g, b);
+        w.drawLine(x1, y1, x2, y2);
+    }
+}
+
+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 nf = 1;
-    const int nm = 1;
     const int w = 1000;
     const int h = 700;
     QApplication application(argc, argv);
+
+    DrawingWindow dl(lines, w, h);
+    dl.show();
+
+    DrawingWindow dr(rectangles, w, h);
+    dr.show();
+
+    const int nf = 1;
+    const int nm = 1;
     DrawingWindow *dw[nf + nm];
 
     for (int i = 0; i < nf; ++i)