Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9737b9c2750d438b2a3a863cb3f7939460a2205b
[graphlib_java.git] / Test.java
1 class Test{
2     public static void main(String[] args) {
3         DrawingWindow w1 = new DrawingWindow("Test!", 400, 300);
4
5         w1.setColor("lawngreen");
6         for (int i = 0; i < 12; i++) {
7             int p = 10 * i + 10;
8             w1.drawLine(p, 0, p, 175);
9             w1.drawLine(p + i, 0, p + i, 175);
10         }
11
12         w1.setColor("black");
13         for (int i = 0; i < 12; i++) {
14             int p = 10 * i + 10;
15
16             w1.drawCircle(p, 25, i);
17             w1.fillCircle(p, 50, i);
18
19             w1.drawRect(p, 75, p + i, 75 + i);
20             w1.fillRect(p, 100, p + i, 100 + i);
21
22             w1.drawTriangle(p, 125, p + i, 125 + i/2, p, 125 + i);
23             w1.fillTriangle(p, 150, p + i, 150 + i/2, p, 150 + i);
24         }
25
26         // Try out of bounds drawings
27         w1.setColor("blue");
28         w1.drawLine(-10, w1.height - 10, w1.width + 10, w1.height - 10);
29         w1.drawLine(w1.width - 10, -10, w1.width - 10, w1.height + 10);
30         w1.setColor("red");
31         for (int x = -10; x <= w1.width + 10; x++) {
32             int y = w1.height - 20;
33             w1.drawPoint(x, y);
34             int c = w1.getPointColor(x, y);
35             if (c != (x < 0 || x >= w1.width ? 0 : 0x00ff0000))
36                 throw new AssertionError("Error with getPointColor(): " +
37                                          "(" + x + ", " + y + "): " +
38                                          String.format("%#010x", c));
39         }
40         for (int y = -10; y <= w1.height + 10; y++) {
41             int x = w1.width - 20;
42             w1.drawPoint(x, y);
43             w1.getPointColor(x, y);
44             int c = w1.getPointColor(x, y);
45             if (c != (y < 0 || y >= w1.height ? 0 : 0x00ff0000))
46                 throw new AssertionError("Error with getPointColor(): " +
47                                          "(" + x + ", " + y + "): " +
48                                          String.format("%#010x", c));
49         }
50
51         DrawingWindow w2 = new DrawingWindow("Test!", 800, 600);
52         w2.setBgColor("red");
53         w2.setColor("blue");
54         for (int i = 0; i < 3; i++) {
55             w2.clearGraph();
56             for (int y = 0; y < w2.height; y++) {
57                 for (int x = 0; x < w2.width; x++) {
58                     w2.drawPoint(x, y);
59                 }
60             }
61         }
62         w2.setColor("white");
63         for (int i = 0; i < 3; i++) {
64             w2.clearGraph();
65             for (int y = 0; y < w2.height; y++) {
66                 for (int x = 0; x < w2.width; x++) {
67                     w2.drawPoint(x, y);
68                 }
69                 w2.sync();
70             }
71         }
72         w2.closeGraph();
73
74         System.out.println("Click anywhere on w1...");
75
76         w1.setColor("black");
77         while (w1.waitMousePress(5 * 1000)) {
78             int x = w1.getMouseX();
79             int y = w1.getMouseY();
80             System.out.println("[ " + x + " ; " + y + " ] - " +
81                                w1.getMouseButton());
82             w1.drawLine(x - 5, y, x + 5, y);
83             w1.drawLine(x, y - 5, x, y + 5);
84         }
85
86         System.out.println("Done!");
87     }
88 }