Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!sun-barr!decwrl!shelby!lindy!hanauma!rick From: rick@hanauma (Richard Ottolini) Newsgroups: comp.windows.x Subject: seasonal demo follows (long) Message-ID: <6591@lindy.Stanford.EDU> Date: 19 Dec 89 21:35:47 GMT Sender: news@lindy.Stanford.EDU (News Service) Reply-To: rick@hanauma (Richard Ottolini) Organization: Stanford University, Dept. of Geophysics Lines: 273 /* display Hanukkah Menorah options: -display DISPLAY display -size 0.2 size fraction -bg blue background color (monochrome black) -candle red menorah color (monochrome white) -flame yellow flame color (monochrome white) -ncandle 8 number of candles -flicker -noflicker flame flicker interactivity: clicking candle ignites or douses flame; exposure and resize. */ /* compile: cc hanu.c -lX11 wakes up once a second to flicker and process events */ #include #include /* x window definitions and globals */ #define SIZE 0.2 #define TITLE "HANUKKAH GREETINGS!" Display *display; int screen; int depth; int width; int height; Colormap colormap; Window window; GC gc; char back_color[30] = "blue"; int back_pixel; /* candle definitions and globals */ #define NCANDLE 8 int ncandle = NCANDLE; char candle_color[30] = "red"; int candle_pixel; /* flame definitions and globals */ #define FLAME_OFF 0 #define FLAME_ON 1 #define FLAME1 1 #define FLAME2 2 char flame_color[30] = "yellow"; int flame_pixel; int flame_state[20]; int flicker = 1; main (argc,argv) int argc; char **argv; { GetparInit (argc,argv); Init (); Loop (); } /* initialize x windows */ Init () { char display_name[80]; float size = SIZE; XColor color1, color2; if (Getpar ("display","s",display_name) == 0) { strcpy (display_name,getenv("DISPLAY")); } if ((display = XOpenDisplay (display_name)) == NULL) { err ("cant open display"); } screen = DefaultScreen (display); depth = DefaultDepth (display,screen); colormap = XDefaultColormap (display,screen); if (depth == 1) { /* monochrome */ back_pixel = BlackPixel (display,screen); candle_pixel = WhitePixel (display,screen); flame_pixel = WhitePixel (display,screen); } else { Getpar ("bg","s",back_color); XAllocNamedColor (display,colormap,back_color,&color1,&color2); back_pixel = color1.pixel; Getpar ("candle","s",candle_color); XAllocNamedColor (display,colormap,candle_color,&color1,&color2); candle_pixel = color1.pixel; Getpar ("flame","s",candle_color); XAllocNamedColor (display,colormap,flame_color,&color1,&color2); flame_pixel = color1.pixel; } Getpar ("size","f",&size); width = DisplayWidth (display,screen) * size; height = DisplayHeight (display,screen) * size; window = XCreateSimpleWindow (display,RootWindow(display,screen), 0,0,width,height, 1,WhitePixel(display,screen),back_pixel); gc = XCreateGC (display,window,0,0); XStoreName (display,window,TITLE); XSelectInput (display,window,VisibilityChangeMask|StructureNotifyMask|ButtonPressMask); XMapWindow (display,window); Getpar ("ncandle","d",&ncandle); if (Getpar ("flicker","0",&flicker)) flicker = 1; if (Getpar ("noflicker","0",&flicker)) flicker = 0; printf ("Click to ignite flame\n"); XFlush (display); } Loop () { int i; static XEvent event; while (1) { while (XPending(display)) { XNextEvent (display,&event); switch (event.type) { /* resize */ case ConfigureNotify: if (width == event.xconfigure.width && height == event.xconfigure.height) break; width = event.xconfigure.width; height = event.xconfigure.height; case VisibilityNotify: DrawCandle (); for (i=0; i