Bonjour,

voici ma nouvelle contribution ,une animation d'un rectangle et d'un cercle qui se dessine,point par point ,+ une version ligne par ligne en dégradée de jaune et vert .

Voici les deux fichiers du programme :


animgeometri.h
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#ifndef _ANIMGEOMETRI_H_
#define _ANIMGEOMETRI_H_
 
#include <QPainter>
#include <QPixmap>
#include <QWidget>
#include <QVector>
#include <QColor>
#include <QLabel>
#include <QObject>
 
class Animgeometri : public QObject
{   Q_OBJECT
    public :
 
    void init()
    {   l_liste1.clear() ;
        l_liste2.clear() ;
        l_liste3.clear() ;
        l_liste4.clear() ;
        actuel_list.clear() ;
        w_widget = new QWidget ;
        l_label = new QLabel ;
        animsuivant = 0 ;
        imajnumero = 0 ;
    }
 
    void ajustelistes(QWidget * widget,QLabel * label)
    {   l_label = label ;
        w_widget = widget ;
        l_liste1.operator=(animcarre1()) ;
        l_liste2.operator=(animcarre2()) ;
        l_liste3.operator=(animcercle1()) ;
        l_liste4.operator=(animcercle2()) ;
        actuel_list.operator=(l_liste1) ;
    }
 
    QVector <QPixmap> animcarre1()
    {   QPixmap photo(400,400) ;
            photo.fill() ;
        QVector <QPixmap> listephotos ;
        int xcoord = 0 ;
        int ycoord = 0 ;
        QPainter encre(&photo) ;
        for( xcoord = 0 ; xcoord < 300 ; xcoord++)
        {   encre.drawPoint((xcoord + 50),100) ;
            listephotos << photo ;
        }
        for( ycoord = 0 ; ycoord < 200 ; ycoord++)
        {   encre.drawPoint(350,(100+ycoord)) ;
            listephotos << photo ;
        }
        for(xcoord = 0 ; xcoord < 300 ; xcoord++)
        {   encre.drawPoint((350-xcoord),300) ;
            listephotos << photo ;
        }
        for(ycoord = 0 ; ycoord < 200 ; ycoord++)
        {   encre.drawPoint(50,(300-ycoord)) ;
            listephotos << photo ;
        }
        encre.end() ;
    return listephotos ;
    }
 
    QVector <QPixmap> animcarre2()
    {   QPixmap photo(400,400) ;
            photo.fill() ;
        QVector <QPixmap> listephotos ;
        int xcoord = 0 ;
        QPainter encre(&photo) ;
        for(xcoord = 0 ;xcoord < 250 ; xcoord++)
        {   encre.setPen(QColor::QColor(xcoord,xcoord,50)) ;
            encre.drawLine((50+xcoord),100,(50+xcoord),300) ;
            listephotos << photo ;
        }
        for(xcoord = 250 ;xcoord > 200 ; xcoord--)
        {   encre.setPen(QColor::QColor(xcoord,xcoord,50))   ;
            encre.drawLine((550-xcoord),100,(550-xcoord),300) ;
            listephotos << photo ;
        }
        encre.end() ;
    return listephotos ;
    }
 
    QVector <QPixmap> animcercle1()
    {   QPixmap photo(400,400) ;
            photo.fill() ;
        QPixmap pivot ;
            pivot.operator=(photo) ;
        QVector <QPixmap> listephotos ;
        int angle = 0 ;
        QPainter encre ;
        for(angle = 0 ; angle < 360 ; angle++)
        {   encre.begin(&pivot) ;
            encre.drawArc(100,100,200,200,0,(16 * angle)) ;
            encre.end() ;
            listephotos << pivot ;
            pivot.operator=(photo) ;
        }
    return listephotos ;
    }
 
