home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: alt.sources
- Path: wupost!sdd.hp.com!decwrl!ampex!gregory
- From: gregory@ampex.com (Gregory Bloom)
- Subject: openlook sun4/60 cgthree color background animator (01/01)
- Message-ID: <1991Aug26.231153.7315@ampex.com>
- Summary: provides color animation for backgrounds loaded with xloadimage
- Keywords: fun, hypnotic, psychedelic, productivity enhancement
- Organization: Ampex Corporation, Golden, CO
- Date: Mon, 26 Aug 1991 23:11:53 GMT
-
-
- Following are two programs that provide a nice color animated background
- for users of openlook on color sun4s. I have only tested this on my
- sun 4/60 with cgthree0. It has a little problem with old sunview applications
- (it animates them, too).
-
- The first program, bloom.c, creates a color gradient rasterfile which
- you can load onto your background using xsetbg (xloadimage). If you
- don't yet have xloadimage, ask your local net guru where you can
- get it.
-
- The second program, phaze.c, opens your frame buffer, examines your
- colormap for gradient colors, then animates those colors it finds.
-
- You can easily hack bloom.c to provide a wide variety of interesting
- color animated backgrounds.
-
- I don't have shar, so y'all are going to have to search for the --cut here--
- marks.
-
-
- Have fun.
-
-
-
- --------------------------------cut here------------------------------------
-
-
- /*/--------------------------------*\
- /* bloom.c create bloom.gr8 |
- /* |
- /* usage: |
- /* cc -o bloom bloom.c -lm |
- /* bloom |
- /* xsetbg bloom.gr8 |
- /* phaze & |
- /* |
- /* bloom creates a 1152 x 900 grey-|
- /* gradient image which has colors |
- /* r = color number, g = r + 1, |
- /* b = r + 2 for its colormap |
- /* which you may use xloadimage |
- /* to set as your background |
- /* and then animate using phaze |
- /* |
- /* Gregory Bloom 1991 |
- /* |
- /* gregory@ampex.com |
- /*\--------------------------------*/
-
- #include <rasterfile.h>
- #include <ctype.h>
- #include <stdio.h>
- #include <math.h>
-
- #define COLORINCREMENT (.01)
- #define ITERATIONS 30
- #define COLORCOUNT 128
-
- #define RAS_MAGIC 0x59a66a95
- #define TWO_PI (6.283185307)
-
- /* ordered dither table */
- int dit[8][8] = {
- 0, 32, 8, 40, 2, 34, 10, 42,
- 48, 16, 56, 24, 50, 18, 58, 26,
- 12, 44, 4, 36, 14, 46, 6, 38,
- 60, 28, 52, 20, 62, 30, 54, 22,
-
- 3, 35, 11, 43, 1, 33, 9, 41,
- 51, 19, 59, 27, 49, 17, 57, 25,
- 15, 47, 7, 39, 13, 45, 5, 37,
- 63, 31, 55, 23, 61, 29, 53, 21
- };
-
- struct rasterfile ras;
-
- unsigned shift_reg;
- unsigned char screen[900][1152];
-
- main(argc, argv)
- int argc;
- char **argv;
- {
- FILE *fo;
- double x, y, dx, dy;
- int count, pass;
- int color, ran;
- unsigned char map[256], remap[256];
- double color_float;
- double floor (), frand ();
- double sin (), cos ();
- double fabs ();
-
- color_float = 0.0;
-
- x = 0;
- y = 0;
-
- color = 0;
-
- srandom (time (0));
-
- /* choose random initial velocity */
- for (dx = 0.0, dy = 0.0; dx == 0.0 && dy == 0.0;)
- {
- dx = (frand () / 5.0 + .1) - (frand () / 5.0 + .1);
- dy = (frand () / 5.0 + .1) - (frand () / 5.0 + .1);
- }
-
-
- printf ("countdown:\n");
- for (pass = 0; pass < ITERATIONS; pass++)
- {
- printf ("%d\n", ITERATIONS - pass);
-
- /* each pass is 1152 * 900 pixels */
- for (count = 0; count < 1036800; count++)
- {
- ran = random ();
-
- /* random walk + velocity */
- x += (double)((ran & 1) - ((ran & 2) == 0)) + dx;
- y += (double)(((ran & 4) == 0) - ((ran & 8) == 0)) + dy;
-
- /* if offscreen, start again in center with new velocity */
- if (x < 0.0 || x >= 1152.0 || y < 0.0 || y >= 900.0)
- {
- for (dx = 0.0, dy = 0.0;
- fabs (dx) <= 0.02 && fabs (dy) <= 0.02;)
- {
- dx = (frand () / 5.0 + .1) - (frand () / 5.0 + .1);
- dy = (frand () / 5.0 + .1) - (frand () / 5.0 + .1);
- }
-
- /* reset to center */
- x = 1152.0 / 2.0;
- y = 900.0 / 2.0;
-
- /* same starting color */
- color_float = 0.0;
- }
-
-
- color_float += COLORINCREMENT;
-
- /* dither color fraction */
- color = (int)color_float +
- ((int)(64.0 * (color_float - floor (color_float))) >
- dit[(int)y & 7][(int)x & 7]);
- color %= COLORCOUNT;
-
- screen[(int)y][(int)x] = color;
- }
- }
-
-
- /* see rasterfile man page to figure this out */
- ras.ras_magic = RAS_MAGIC;
- ras.ras_width = 0x480;
- ras.ras_height = 0x384;
- ras.ras_depth = 0x08;
- ras.ras_length = 0xfd200;
- ras.ras_type = RT_STANDARD;
- ras.ras_maptype = RMT_EQUAL_RGB;
- ras.ras_maplength = 3 * COLORCOUNT;
-
- fo = fopen("bloom.gr8", "w");
-
- putw (ras.ras_magic, fo);
- putw (ras.ras_width, fo);
- putw (ras.ras_height, fo);
- putw (ras.ras_depth, fo);
- putw (ras.ras_length, fo);
- putw (ras.ras_type, fo);
- putw (ras.ras_maptype, fo);
- putw (ras.ras_maplength, fo);
-
- /* create easily recognizable grey colormap */
- for (color = 0; color < COLORCOUNT; color++)
- {
- putc (color, fo);
- }
- for (color = 0; color < COLORCOUNT; color++)
- {
- putc (color + 1, fo);
- }
- for (color = 0; color < COLORCOUNT; color++)
- {
- putc (color + 2, fo);
- }
-
-
- /* output */
- for (y = 0; y < 900; y++)
- {
- for (x = 0; x < 1152; x++)
- {
- putc (screen[(int)y][(int)x], fo);
- }
- }
- printf ("bloom.gr8 created\n");
- }
-
- double
- frand ()
- {
- return ((double) (random ()) / 2147483647.0);
- }
-
-
-
- --------------------------------cut here------------------------------------
-
-
-
- /*/--------------------------------*\
- /* phaze.c animate desktop colors |
- /* |
- /* usage on sun 4/60 with cgthree0:|
- /* cc -o phaze phaze.c -lpixrect |
- /* xsetbg <file.gr8> (ie bloom.gr8)|
- /* phaze & |
- /* |
- /* you need to have loaded a grey- |
- /* gradient image which has colors |
- /* r = color number, g = r + 1, |
- /* b = r + 2 for its colormap |
- /* |
- /* Gregory Bloom 1991 |
- /* |
- /* phaze is tuneware: (p-haze?) |
- /* I don't care what you do with it|
- /* but if you have a CD of obscure |
- /* tunes you think I should have, |
- /* lemme know about it. Or, if the|
- /* disk is just cluttering up your |
- /* shelf, feel free to send it! |
- /* |
- /* gregory@ampex.com |
- /* |
- /* Gregory Bloom |
- /* 11540 West 100th Place |
- /* Broomfield, CO 80021 |
- /* |
- /*\--------------------------------*/
-
- #include <pixrect/pixrect_hs.h>
- #include <stdio.h>
-
- #define MAX_FREQUENCY 32
- #define HELL_SLOWLY_FREEZES_OVER 1
-
- main (argc, argv)
- int argc;
- char **argv;
- {
- Pixrect *screen;
- int rb, gb, bb;
- int rs, gs, bs;
- int rt, gt, bt;
- int pause;
- int index, back_index, count, maplen;
- int step, sweep, value;
- int r_index, g_index, b_index;
- int r_flip, g_flip, b_flip;
- unsigned char ranbyte;
-
- unsigned char sr[257], sg[257], sb[257];
- int remap[256];
- unsigned char rcolor[2 * 256 * MAX_FREQUENCY + 256];
- unsigned char gcolor[2 * 256 * MAX_FREQUENCY + 256];
- unsigned char bcolor[2 * 256 * MAX_FREQUENCY + 256];
-
- int r_offset, g_offset, b_offset;
- int mapCount;
-
-
- /* init random */
- srandom (time (0));
-
-
- /* access screen */
- screen = pr_open("/dev/fb");
-
- index = 0;
- value = 0;
-
- /* set up random colormap with each r, g, and b ramp frequency */
- for (step = 1; step <= MAX_FREQUENCY; step++)
- {
- for (sweep = 0; sweep < (MAX_FREQUENCY - step); sweep++)
- {
- value += step;
-
- rcolor[index] = value;
- gcolor[index] = value;
- bcolor[index] = value;
- ++index;
- }
- }
-
- /* append backwards colormap */
- for (count = index - 1; count >= 0; count--)
- {
- rcolor[index] = rcolor[count];
- gcolor[index] = gcolor[count];
- bcolor[index] = bcolor[count];
- ++index;
- }
-
- /* append start of forward colormap for clean wrap */
- for (count = 0; count < 256; count++)
- {
- rcolor[index] = rcolor[count];
- gcolor[index] = gcolor[count];
- bcolor[index] = bcolor[count];
- ++index;
- }
-
- maplen = index;
-
-
- /* start each color phaze at a random offset into map sequence */
- r_offset = random () % maplen;
- g_offset = random () % maplen;
- b_offset = random () % maplen;
-
- /* each phaze starts running forward through colormap sequence */
- r_flip = 0;
- g_flip = 0;
- b_flip = 0;
-
- /* get current colormap */
- pr_getcolormap (screen, 0, 256, sr, sg, sb);
-
- /* default colors that are not ours off colormap */
- for (count = 0; count < 256; count++)
- remap[count] = 256;
-
- /* xloadimage sprays colors all through the colormap, so we need
- /* to find each slot that our colors have been assigned.
- /* for this reason, our colors are easily recognizable as:
- /* r = color number, g = r + 1, b = r + 2
- */
- mapCount = 0;
- for (count = 0; count < 256; count++)
- {
- /* is this one of our colors? */
- if (sr[count] == sg[count] - 1 &&
- sr[count] == sb[count] - 2 &&
- sr[count] < sg[count] &&
- sg[count] < sb[count])
- {
- ++mapCount;
-
- /* keep track of where this color was in the current colormap
- /* (r = color number)
- */
- remap[sr[count]] = count;
- }
- }
-
- while (HELL_SLOWLY_FREEZES_OVER)
- {
- /* step through colormap sequence */
- for (index = 0; index < maplen - MAX_FREQUENCY; index++)
- {
- /* back_index is for color phazes moving back thru sequence */
- back_index = maplen - MAX_FREQUENCY - index;
-
- r_index = ((r_flip ? back_index : index) + r_offset) % maplen;
- g_index = ((g_flip ? back_index : index) + g_offset) % maplen;
- b_index = ((b_flip ? back_index : index) + b_offset) % maplen;
-
- for (count = 0; count < 256; count++)
- {
- sr[remap[count]] = rcolor[r_index + count];
- sg[remap[count]] = gcolor[g_index + count];
- sb[remap[count]] = bcolor[b_index + count];
- }
-
- pr_putcolormap (screen, 0, 256, sr, sg, sb);
-
- /* go do something useful for a while */
- usleep (63000);
-
- }
-
- ranbyte = random () % 3;;
-
- /* after each pass, shift a color wrt the others, maybe reversing */
- switch (ranbyte)
- {
- case 0:
- r_offset = (r_offset + ((random () % 3) - 1) + maplen) % maplen;
- if (r_flip != r_offset & 0x01)
- {
- r_offset = (maplen - MAX_FREQUENCY) - r_offset;
- r_flip = (r_flip == 0);
- }
- break;
-
- case 1:
- g_offset = (g_offset + ((random () % 3) - 1) + maplen) % maplen;
- if (g_flip != g_offset & 0x01)
- {
- g_offset = (maplen - MAX_FREQUENCY) - g_offset;
- g_flip = (g_flip == 0);
- }
- break;
-
- case 2:
- b_offset = (b_offset + ((random () % 3) - 1) + maplen) % maplen;
- if (b_flip != b_offset & 0x01)
- {
- b_offset = (maplen - MAX_FREQUENCY) - b_offset;
- b_flip = (b_flip == 0);
- }
- break;
- }
- }
- }
-
-
-