Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- #include <X11/Xos.h>
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <math.h>
- using namespace std;
- Display *dis;
- int screen;
- Window win;
- GC gc;
- void init_x();
- void close_x();
- void redraw();
- int main(){
- init_x();
- 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(dis,win,gc,xi,yi);
- }
- }
- sleep(1);
- redraw();
- cin.get();
- sleep(1);
- close_x();
- }
- void init_x() {
- /* get the colors black and white (see section for details) */
- unsigned long black,white;
- dis=XOpenDisplay((char *)0);
- screen=DefaultScreen(dis);
- black=BlackPixel(dis,screen),
- white=WhitePixel(dis, screen);
- printf("Windows Dimensions: ");
- int height, width;
- scanf("%d %d",&height,&width);
- printf("Window (white=0,black=1): ");
- setwin:
- int swin;
- scanf("%d",&swin);
- if(swin==0){
- win=XCreateSimpleWindow(dis,DefaultRootWindow(dis),0,0,height,width, 5,black, white);
- } else if(swin==1){
- win=XCreateSimpleWindow(dis,DefaultRootWindow(dis),0,0,height,width, 5,white, black);
- } else {
- printf("%d is not an option!",swin);
- goto setwin;
- }
- XSetStandardProperties(dis,win,"SC","Siegfried Keller",None,NULL,0,NULL);
- XSelectInput(dis, win, ExposureMask|ButtonPressMask|KeyPressMask);
- gc=XCreateGC(dis, win, 0,0);
- if(swin==0){
- XSetBackground(dis,gc,white);
- XSetForeground(dis,gc,black);
- } else {
- XSetBackground(dis,gc,black);
- XSetForeground(dis,gc,white);
- }
- XClearWindow(dis, win);
- XMapRaised(dis, win);
- };
- void close_x() {
- XFreeGC(dis, gc);
- XDestroyWindow(dis,win);
- XCloseDisplay(dis);
- exit(1);
- };
- void redraw() {
- XClearWindow(dis, win);
- };
Advertisement
Add Comment
Please, Sign In to add comment