12,698,453 members (23,840 online)

15.9K views
14 bookmarked
Posted

# A simple graphics library in C with BMP and WMF export

, 15 Jul 2011 CPOL
A graphics library to export graphical output to BMP or WMF.
 potential flow potential flow.vcproj.uhwang-PC.uhwang.user uniform-dipole.bmp uniform-rnkovl.bmp uniform-source.bmp uniform-vortex.bmp simple motion simple motion.vcproj.uhwang-PC.uhwang.user plate plate.vcproj.uhwang-PC.uhwang.user u-plate.bmp ```/* SIMPLE FLOW SIMULATION AROUND A PLATE */ #include #include #include #include "libtg.h" #define PI 3.141592653589793239 #define U 1.0 #define X2(x) ((x)*(x)) #define TUPI (2.0*PI) #define FOPI (2*TUPI) #define R2PI (1/TUPI) #define R4PI (1/FOPI) #define ALPHA 0.0 #define toradian(x) ((x)*PI/180) /*----------------- Lumpted Vortex Method -------------------------*/ /* Gaussian elimination */ typedef float** Array2d; typedef float* Array1d; void solveMatrix(Array2d A, Array1d x, Array1d b, int nx) { int i, j, count, n = nx; float ratio=0, temp; for(i=0;i<(n-1);i++){ for(j=(i+1);j=0;i--){ temp = b[i]; for(j=(i+1);jplot; Array1d xv, xc; Array2d A; Array1d b, gam, gridy; xv = createArray1d(npan); xc = createArray1d(npan); A = createArray2D(npan, npan); b = createArray1d(npan); gam = createArray1d(npan); gridy = createArray1d(nsgy); rhs = (float)(-2*PI*U*sin(alrad)); for(i = 0; i < npan; i++) { xv[i] = (float)(1+4*i)*chord/(npan*4); xc[i] = (float)(3+4*i)*chord/(npan*4); b[i] = (float)rhs; } for(i = 0; i < npan; i++) { for(j = 0; j < npan; j++) { A[i][j] = 1/(xc[i]-xv[j]); } } solveMatrix(A, gam, b, npan); for(i = 0; i < nsgy; i++) gridy[i] = miny+dely*i; uu = (float)(U*cos(alrad)); vv = (float)(U*sin(alrad)); p->gsave(); p->makepen(pz, TG_GetColor(TG_MAGENTA), 0.01); p->moveto(pz, xs,ys); p->lineto(pz, (float)chord,ys); p->deletepen(); p->grestore(); for(j = 0; j < nsgy; j++) { xs = minx; ys = gridy[j]; p->moveto(pz,xs,ys); while(1) { Euler_UPlate(gam, xv, uu, vv, xs, ys, npan, dell, &xm1p, &ym1p); /*RungeKutta4_UPlate(gam,xv,uu,vv,xs,ys,npan, dell, &xm1p, &ym1p);*/ if(xm1p < minx || xm1p > maxx || ym1p < miny || ym1p > maxy) break; p->lineto(pz,xm1p, ym1p); xs = xm1p, ys = ym1p; } } freeArray1d(xv); freeArray1d(xc); freeArray2D(A, npan); freeArray1d(b); freeArray1d(gam); freeArray1d(gridy); } #define BMP int main() { int xwid=500, xhgt=500; TG_PlotZone_Ptr zone=NULL; TG_Workspace_Ptr workspace = TG_InitTGLibrary("Letter"); float minx=-1.0f, maxx=1.0f, miny=-1.0f, maxy=1.0f; if(!workspace) return 1; zone = &workspace->zone; TG_SetFrame(&zone->frame, 0, 0, 3, 3, minx, maxx, miny, maxy); #ifdef BMP TG_BMP_OpenExport(zone, "u-plate.bmp", xwid, xhgt, 1); #else TG_WMF_OpenExport(zone, "u-plate.wmf"); #endif U_Plate(zone, 10, minx,miny,maxx,maxy, 50, 40); #ifdef BMP TG_BMP_CloseExport(); #else TG_WMF_CloseExport(); #endif return 0; }```

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.