Logo AND Algorithmique Numérique Distribuée

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