    QVector <QPixmap> animcercle2()
    {   QPixmap photo(400,400) ;
            photo.fill() ;
        int angle = 0 ;
        QVector <QPixmap> listephotos ;
        QPainter encre (&photo);
        for(angle = 70 ; angle < 250 ; angle++)
        {   encre.setBrush(QColor::QColor(0,angle,70)) ;
            encre.setPen(QColor::QColor(0,angle,70) ) ;
            encre.drawPie(100,100,200,200,(16 * (angle-70)),16) ;
            listephotos << photo ;
        }
        for(angle = 250 ; angle > 70 ; angle--)
        {   encre.setBrush(QColor::QColor(0,angle,70)) ;
            encre.setPen(QColor::QColor(0,angle,70)) ;
            encre.drawPie(100,100,200,200,(16 * (430-angle)),16) ;
            listephotos << photo ;
        }
        encre.end() ;
    return listephotos ;
    }
 
    public slots :
    void affichAnim()
    {   if ((animsuivant == 0) and (imajnumero == 999) )
        {   l_liste1.clear() ;
            actuel_list.clear() ;
            animsuivant = 1 ;
            imajnumero = 0 ;
            actuel_list = l_liste2 ;
        }
        else if ((animsuivant == 1) and (imajnumero == 299) )
        {   l_liste2.clear() ;
            actuel_list.clear() ;
            animsuivant = 2 ;
            imajnumero = 0 ;
            actuel_list = l_liste3 ;
        }
        else if ((animsuivant == 2) and (imajnumero == 359) )
        {   l_liste3.clear() ;
            actuel_list.clear() ;
            animsuivant = 3 ;
            imajnumero = 0 ;
            actuel_list = l_liste4 ;
        }
        else if((animsuivant == 3) and (imajnumero == 359) )
        {   animsuivant = 4 ;       }
 
        l_label->setPixmap(actuel_list.at(imajnumero)) ;
        l_label->update() ;
        w_widget->update() ;
        if (animsuivant < 4)
        { imajnumero++ ; }
        else
        { emit fin() ;}
    }
 
signals :
void fin() ;
 
    private :
    int imajnumero ;
    int animsuivant ;
    QVector <QPixmap> actuel_list ;
    QVector <QPixmap> l_liste1 ;
    QVector <QPixmap> l_liste2 ;
    QVector <QPixmap> l_liste3 ;
    QVector <QPixmap> l_liste4 ;
    QWidget * w_widget ;
    QLabel * l_label ;
};
 
#endif
animgeometri.cpp
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
#include "animgeometri.h"
#include <QApplication>
#include <QPainter>
#include <QPixmap>
#include <QLabel>
#include <QTimer>
#include <QVector>
#include <QGridLayout>
#include <QPushButton>
int main(int argc,char ** argv)
{   QApplication app(argc,argv) ;
    QPixmap pixels(400,400) ;
        pixels.fill(QColor::QColor(0,0,0)) ;
    QLabel * mlabel = new QLabel ;
       mlabel->setPixmap(pixels) ;
    QPushButton * bouton1 = new QPushButton ("LECTURE") ;
       bouton1->setFixedSize(80,30) ;
    QPushButton * bouton2 = new QPushButton ("FERMER") ;
       bouton2->setFixedSize(80,30) ;
    QGridLayout * mlayout = new QGridLayout ;        
        mlayout->addWidget(mlabel,0,0,1,2) ;
        mlayout->addWidget(bouton1,1,0,Qt::AlignHCenter) ;
        mlayout->addWidget(bouton2,1,1,Qt::AlignHCenter) ;
 //------------------------------------------------------------
    QWidget * mwidget = new QWidget ;
        mwidget->setLayout(mlayout) ;
        mwidget->show() ;
    Animgeometri  objet ;
        objet.init() ;
        objet.ajustelistes(mwidget,mlabel) ;
    QTimer * temp = new QTimer ;
        temp->setInterval(30) ;
    QObject::connect(temp,SIGNAL(timeout()),&objet,SLOT(affichAnim()) ) ;
    QObject::connect(bouton1,SIGNAL(clicked()),temp,SLOT(start()) ) ;
    QObject::connect(&objet,SIGNAL(fin()),temp,SLOT(stop()) ) ;
    QObject::connect(bouton2,SIGNAL(clicked()),&app,SLOT(quit()) ) ;
app.exec() ;
return 0 ;
}
Aurevoir et bonne programmation !