1 #include <DrawingWindow.h>
2 #include <QApplication>
5 void do_mandel(DrawingWindow &w,
6 double Rmin, double Rmax, double Imin, double Imax,
9 int x, y; // le pixel considéré
10 double cr, ci; // le complexe correspondant
11 double zr, zi; // pour calculer la suite
13 double pr, pi; // taille d'un pixel
14 double rouge, vert, bleu;
17 pr = (Rmax - Rmin) / (w.width - 1);
18 pi = (Imax - Imin) / (w.height - 1);
21 for (x = 0; x < w.width; x++) {
23 for (y = 0; y < w.height; y++) {
27 for (i = 1; i <= maxiter; i++) {
31 // |z| >= 2 : on sort de la boucle
34 // on calcule le z suivant
35 zi = 2 * zr * zi + ci;
39 rouge = vert = bleu = 0.0;
41 // on est sorti trop tôt du for(...): on affiche le
42 // pixel d'un couleur en fonction de i
43 int ii = (maxiter - i) % 96;
51 rouge = (ii - 32) / 32.0;
56 vert = (ii - 64) / 32.0;
61 w.setColor(rouge, vert, bleu);
70 void mandel(DrawingWindow &w)
72 // nombre max d'itérations
74 // zone d'intérêt par défaut
84 do_mandel(w, Rmin, Rmax, Imin, Imax, maxiter);
87 w.drawText(5, 5, "Cliquer sur l'image pour zoomer");
91 w.waitMousePress(x, y, button);
93 // calcul des coordonnées du point cliqué
94 Tr = Rmin + x * (Rmax - Rmin) / (w.width - 1);
95 Ti = Imax - y * (Imax - Imin) / (w.height - 1);
97 // calcul de la nouvelle zone d'intérêt :
98 // zoom ×2 en direction du point cliqué
100 double Rmin2 = Rmin / zoom;
101 double Rmax2 = Rmax / zoom;
102 double Imin2 = Imin / zoom;
103 double Imax2 = Imax / zoom;
104 double Rshift = Tr - (Rmin2 + Rmax2) / 2;
105 double Ishift = Ti - (Imin2 + Imax2) / 2;
111 // affichage d'un rectangle autour de la nouvelle zone d'intérêt
112 double x_factor = (w.width - 1) / (Rmax - Rmin);
113 double y_factor = (w.height - 1) / (Imax - Imin);
115 w.drawRect((Rmin2 - Rmin) * x_factor, (Imax - Imin2) * y_factor,
116 (Rmax2 - Rmin) * x_factor, (Imax - Imax2) * y_factor);
125 int main(int argc, char *argv[])
127 QApplication app(argc, argv);
128 DrawingWindow win(mandel, 800, 800);