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 82 83 84
|
#include <X11/Xlib.h>
#include <unistd.h> //Sleep();
#include <math.h> //Sinus: sin();
#include <stdio.h> // getchar(); etc...
int main(){
//Creates Window
Display *display;
Window window, rootwindow;
int screen;
display = XOpenDisplay(NULL);
screen = DefaultScreen(display);
rootwindow = RootWindow(display,screen);
printf("Window Dimensions: ");
int width,height;
scanf("%d %d",&width,&height);
//Sets foreground and background of the window
GC gc;
int screen_num = DefaultScreen(display);
bg:
printf("Foreground Color (white=0,black=1): ");
int fcolor;
scanf("%d",&fcolor);
if(fcolor == 0){
XSetForeground(display,gc,WhitePixel(display,screen_num));
XSetBackground(display,gc,BlackPixel(display,screen_num));
window = XCreateSimpleWindow(display, rootwindow,0, 0, width, height, 1,BlackPixel(display,screen_num),WhitePixel(display,screen_num));
} else if(fcolor == 1){
XSetForeground(display,gc,BlackPixel(display,screen_num));
XSetBackground(display,gc,WhitePixel(display,screen_num));
window = XCreateSimpleWindow(display, rootwindow,0, 0, width, height, 1,WhitePixel(display,screen_num),BlackPixel(display,screen_num));
} else {
printf("Error! Goto to fcolor\n");
goto bg;
}
//window = XCreateSimpleWindow(display, rootwindow,0, 0, width, height, 1, 0, 0);
XMapWindow(display, window);
XFlush(display);
XGCValues values;
gc = XCreateGC(display,window,0,&values);
//creates lines definitions
int line_width = 2;
int line_style = LineSolid;
int cap_style = CapButt;
int join_style = JoinBevel;
XSetLineAttributes(display,gc,line_width,line_style,cap_style,join_style);
XSetFillStyle(display,gc,FillSolid); //Fill style for GC
//XSetForeground(display,gc,WhitePixel(display,screen_num));
//End of creating window...
double r,a;
printf("Repeat: ");
scanf("%d",&r);
printf("Amount: ");
scanf("%d",&a);
for(double yi=0;yi<r;yi++){
yi=sin(yi);
yi=yi*a;
for(double xi=0;xi<r;xi++){
xi=sin(xi);
xi=xi*a;
XDrawPoint(display,window,gc,xi,yi);
}
}
XDrawLine(display,window,gc,500,5,400,34); //This is a test, to see if the program also prints this line... but it doesn't
getchar();
sleep(5);
XCloseDisplay(display);
return 0;
}
| |