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
|
#include <stdio.h>
#include <X11/Xaw/Command.h>
#define N 10
typedef struct { double X;
double Y; } COORDINATES;
#define NIL (0)
void PLOT_CURVE(double F[N] , double X[N],
COORDINATES Min, COORDINATES Max )
{ //---------PLOT EDGES IN A BITMAP PICTURE-------//
Display *dpy;
int Width = 400; //Width of picture in pixels
int Height= 400; //Height of picture in pixels
Pixmap Edge_pix;
GC Edge_gc;
dpy = XOpenDisplay(NIL);
Edge_pix = XCreatePixmap (dpy, RootWindowOfScreen (DefaultScreenOfDisplay (dpy)), Width, Height, 1);
int White = BlackPixel (dpy, DefaultScreen (dpy)); //This is strange but there is an inversion of colours
int Black = WhitePixel (dpy, DefaultScreen (dpy));
Edge_gc = XCreateGC (dpy, Edge_pix, 0, 0);
XSetForeground(dpy, Edge_gc, White);
XFillRectangle (dpy, Edge_pix, Edge_gc, 0, 0, Width-1, Height-1);
XSetForeground(dpy, Edge_gc, Black);
//PLOTING EDGE POINTS ON PIXMAP
#include <string.h>
char buffer[5];
int i, Xi, Yi;
for(i = 0; i<N; i++)
{ sprintf(buffer, "%d", i);
Xi = (int)( (X[i]-Min.X)/(Max.X-Min.X)*Width );
Yi = (int)( Height-(F[i]-Min.Y)/(Max.Y-Min.Y)*Height);
XDrawString(dpy, Edge_pix, Edge_gc, Xi, Yi, buffer, strlen(buffer) );
XDrawPoint (dpy, Edge_pix, Edge_gc, Xi, Yi );
}
//WE WRITE A PICTURE YOU CAN CONVERT IN GIF WITH: convert Edges.bmp Edges.gif
XWriteBitmapFile (dpy, "Picture.bmp", Edge_pix, Width, Height, -1, -1);
XFreePixmap(dpy, Edge_pix);
}
int main()
{ double F[N], X[N];
COORDINATES Min, Max; //Extremum points to plot
int i;
for(i=0; i<N; i++)
{ F[i]=(double)(i*i);
X[i]=(double)i;
}
Min.X = 0; Max.X = N;
Min.Y = 0; Max.Y = N*N;
PLOT_CURVE(F, X, Min, Max);
printf("Picture.bmp has been created\n");
return 0;
} |