kellex

SC

Sep 12th, 2014
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1. #include <X11/Xlib.h>
  2. #include <X11/Xutil.h>
  3. #include <X11/Xos.h>
  4. #include <iostream>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <math.h>
  9.  
  10. using namespace std;
  11.  
  12. Display *dis;
  13. int screen;
  14. Window win;
  15. GC gc;
  16.  
  17. void init_x();
  18. void close_x();
  19. void redraw();
  20.  
  21. int main(){
  22.    
  23.     init_x();
  24.  
  25.     double r,a;
  26.             printf("Repeat: ");
  27.             scanf("%d",&r);
  28.             printf("Amount: ");
  29.             scanf("%d",&a);
  30.      
  31.             for(double yi=0;yi<r;yi++){
  32.                     yi=sin(yi);
  33.                     yi=yi*a;
  34.                     for(double xi=0;xi<r;xi++){
  35.                             xi=sin(xi);
  36.                             xi=xi*a;
  37.                             XDrawPoint(dis,win,gc,xi,yi);
  38.                     }
  39.             }
  40.            
  41.             sleep(1);
  42.             redraw();
  43.             cin.get();
  44.             sleep(1);
  45.             close_x();
  46. }
  47.  
  48. void init_x() {
  49. /* get the colors black and white (see section for details) */        
  50.     unsigned long black,white;
  51.  
  52.     dis=XOpenDisplay((char *)0);
  53.     screen=DefaultScreen(dis);
  54.     black=BlackPixel(dis,screen),
  55.     white=WhitePixel(dis, screen);
  56.     printf("Windows Dimensions: ");
  57.     int height, width;
  58.     scanf("%d %d",&height,&width);
  59.     printf("Window (white=0,black=1): ");
  60.     setwin:
  61.     int swin;
  62.     scanf("%d",&swin);
  63.     if(swin==0){
  64.         win=XCreateSimpleWindow(dis,DefaultRootWindow(dis),0,0,height,width, 5,black, white);
  65.     } else if(swin==1){
  66.         win=XCreateSimpleWindow(dis,DefaultRootWindow(dis),0,0,height,width, 5,white, black);
  67.     } else {
  68.         printf("%d is not an option!",swin);
  69.         goto setwin;
  70.     }
  71.     XSetStandardProperties(dis,win,"SC","Siegfried Keller",None,NULL,0,NULL);
  72.     XSelectInput(dis, win, ExposureMask|ButtonPressMask|KeyPressMask);
  73.         gc=XCreateGC(dis, win, 0,0);
  74.     if(swin==0){        
  75.         XSetBackground(dis,gc,white);
  76.         XSetForeground(dis,gc,black);
  77.     } else {
  78.         XSetBackground(dis,gc,black);
  79.         XSetForeground(dis,gc,white);
  80.     }
  81.     XClearWindow(dis, win);
  82.     XMapRaised(dis, win);
  83. };
  84.  
  85. void close_x() {
  86.     XFreeGC(dis, gc);
  87.     XDestroyWindow(dis,win);
  88.     XCloseDisplay(dis);
  89.     exit(1);               
  90. };
  91.  
  92. void redraw() {
  93.     XClearWindow(dis, win);
  94. };
Advertisement
Add Comment
Please, Sign In to add comment