Advertisement
kellex

Sinux

Sep 10th, 2014
1,970
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.22 KB | None | 0 0
  1. #include <X11/Xlib.h>
  2. #include <unistd.h> //Sleep();
  3. #include <math.h> //Sinus: sin();
  4. #include <stdio.h> // getchar(); etc...
  5.  
  6. int main(){
  7.     //Creates Window
  8.     Display *display;
  9.     Window window, rootwindow;
  10.     int screen;
  11.  
  12.     display = XOpenDisplay(NULL);
  13.     screen = DefaultScreen(display);
  14.     rootwindow = RootWindow(display,screen);
  15.  
  16.     printf("Window Dimensions: ");
  17.     int width,height;
  18.     scanf("%d %d",&width,&height);
  19.    
  20.     //Sets foreground and background of the window
  21.     GC gc;
  22.     int screen_num = DefaultScreen(display);
  23.  
  24.  
  25.     bg:
  26.     printf("Foreground Color (white=0,black=1): ");
  27.     int fcolor;
  28.     scanf("%d",&fcolor);
  29.     if(fcolor == 0){
  30.         XSetForeground(display,gc,WhitePixel(display,screen_num));
  31.         XSetBackground(display,gc,BlackPixel(display,screen_num));
  32.         window = XCreateSimpleWindow(display, rootwindow,0, 0, width, height, 1,BlackPixel(display,screen_num),WhitePixel(display,screen_num));
  33.     } else if(fcolor == 1){
  34.         XSetForeground(display,gc,BlackPixel(display,screen_num));
  35.         XSetBackground(display,gc,WhitePixel(display,screen_num));
  36.         window = XCreateSimpleWindow(display, rootwindow,0, 0, width, height, 1,WhitePixel(display,screen_num),BlackPixel(display,screen_num));
  37.     } else {
  38.         printf("Error! Goto to fcolor\n");
  39.         goto bg;
  40.     }
  41.  
  42.     //window = XCreateSimpleWindow(display, rootwindow,0, 0, width, height, 1, 0, 0);
  43.     XMapWindow(display, window);
  44.     XFlush(display);
  45.     XGCValues values;
  46.     gc = XCreateGC(display,window,0,&values);
  47.  
  48.     //creates lines definitions
  49.  
  50.     int line_width = 2;
  51.     int line_style = LineSolid;
  52.     int cap_style = CapButt;
  53.     int join_style = JoinBevel;
  54.  
  55.     XSetLineAttributes(display,gc,line_width,line_style,cap_style,join_style);
  56.     XSetFillStyle(display,gc,FillSolid); //Fill style for GC
  57.  
  58.     //XSetForeground(display,gc,WhitePixel(display,screen_num));
  59.  
  60.     //End of creating window...
  61.  
  62.     double r,a;
  63.     printf("Repeat: ");
  64.     scanf("%d",&r);
  65.     printf("Amount: ");
  66.     scanf("%d",&a);
  67.  
  68.     for(double yi=0;yi<r;yi++){
  69.         yi=sin(yi);
  70.         yi=yi*a;
  71.         for(double xi=0;xi<r;xi++){
  72.             xi=sin(xi);
  73.             xi=xi*a;
  74.             XDrawPoint(display,window,gc,xi,yi);
  75.         }
  76.     }
  77.    
  78.     XDrawLine(display,window,gc,500,5,400,34);
  79.  
  80.  
  81.     XMapWindow (display, window);
  82.     XFlush (display);
  83.     getchar();
  84.     sleep(5);
  85.     XCloseDisplay(display);
  86.     return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement