5 * 1. Créer le fichier hello.pro :
6 * +------------------------------------------------------------+
8 * |CONFIG += qt debug |
9 * |SOURCES += hello.cc |
10 * +------------------------------------------------------------+
12 * 2. Créer le fichier Makefile avec la commande :
13 * $ qmake -makefile hello.pro
14 * ou tout simplement :
17 * 3. Compiler avec la commande :
24 #include <QApplication>
25 #include <DrawingWindow.h>
29 void flip(DrawingWindow &w)
31 std::cout << "[ " << w.width << " x " << w.height << " ]\n";
35 int count = 50;//1 << 31;
38 for (int yy = y; yy < y + 10; yy++) {
39 for (int x = 0; x < w.width; x++)
42 if ((y += 10) >= w.height) {
51 void mandel(DrawingWindow &w)
53 /* paramètres par défaut */
63 int x, y; /* le pixel considéré */
64 float cr, ci; /* le complexe correspondant */
65 float zr, zi; /* pour calculer la suite */
67 float pr, pi; /* taille d'un pixel */
68 float rouge, vert, bleu;
71 pr = (Rmax - Rmin) / larg;
72 pi = (Imax - Imin) / haut;
75 for (x = 0; x < larg; x++) {
77 for (y = 0; y < haut; y++) {
81 for (i = 1; i <= maxiter; i++) {
85 /* |z| >= 2 : on sort de la boucle */
88 /* on calcule le z suivant */
92 /* on est sorti trop tôt du for(...):
93 on affiche le pixel d'un couleur en fonction
95 if (i <= maxiter / 2) {
96 /* entre rouge et vert */
97 vert = (2.0 * i) / maxiter;
100 } else if (i <= maxiter) {
101 /* entre vert et bleu */
103 bleu = (2.0 * i) / maxiter - 1.0;
105 } else /* (i > maxiter) */
106 rouge = vert = bleu = 0.0;
107 w.setColor(rouge, vert, bleu);
118 void lines(DrawingWindow &w)
124 double r = rand() / (float )RAND_MAX;
125 double g = rand() / (float )RAND_MAX;
126 double b = rand() / (float )RAND_MAX;
127 int x1 = rand() % xmax;
128 int y1 = rand() % ymax;
129 int x2 = rand() % xmax;
130 int y2 = rand() % ymax;
132 w.drawLine(x1, y1, x2, y2);
138 void rectangles(DrawingWindow &w)
141 int z = (w.width > w.height ? w.height : w.width) / 2;
144 w.drawRect(z, z, w.width - 1 - z, w.height - 1 - z);
149 int main(int argc, char *argv[])
153 QApplication application(argc, argv);
157 DrawingWindow *dw[nf + nm];
159 for (int i = 0; i < nf; ++i)
160 dw[i] = new DrawingWindow(flip, w, h);
161 for (int i = nf; i < nf + nm; ++i)
162 dw[i] = new DrawingWindow(mandel, w, h);
164 for (int i = 0; i < nf + nm; ++i)
167 DrawingWindow dr(rectangles, w, h);
170 DrawingWindow dl(lines, w, h);
173 return application.exec();