Bonjour, j'essaye de générer puis d'afficher un ensemble de mandelbrot... Le tout compile, mais rien ne sort... Voici mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
#include "window.hpp"
 
int main(int argc, char* argv[])
{
    QApplication app(argc, argv);
    Window w;
    return app.exec();
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
#ifndef WINDOW__HPP
#define WINDOW__HPP
 
#include <QtGlobal>
#include <QtCore>
#include <QtGui>
 
class Window : public QWidget
{
    Q_OBJECT
 
    private:
        QImage imgMandelbrot;
 
        void drawImage();
 
        virtual void paintEvent(QPaintEvent* argPaintEvent);
 
    public:
        explicit Window(QWidget* widgetParent = 0);
};
 
#endif // WINDOW__HPP
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 
#include "window.hpp"
 
void Window::drawImage()
{
    qreal x1 = -2.1;
    qreal x2 = 0.6;
    qreal y1 = -1.2;
    qreal y2 = 1.2;
 
    int zoom = 100;
    int iteractionMax = 150;
 
    int widthImage = (x2 - x1) * zoom;
    int heightImage = (y2 - y1) * zoom;
 
    imgMandelbrot = QImage(widthImage, heightImage, QImage::Format_RGB32);
 
    qreal unityX = 1 / widthImage;
    qreal unityY = 1 / heightImage;
 
    for (int x = x1; x < x2; x += unityX)
    {
        for (int y = y1; y < y2; y += unityY)
        {
            int z_r = 0;
            int z_i = 0;
            int i = 0;
 
            do
            {
                int tmp = z_r;
                z_r = z_r * z_r - z_i * z_i + x;
                z_i = 2 * tmp * z_i + y;
                i++;
            } while (z_r * z_r + z_i * z_i < 4 && i < iteractionMax);
 
            if(i == iteractionMax)
                imgMandelbrot.setPixel((x - x1) * zoom, (y - y1) * zoom , qRgb(189, 149, 39));
        }
    }
 
}
 
void Window::paintEvent(QPaintEvent* argPaintEvent)
{
    Q_UNUSED(argPaintEvent);
 
    QPainter painter(this);
        painter.drawImage(0, 0, imgMandelbrot);
}
 
Window::Window(QWidget* widgetParent) :
    QWidget(widgetParent)
{
    this->drawImage();
    this->setGeometry(imgMandelbrot.rect());
    this->move(50, 50);
    this->setWindowTitle("Fractale Mandelbrot");
    this->show();
}
Ais-je fais une erreur dans la boucle ? Merci d'avance pour votre aide.