Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Cosmetics.
[graphlib_java.git] / Exemple2.java
1 import java.util.*;
2
3 class Exemple2 {
4
5     public static void main(String[] args) {
6         // Création de la fenêtre
7         DrawingWindow w = new DrawingWindow("Exemple 2", 640, 480);
8
9         int width = Math.min(w.width - 1, w.height - 1) / 2;
10
11         // Affichage de rectangles concentriques, avec un dégradé de
12         // couleurs
13         for (int z = 0; z <= width; z++) {
14             float r, g, b;
15             float s = 3.0f * z / width;
16             if (z <= width / 3.0f) {
17                 r = 1.0f - s;
18                 g = s;
19                 b = 0.0f;
20             } else if (z <= 2.0f * width / 3.0f) {
21                 s -= 1.0f;
22                 r = 0.0f;
23                 g = 1.0f - s;
24                 b = s;
25             } else {
26                 s -= 2.0f;
27                 r = s;
28                 g = 0.0f;
29                 b = 1.0f - s;
30             }
31             // On change la couleur de dessin...
32             w.setColor(r, g, b);
33             // ... et on affiche un rectangle
34             w.drawRect(z, z, w.width - 1 - z, w.height - 1 - z);
35         }
36     }
37 }