kellex

Sinux2

Sep 12th, 2014
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. /* include the X library headers */
  2. #include <X11/Xlib.h>
  3. #include <X11/Xutil.h>
  4. #include <X11/Xos.h>
  5.  
  6. /* include some silly stuff */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <math.h>
  10.  
  11. /* here are our X variables */
  12. Display *dis;
  13. int screen;
  14. Window win;
  15. GC gc;
  16.  
  17. /* here are our X routines declared! */
  18. void init_x();
  19. void close_x();
  20. void redraw();
  21.  
  22. main () {
  23.     XEvent event;        /* the XEvent declaration !!! */
  24.     KeySym key;        /* a dealie-bob to handle KeyPress Events */    
  25.     char text[255];        /* a char buffer for KeyPress Events */
  26.  
  27.     init_x();
  28.  
  29.     double r,a;
  30.     printf("Repeat: ");
  31.     scanf("%d",&r);
  32.     printf("Amount: ");
  33.     scanf("%d",&a);
  34.  
  35.     for(double yi=0;yi<r;yi++){
  36.         yi=sin(yi);
  37.         yi=yi*a;
  38.         for(double xi=0;xi<r;xi++){
  39.             xi=sin(xi);
  40.             xi=xi*a;
  41.             XDrawPoint(dis,win,gc,xi,yi);
  42.         }
  43.     }
  44.  
  45.     getchar();
  46.     sleep(5);
  47.     close_x();
  48. }
  49.  
  50. void init_x() {
  51. /* get the colors black and white (see section for details) */        
  52.     unsigned long black,white;
  53.  
  54.     dis=XOpenDisplay((char *)0);
  55.        screen=DefaultScreen(dis);
  56.     black=BlackPixel(dis,screen),
  57.     white=WhitePixel(dis, screen);
  58.     printf("Window height, width: ");
  59.     int height,width;
  60.     scanf("%d %d",&height,&width);
  61.        win=XCreateSimpleWindow(dis,DefaultRootWindow(dis),0,0,height, width, 5,black, white);
  62.     XSetStandardProperties(dis,win,"x11lib","template",None,NULL,0,NULL);
  63.     XSelectInput(dis, win, ExposureMask|ButtonPressMask|KeyPressMask);
  64.         gc=XCreateGC(dis, win, 0,0);
  65.     XSetBackground(dis,gc,white);
  66.     XSetForeground(dis,gc,black);
  67.     XClearWindow(dis, win);
  68.     XMapRaised(dis, win);
  69. };
  70.  
  71. void close_x() {
  72.     XFreeGC(dis, gc);
  73.     XDestroyWindow(dis,win);
  74.     XCloseDisplay(dis);
  75.     exit(1);
  76. };
  77.  
  78. void redraw() {
  79.     XClearWindow(dis, win);
  80. };
Advertisement
Add Comment
Please, Sign In to add comment