v05i006: floatbg -- slowly modify the root window colors, Part01/01

Dan Heller argv at island.uu.net
Mon Sep 25 04:01:06 AEST 1989


Submitted-by: uunet!cwi.nl!rekers
Posting-number: Volume 5, Issue 6
Archive-name: floatbg/part01

#--------------------------------CUT HERE-------------------------------------
#! /bin/sh
#
# This is a shell archive.  Save this into a file, edit it
# and delete all lines above this comment.  Then give this
# file to sh by executing the command "sh file".  The files
# will be extracted into the current directory owned by
# you with default permissions.
#
# The files contained herein are:
#
# -rw-r--r--  1 rekers       1890 Sep 22 13:53 README
# -rw-r--r--  1 rekers        234 Sep 22 13:58 Makefile
# -rw-r--r--  1 rekers        143 Sep 18 14:36 Imakefile
# -rw-r--r--  1 rekers       4561 Sep 19 16:12 floatbg.c
# -rw-r--r--  1 rekers       1413 Sep 22 13:56 floatbg.man
#
echo 'x - README'
if test -f README; then echo 'shar: not overwriting README'; else
sed 's/^X//' << '________This_Is_The_END________' > README
XFloatbg is a little X-application that slowly modifies the color of
Xthe root-window. You won't be able to see the color change, but after a
Xquarter of an hour, you'll notice that it did change, however. 
X
XThe program does have a minimal processor time consumption, as it sleeps
Xmost of the time and its computations are not complicated.
XAfter having run for more than two hours, `ps ux' on my sparc reported the
Xfollowing:
XUSER       PID %CPU %MEM   SZ  RSS TT STAT START  TIME COMMAND
Xrekers     849  0.0  0.7   52   80 p3 S    12:14   0:00 floatbg
X
XFloatbg doesn't use any window, button or menu, and it can only be stopped
Xby killing it. This is a feature I don't like too much, but making a realy
Xnice user interface is just too much for such a little joke...
X
XFloatbg starts with a random color and changes it deterministicly by moving
Xthrough a hsv-model of colors.
XIn the hsv-model, colors are described by three parameters:
Xh = hue stands for the tint of a color
X	(0 degrees is red, 60 = yellow, 120 = green, 180 = aquamarine, etc)
Xs = saturations stands for the brightness of the color
X	(0 = white, 1 = bright)
Xv = value stands for the intensity of the color
X	(0 = black, 1 = normal)
X
XEvery 10 seconds the hue is increased by 1 degree and the saturation is 
Xchanged by a sinus over the hue. The value remains fixed.
XThe default values are chosen such that all pastel tints are visited,
Xbut these can of course be customized:
Xusage: floatbg [options]
X  where options are:
X  -display <display>   or   -d <display>
X  -help
X  -value <float>   (default 0.87)
X  -satmid <float>  (default 0.375)
X  -satvar <float>  (default 0.125)
X  -fase <float>    (default 0.25)
X  value, (satmid-satvar) and (satmid+satvar) must be between 0 and 1
X
XFloatbg is free and yours!
XI would like to hear about changes people made on it.
X
XAmsterdam, September 18, 1989.
X					Jan Rekers (email: rekers at cwi.nl)
X
________This_Is_The_END________
if test `wc -l < README` -ne 45; then
	echo 'shar: README was damaged during transit (should have been 45 bytes)'
fi
fi		; : end of overwriting check
echo 'x - Makefile'
if test -f Makefile; then echo 'shar: not overwriting Makefile'; else
sed 's/^X//' << '________This_Is_The_END________' > Makefile
X
Xfloatbg: floatbg.o
X	cc -O -o floatbg floatbg.o -lX11 -lm
X
Xfloatbg.o: floatbg.c
X	cc -O -c floatbg.c
X
Xclean:
X	rm -f floatbg floatbg.o floatbg.shar core a.out
X
Xshar:
X	shar -h floatbg.shar README Makefile Imakefile floatbg.c floatbg.man
________This_Is_The_END________
if test `wc -l < Makefile` -ne 12; then
	echo 'shar: Makefile was damaged during transit (should have been 12 bytes)'
fi
fi		; : end of overwriting check
echo 'x - Imakefile'
if test -f Imakefile; then echo 'shar: not overwriting Imakefile'; else
sed 's/^X//' << '________This_Is_The_END________' > Imakefile
X  LOCAL_LIBRARIES = $(XLIB)
X             SRCS = floatbg.c
X             OBJS = floatbg.o
XSYSLAST_LIBRARIES = -lm
X
XComplexProgramTarget(floatbg)
________This_Is_The_END________
if test `wc -l < Imakefile` -ne 6; then
	echo 'shar: Imakefile was damaged during transit (should have been 6 bytes)'
fi
fi		; : end of overwriting check
echo 'x - floatbg.c'
if test -f floatbg.c; then echo 'shar: not overwriting floatbg.c'; else
sed 's/^X//' << '________This_Is_The_END________' > floatbg.c
X/*
X *	floatbg.c
X *	author: Jan Rekers
X *	purpose: This program slowly changes the color of the root window of X.
X */
X
X#include <X11/Xlib.h>
X#include <stdio.h>
X
X#define MaxColor 	0xffff
X#define MaxTime  	0x7fff
X#define pi		3.1415926535
X#define default_sf_in_hf	.25
X#define default_s_mid	.375
X#define default_s_var	.125
X#define default_v_val	.87
X
Xchar *program_name;
XDisplay *dpy;
Xint screen;
XWindow root;
X
Xstruct hsv { float h,s,v; };
Xstruct rgb { float r,g,b; };
X
Xvoid hsv2rgb(), ticks2hsv();
Xfloat sf_in_hf = default_sf_in_hf;
Xfloat s_mid = default_s_mid;
Xfloat s_var = default_s_var;
Xfloat v_val = default_v_val;
X
Xunsigned long GetMutableColor();
Xvoid SetColor();
Xlong time(), random();
Xdouble atof();
X
Xusage()
X{
X    fprintf(stderr, "usage: %s [options]\n", program_name);
X    fprintf(stderr, "  where options are:\n");
X    fprintf(stderr, "  -display <display>   or   -d <display>\n");
X    fprintf(stderr, "  -help\n");
X    fprintf(stderr, "  -value <float>   (default %1.2f)\n", default_v_val);
X    fprintf(stderr, "  -satmid <float>  (default %1.3f)\n", default_s_mid);
X    fprintf(stderr, "  -satvar <float>  (default %1.3f)\n", default_s_var);
X    fprintf(stderr, "  -fase <float>    (default %1.2f)\n", default_sf_in_hf);
X    fprintf(stderr, "  value, (satmid-satvar) and (satmid+satvar) must be between 0 and 1\n");
X    exit(1);
X}
X
Xmain(argc, argv) 
X    int argc;
X    char **argv;
X{
X    char *display_name = NULL;
X    unsigned long cmapentry;
X    register int ticks;
X    int i;
X    struct hsv hsv;
X    struct rgb rgb;
X    extern char *optarg;
X
X    program_name=argv[0];
X    for (i = 1; i < argc; i++) {
X	if (!strcmp ("-display", argv[i]) || !strcmp ("-d", argv[i])) {
X	    if (++i>=argc) usage ();
X	    display_name = argv[i];
X	    continue;
X	}
X	if (!strcmp("-help", argv[i])) {
X	    usage();
X	}
X	if (!strcmp("-value", argv[i])) {
X	    if (++i>=argc) usage();
X	    v_val = atof(argv[i]);
X	    continue;
X	}
X	if (!strcmp("-satmid", argv[i])) {
X	    if (++i>=argc) usage();
X	    s_mid = atof(argv[i]);
X	    continue;
X	}
X	if (!strcmp("-satvar", argv[i])) {
X	    if (++i>=argc) usage();
X	    s_var = atof(argv[i]);
X	    continue;
X	}
X	if (!strcmp("-fase", argv[i])) {
X	    if (++i>=argc) usage();
X	    sf_in_hf = atof(argv[i]);
X	    continue;
X	}
X	usage();
X    } 
X
X    if ( (v_val < 0) || (v_val > 1) ) usage();
X    if ( ((s_mid - s_var) < 0) || ((s_mid + s_var) > 1) ) usage();
X
X    dpy = XOpenDisplay(display_name);
X    if (!dpy) {
X	fprintf(stderr, "%s:  unable to open display '%s'\n",
X		program_name, XDisplayName (display_name));
X	exit(1);
X    }
X    screen = DefaultScreen(dpy);
X    root = RootWindow(dpy, screen);
X
X    srandom( (int)time(0L) );
X    ticks = (int)random() % MaxTime;
X
X    cmapentry = GetMutableColor();
X    XSetWindowBackground(dpy, root, cmapentry);
X    XClearWindow(dpy, root);
X    while ( 1 ) {
X	ticks2hsv(ticks, &hsv);
X	hsv2rgb(&hsv, &rgb);
X	SetColor(cmapentry, &rgb);
X	XFlush(dpy);
X	ticks = ticks++ % MaxTime;
X	sleep(10);
X    }
X}
X
Xunsigned long GetMutableColor ()
X{
X    XColor color;
X    if (XAllocColorCells (dpy, DefaultColormap(dpy,screen),
X			  0, 0, 0, &color.pixel, 1) == NULL) {
X	fprintf(stderr, "%s:  unable to allocate colorcells\n", program_name);
X	exit(1); }
X    return(color.pixel);
X}
X
Xvoid SetColor (pixel, rgb)
X    unsigned long pixel;
X    struct rgb *rgb;
X{
X    XColor color;
X    int red = (int) MaxColor * rgb->r;
X    int green = (int) MaxColor * rgb->g;
X    int blue = (int) MaxColor * rgb->b;
X
X    color.red = red; color.green = green; color.blue = blue;
X    color.pixel = pixel;
X    color.flags = DoRed|DoGreen|DoBlue;
X    XStoreColor(dpy, DefaultColormap(dpy,screen), &color);
X}
X
Xvoid ticks2hsv (ticks, hsv)
X    int ticks;
X    struct hsv *hsv;
X{
X    float s_fase, sin();
X
X    hsv->h = ticks % 360;
X    s_fase = sf_in_hf * (pi / 180) * ticks;
X    hsv->s = s_mid - (s_var * sin(s_fase));
X    hsv->v = v_val;
X}
X
Xvoid hsv2rgb (hsv, rgb)
X    struct hsv *hsv;
X    struct rgb *rgb;
X{
X    int i;
X    float f, p, q, r, h, v;
X
X    v = hsv->v;
X    if (hsv->s == 0) {
X	rgb->r = v; rgb->g = v; rgb->b = v; }
X    else {
X	h = hsv->h / 60;
X	i = (int) h;
X	f = h - i;
X	p = hsv->v * (1 - hsv->s);
X	q = hsv->v * (1 - (hsv->s * f));
X	r = hsv->v * (1 - (hsv->s * (1 - f)));
X	switch (i) {
X	    case 0: rgb->r = v; rgb->g = r; rgb->b = p; break;
X	    case 1: rgb->r = q; rgb->g = v; rgb->b = p; break;
X	    case 2: rgb->r = p; rgb->g = v; rgb->b = r; break;
X	    case 3: rgb->r = p; rgb->g = q; rgb->b = v; break;
X	    case 4: rgb->r = r; rgb->g = p; rgb->b = v; break;
X	    case 5: rgb->r = v; rgb->g = p; rgb->b = q; break;
X	}
X    }
X}
________This_Is_The_END________
if test `wc -l < floatbg.c` -ne 187; then
	echo 'shar: floatbg.c was damaged during transit (should have been 187 bytes)'
fi
fi		; : end of overwriting check
echo 'x - floatbg.man'
if test -f floatbg.man; then echo 'shar: not overwriting floatbg.man'; else
sed 's/^X//' << '________This_Is_The_END________' > floatbg.man
X.TH floatbg 1X
X.SH NAME
Xfloatbg \- slowly modify the color of the X root window
X.SH SYNTAX
X\fBfloatbg\fP
X[-display \fIdisplay\fP]
X[-help]
X[-value \fIfloat\fP] 
X[-satmid \fIfloat\fP] 
X[-satvar \fIfloat\fP] 
X[-fase \fIfloat\fP] 
X.SH DESCRIPTION
XFloatbg is an X11 program that modifies the color of the root window
Xin such a manner that you won't to see the color change,
Xbut after a while you'll notice that it did change, however.
X.PP
XFloatbg starts with a random color and changes it deterministicly by moving
Xthrough a hsv-model of colors.
XIn the hsv-model, colors are described by three parameters:
XHue stands for the tint of a color
X(0 degrees is red, 60 = yellow, 120 = green, 180 = aquamarine, etc),
Xsaturations stands for the brightness of the color
X(0 = white, 1 = bright),
Xand value stands for the intensity of the color
X(0 = black, 1 = normal).
X.PP
XEvery 10 seconds the hue (tint) is increased by one degree
Xand the saturation (brightness) is changed by a sinus over the hue.
XThe shape of this sinus can be addapted with
Xthe options -satmid, -satvar and -fase.
XThe value (blackness) is fixed and can be set with the option -value.
XThe default values are: 
X\fIfloatbg -value .87 -satmid .375 -satvar .125 -fase .25\fP,
Xand are such that all pastel tints are visited.
X.SH BUGS
XFloatbg doesn't use any window, button or menu,
Xand it can only be stopped by killing it.
X.SH AUTHOR
XJan Rekers \- rekers at cwi.nl
________This_Is_The_END________
if test `wc -l < floatbg.man` -ne 39; then
	echo 'shar: floatbg.man was damaged during transit (should have been 39 bytes)'
fi
fi		; : end of overwriting check
exit 0



More information about the Comp.sources.x mailing list