//------------------------------------------------------ // module : Tp4-IFT2425-4-3.c // author : // date : // version : 1.0 // language: C++ // note : //------------------------------------------------------ // //------------------------------------------------ // FICHIERS INCLUS ------------------------------- //------------------------------------------------ #include #include #include #include #include #include /*************************************************************/ /* WINDOWS */ /*************************************************************/ #include #include #include #include #include #include Display *display; int screen_num; int depth; Window root; Visual* visual; GC gc; //------------------------------------------------ // DEFINITIONS ----------------------------------- //------------------------------------------------ #define CARRE(X) ((X)*(X)) #define OUTPUT_FILE "ImgOut.pgm" #define VIEW_PGM "xv" #define H 0.00005 #define T_0 0.0 #define T_F 150.0 #define NB_INTERV (T_F-T_0)/H #define X_1_INI 0.0 #define X_2_INI 0.0 #define X_3_INI 0.0 #define X_4_INI 0.0 #define WIDTH 512 #define HEIGHT 512 #define MAX_X 1.5 #define MAX_Y 1.5 #define EVOL_GRAPH 3000 #define WHITE 255 #define GREYWHITE 240 #define GREY 200 #define BLACK 0 //------------------------------------------------ // GLOBAL CST ------------------------------------ //------------------------------------------------ float Xmin=0.0; float Xmax=0.0; float Ymin=0.0; float Ymax=0.0; /************************************************************************/ /* OPEN_DISPLAY() */ /************************************************************************/ int open_display() { if ((display=XOpenDisplay(NULL))==NULL) { printf("Connection impossible\n"); return(-1); } else { screen_num=DefaultScreen(display); visual=DefaultVisual(display,screen_num); depth=DefaultDepth(display,screen_num); root=RootWindow(display,screen_num); return 0; } } /************************************************************************/ /* FABRIQUE_WINDOW() */ /* Cette fonction crée une fenetre X et l'affiche à l'écran. */ /************************************************************************/ Window fabrique_window(char *nom_fen,int x,int y,int width,int height,int zoom) { Window win; XSizeHints size_hints; XWMHints wm_hints; XClassHint class_hints; XTextProperty windowName, iconName; char *name=nom_fen; if(zoom<0) { width/=-zoom; height/=-zoom; } if(zoom>0) { width*=zoom; height*=zoom; } win=XCreateSimpleWindow(display,root,x,y,width,height,1,0,255); size_hints.flags=PPosition|PSize|PMinSize; size_hints.min_width=width; size_hints.min_height=height; XStringListToTextProperty(&name,1,&windowName); XStringListToTextProperty(&name,1,&iconName); wm_hints.initial_state=NormalState; wm_hints.input=True; wm_hints.flags=StateHint|InputHint; class_hints.res_name=nom_fen; class_hints.res_class=nom_fen; XSetWMProperties(display,win,&windowName,&iconName, NULL,0,&size_hints,&wm_hints,&class_hints); gc=XCreateGC(display,win,0,NULL); XSelectInput(display,win,ExposureMask|KeyPressMask|ButtonPressMask| ButtonReleaseMask|ButtonMotionMask|PointerMotionHintMask| StructureNotifyMask); XMapWindow(display,win); return(win); } /****************************************************************************/ /* CREE_XIMAGE() */ /* Crée une XImage à partir d'un tableau de double */ /* L'image peut subir un zoom. */ /****************************************************************************/ XImage* cree_Ximage(double** mat,int z,int length,int width) { int lgth,wdth,lig,col,zoom_col,zoom_lig; float somme; unsigned char pix; unsigned char* dat; XImage* imageX; /*Zoom positiv*/ /*------------*/ if (z>0) { lgth=length*z; wdth=width*z; dat=(unsigned char*)malloc(lgth*(wdth*4)*sizeof(unsigned char)); if (dat==NULL) { printf("Impossible d'allouer de la memoire."); exit(-1); } for(lig=0;ligAllocMemory double** MatPict=dmatrix_allocate_2d(HEIGHT,WIDTH); double** MatPts=dmatrix_allocate_2d((int)(NB_INTERV),2); //>Init for(i=0;iAlgorithme RungeKutta ordre 4 //-------------------------------------------------------------- // Ici il faut travailler ... //Un exemple ou la matrice de points est remplie //par un cercle grandissant ... et non pas par //la solution de l'équation différentielle for(k=0;k<(int)(NB_INTERV);k++) { MatPts[k][0]=(MAX_Y/2.0)+(k/(float)(NB_INTERV))*cos((k*0.001)*3.14159); MatPts[k][1]=(k/(float)(NB_INTERV))*sin((k*0.001)*3.14159); } //--Fin Algo RK4---------------------------------------------- //>Affichage des Points MatPts dans MatPict plot_point(MatPts,MatPict,(int)(NB_INTERV)); //>Save&Visu de MatPict SaveImagePgm(OUTPUT_FILE,MatPict,HEIGHT,WIDTH); strcpy(BufSystVisu,VIEW_PGM); strcat(BufSystVisu," "); strcat(BufSystVisu,OUTPUT_FILE); strcat(BufSystVisu," &"); system(BufSystVisu); //>Affiche Statistique printf("\n\n Stat: Xmin=[%.2f] Xmax=[%.2f] Ymin=[%.2f] Ymax=[%.2f]\n",Xmin,Xmax,Ymin,Ymax); //-------------------------------------------------------------------------------- //-------------- visu sous XWINDOW de l'évolution de MatPts ---------------------- //-------------------------------------------------------------------------------- if (flag_graph) { //>Uuverture Session Graphique if (open_display()<0) printf(" Impossible d'ouvrir une session graphique"); sprintf(nomfen_ppicture,"Évolution du Graphe"); win_ppicture=fabrique_window(nomfen_ppicture,10,10,HEIGHT,WIDTH,zoom); x_ppicture=cree_Ximage(MatPict,zoom,HEIGHT,WIDTH); printf("\n\n Pour quitter,appuyer sur la barre d'espace"); fflush(stdout); //>Boucle Evolution for(i=0;iwidth,x_ppicture->height); } } //>Retour printf("\n Fini... \n\n\n"); return 0; }