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
| //dessin parabole version 0.03
#include <QApplication>
#include <QPixmap>
#include <QPainter>
#include <QLabel>
#include <QString>
//include <QPen>
//image des axes : xc horyzontale et yc verticale
QPixmap axehxy()
{ QPixmap image(500,500) ;
image.fill() ;
int yc = 0 ;
int xc = 0 ;
QString valmotyc ;
QString valmotxc ;
QPainter stylet(&image) ;
stylet.drawLine(250,20,250,490) ;
for ( yc = 20 ; yc <= 489 ; yc+=10 )
{ stylet.drawLine(248,yc,252,yc) ;
if ( yc % 50 == 0)
{ valmotyc = QString::number(yc) ;
if ( yc < 51)
{ stylet.drawText(225,(yc + 25) ,valmotyc) ; }
if ( yc > 50 )
{ stylet.drawText(220,(yc + 25),valmotyc) ; }
}
}
stylet.drawLine(5,20,490,20) ;
for ( xc = 10 ; xc < 489 ; xc+=10 )
{ stylet.drawLine(xc,18,xc,22) ;
if ( xc % 50 == 0)
{ valmotxc = QString::number(xc-250) ;
if( ((xc -250) >= -50) and ((xc -250) <= 50) )
{ stylet.drawText(xc-8,13,valmotxc) ; }
if ((xc - 250) < -51)
{ stylet.drawText(xc-15,13,valmotxc) ; }
if ((xc - 250) > 50)
{ stylet.drawText(xc-15,13,valmotxc) ; }
}
}
stylet.end() ;
return image ;
}
//fonction parabole f(x) = a*x*x + b*x + c
int fdxw(double afix = 0,double bfix = 0,double cfix = 0,double xv = 0)
{ double fdxv = 0 ;
fdxv = afix*xv*xv + bfix*xv + cfix ;
return fdxv ;
}
int main(int argc, char ** argv)
{ QApplication app(argc,argv) ;
QPixmap pixels ;
pixels = axehxy() ;
double xw = 0 ;
double yw = 0 ;
QPainter crayon(&pixels) ;
for (xw = -70 ; xw < 70 ; xw+=0.1)
{ yw = fdxw(0.1,0.1,0,xw) ;
//f(x) = 0.1*x*x + 0.1*x + 0
crayon.drawRect(xw + 250,yw + 20,1,1) ;
//x0 + 250, f(x0) + 20 ,la parabole est decaley
}
crayon.end() ;
QLabel fenetre ;
fenetre.setFixedSize(510,510) ;
fenetre.setPixmap(pixels) ;
fenetre.show() ;
app.exec() ;
return 0 ;
} |
Partager