Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Check bounds in drawPoint().
[graphlib_java.git] / Test.java
1 class Test{
2     public static void main(String[] args) {
3         DrawingWindow w1 = new DrawingWindow("Test!", 400, 400);
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             w1.drawPoint(x, w1.height - 20);
33         for (int y = -10; y <= w1.height + 10; y++)
34             w1.drawPoint(w1.width - 20, y);
35
36         DrawingWindow w2 = new DrawingWindow("Test!", 800, 600);
37         w2.setBgColor("red");
38         w2.setColor("blue");
39         for (int i = 0; i < 3; i++) {
40             w2.clearGraph();
41             for (int y = 0; y < w2.height; y++) {
42                 for (int x = 0; x < w2.width; x++) {
43                     w2.drawPoint(x, y);
44                 }
45             }
46         }
47         w2.setColor("white");
48         for (int i = 0; i < 3; i++) {
49             w2.clearGraph();
50             for (int y = 0; y < w2.height; y++) {
51                 for (int x = 0; x < w2.width; x++) {
52                     w2.drawPoint(x, y);
53                 }
54                 w2.sync();
55             }
56         }
57         w2.closeGraph();
58
59         System.out.println("Click anywhere on w1...");
60
61         w1.setColor("black");
62         while (w1.waitMousePress(5 * 1000)) {
63             int x = w1.getMouseX();
64             int y = w1.getMouseY();
65             System.out.println("[ " + x + " ; " + y + " ] - " +
66                                w1.getMouseButton());
67             w1.drawLine(x - 5, y, x + 5, y);
68             w1.drawLine(x, y - 5, x, y + 5);
69         }
70
71         System.out.println("Done!");
72     }
73 }