From 3b19bde79e7b1b5b05ecb8ac111874be25e04409 Mon Sep 17 00:00:00 2001 From: Theo Date: Mon, 9 Sep 2024 13:02:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20TP=20Termin=C3=A9=20=F0=9F=94=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 83 insertions(+), 13 deletions(-) diff --git a/main.c b/main.c index bf3e2ba..23d3277 100644 --- a/main.c +++ b/main.c @@ -15,6 +15,7 @@ void ligne(int, float, float, float, float); float map(float, float, float, float, float); void reshapeCallback(int, int); void axes(float, float, float, float); +void histo(int, float, float, float, float); // Variables donneés #define MAXC 20 @@ -30,9 +31,14 @@ int nc = 0; #define VERTICAL 1 #define SUPERPOSER 2 +#define LIGNE 0 +#define LIGNE_AXES 1 +#define HISTOGRAMME 2 // pas un vrai histogramme + // Variables globales int vx1 = 0, vx2 = 400, vy1 = 0, vy2 = 400; int mode_affichage = HORIZONTAL; +int type_dessin = LIGNE; float map(float smin, float smax, float val, float omin, float omax) { @@ -92,20 +98,65 @@ void ligne(int index, float hgx, float hgy, float bdx, float bdy) glEnd(); - for(unsigned int i = 1; i < size+1; i++) + if(type_dessin == LIGNE_AXES) { - float pos_x = map(0, size-1, i-1, hgx, bdx); - float pos_y = map(valmin[index], valmax[index], courbe[index][i], bdy, hgy); - if(mode_affichage == VERTICAL) + for(unsigned int i = 1; i < size+1; i++) { - axes(bdy, pos_y, hgx, pos_x); - }else{ - axes(hgx, pos_x, bdy, pos_y); + float pos_x = map(0, size-1, i-1, hgx, bdx); + float pos_y = map(valmin[index], valmax[index], courbe[index][i], bdy, hgy); + if(mode_affichage == VERTICAL) + { + axes(bdy, pos_y, hgx, pos_x); + }else{ + axes(hgx, pos_x, bdy, pos_y); + } } } } +void histo(int index, float hgx, float hgy, float bdx, float bdy) +{ + if(index >= nc) + { + printf("Courbe non-existante."); + return; + } + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0); + glColor3f(1.0,1.0,1.0); + //glBegin(GL_POLYGON); + + unsigned int size = (unsigned int)courbe[index][0]; + + for(unsigned int i = 1; i < size+1; i++) + { + float gauche = map(0, size, i-1, hgx, bdx); + float droite = map(0, size, i, hgx, bdx); + float haut = map(valmin[index], valmax[index], courbe[index][i], bdy, hgy); + float bas = bdy; + + if(mode_affichage == VERTICAL) + { + float temp = bas; + bas = gauche; + gauche = haut; + haut = droite; + droite = temp; + } + + glRectf(gauche, haut, droite, bas); + //printf("%d : {g%f, h%f, b%f, d%f}\n", i, gauche, haut, droite, bas); + + } + + fflush(stdout); + + //glEnd(); +} + void afficher(void) { glClearColor(0.0,0.0,0.0,0.0); @@ -117,7 +168,13 @@ void afficher(void) { float haut = map(0, nc, i-1, 1.0, -1.0); float bas = map(0, nc, i, 1.0, -1.0); - ligne(i-1, -1.0, haut, 1.0, bas); + if(type_dessin == LIGNE || type_dessin == LIGNE_AXES) + { + ligne(i-1, -1.0, haut, 1.0, bas); + }else{ + // type_dessin == HISTO + histo(i-1, -1.0, haut, 1.0, bas); + } } } @@ -127,7 +184,13 @@ void afficher(void) { float gauche = map(0, nc, i-1, -1.0, 1.0); float droite = map(0, nc, i, -1.0, 1.0); - ligne(i-1, -1.0, gauche, 1.0, droite); + if(type_dessin == LIGNE || type_dessin == LIGNE_AXES) + { + ligne(i-1, -1.0, gauche, 1.0, droite); + }else{ + // type_dessin == HISTO + histo(i-1, -1.0, gauche, 1.0, droite); + } } } @@ -135,7 +198,13 @@ void afficher(void) { for(unsigned int i = 1; i < nc+1; i++) { - ligne(i-1, -1.0, 1.0, 1.0, -1.0); + if(type_dessin == LIGNE || type_dessin == LIGNE_AXES) + { + ligne(i-1, -1.0, 1.0, 1.0, -1.0); + }else{ + // type_dessin == HISTO + histo(i-1, -1.0, 1.0, 1.0, -1.0); + } } } @@ -150,7 +219,7 @@ void reshapeCallback(int largeur, int hauteur) glViewport(0, 0, largeur, hauteur); //glutPostRedisplay(); - printf("Reshape : [%d, %d]\n", vx2, vy2); + //printf("Reshape : [%d, %d]\n", vx2, vy2); } int initWindow(int argc, char* argv[], void(*display)(void)) @@ -185,7 +254,7 @@ long getFileSize(FILE* file) void parseFile(char* file, long size) { nc = atoi(file); - printf("nc=%d\n", nc); + //printf("nc=%d\n", nc); //printf("====\n%s\n====\n", file); @@ -283,7 +352,8 @@ int main(int argc, char* argv[]) printCourbeTerminal(); - mode_affichage = SUPERPOSER; + type_dessin = LIGNE_AXES; + mode_affichage = VERTICAL; int window = initWindow(argc, argv, afficher); glutMainLoop();