Skip to content

Instantly share code, notes, and snippets.

Created January 24, 2014 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/8600647 to your computer and use it in GitHub Desktop.
Save anonymous/8600647 to your computer and use it in GitHub Desktop.
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>
#include <cairo-xlib.h>
#ifndef M_PI
#define M_PI 3.1415926535
#endif
const int gWidth = 500;
const int gHeight = 500;
int main(int argc, char *argv[]) {
cairo_surface_t* cs;
cairo_t *cr;
Display *xDpy;
Window window;
double angle;
struct timeval start, now;
xDpy = XOpenDisplay(NULL);
window = XCreateSimpleWindow(xDpy, XDefaultRootWindow(xDpy), 0, 0, gWidth, gHeight, 0, 0, 0);
XMapWindow(xDpy, window);
cs = cairo_xlib_surface_create(xDpy, window, DefaultVisual(xDpy, 0), gWidth, gHeight);
gettimeofday(&start, NULL);
for(;;) {
cr = cairo_create(cs);
gettimeofday(&now, NULL);
angle = (now.tv_sec - start.tv_usec + (now.tv_usec-start.tv_usec)*1e-6) * M_PI/2;
cairo_set_source_rgba(cr, 1., 1., 1., 1.);
cairo_paint(cr);
cairo_set_source_rgba(cr, 0., 0., 0., 1.);
cairo_set_line_width (cr, 10.);
cairo_arc (cr, gWidth/2., gHeight/2., 100., angle, angle + M_PI/4);
cairo_stroke (cr);
cairo_destroy(cr);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment