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
| //3 droites
#include <QApplication>
#include <QString>
#include <QPainter>
#include <QPixmap>
#include <QLabel>
#include <QColor>
#include <QVector>
void Fctinit(QPixmap * grille )
{ grille->fill() ; }
void Fctdroite (QPixmap * grille ,double xcoord = 0, double coeffd = 1, double fz = 0 )
{ double ycoord = 0 ;
//-------------------------------------------
ycoord = xcoord * coeffd + fz ;
// y = ax + b
// ou f(x) = ax + f(0)
//-------------------------------------------
qreal angle1 = -90 ;
qreal xdeplace = -470 ;
qreal ydeplace = 30 ;
QPainter encre(grille ) ;
encre.rotate(angle1) ;
encre.translate(xdeplace,ydeplace) ;
encre.drawPoint(ycoord,xcoord ) ;
encre.end() ;
}
//******************************************
void Fctligne( QPixmap * grille)
{ double xw = 0 ;
//tracement de 3 droites
for (xw = 0 ; xw < 470 ; xw+=0.5)
{ Fctdroite(grille,xw) ;
Fctdroite(grille,xw,0.5) ;
Fctdroite(grille,xw,2) ;
}
}
//*******************************************
void Fctgrille(QPixmap * grille )
{ int x1= 0 ; int y1 = 0 ;
qreal angle1 = -90 ;
qreal xdeplace = -470 ;
qreal ydeplace = 30 ;
QPainter graphite(grille ) ;
graphite.rotate(angle1) ;
graphite.translate(xdeplace,ydeplace) ;
graphite.drawLine(0,0,0,470) ;
graphite.drawLine(0,0,470,0) ;
for ( y1 = 10 ; y1 < 470 ; y1+= 10)
{ graphite.drawLine( x1 ,y1,x1 + 5,y1 ) ; }
x1 = 0 ;
for ( y1 = 50 ; y1 < 470 ; y1+= 50)
{ graphite.drawLine(x1,y1,x1 + 10 ,y1) ; }
y1 = 0 ;
for ( x1 = 10 ; x1 < 470 ; x1+=10)
{ graphite.drawLine( x1 ,y1,x1 ,y1 + 5) ; }
x1 = 0 ;
for ( x1 = 50 ; x1 < 470 ; x1+= 50)
{ graphite.drawLine(x1,y1,x1 ,y1+10 ) ; }
graphite.end() ;
}
void Fcttxt(QPixmap * image )
{ int x20 = 0 ; int y20 = 480 ;
QString valeurmo ;
QPainter graphite( image) ;
for (x20 = 50 ; x20 < 451 ; x20 += 50 )
{ valeurmo = QString::number(x20) ;
graphite.drawText(x20+20 ,y20+5, valeurmo) ;
}
y20 = 0 ; x20 = 0 ;
for (y20 = 500 ; y20 > 0 ; y20 -= 50 )
{ valeurmo = QString::number(y20) ;
graphite.drawText(x20+5 ,475 - y20, valeurmo) ;
}
}
int main(int argc,char ** argv)
{ QApplication app( argc,argv) ;
QPixmap papier(500,500) ;
Fctinit(&papier) ;
Fctgrille( &papier ) ;
Fcttxt(&papier) ;
Fctligne(&papier) ;
//papier.save("droites3.png","png" ) ;
QLabel fenetre1 ;
fenetre1.setFixedSize(500,500 ) ;
fenetre1.setPixmap( papier) ;
fenetre1.show() ;
app.exec() ;
return 0 ;
} |
Partager