/* gcc -o psycho psycho.c -I/usr/X11R6/include -L/usr/X11R6/lib -lX11 -lXext -lXxf86vm -lm */ #include #include "SDL.h" #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #define GAMMA_COMPONENTS 3 #define GAMMA_RESOLUTION 256 /* * Ben Winslow - 9/28/2001 * * Modified Fri Sep 28 20:16:59 CDT 2001 by Zinx Verituse - Psychadelic color cycling :P */ unsigned short ramp_in[GAMMA_COMPONENTS][GAMMA_RESOLUTION]; void cleanup(void) { SDL_SetGammaRamp(ramp_in[0], ramp_in[1], ramp_in[2]); exit(0); } int main(int argc, char *argv[]) { Uint16 ramp_out[GAMMA_COMPONENTS][GAMMA_RESOLUTION]; int x, y; int n[GAMMA_COMPONENTS], nd[GAMMA_COMPONENTS], nt[GAMMA_COMPONENTS]; SDL_Event event; SDL_Init(SDL_INIT_VIDEO); SDL_SetVideoMode(32, 32, 0, 0); srand(time(NULL)+getpid()); for (x = 0; x < GAMMA_COMPONENTS; x++) { n[x] = rand()%360; nd[x] = (rand()&1)?-1:1; nt[x] = rand()%720 + 100; } for (;;) { for (x = 0; x < GAMMA_COMPONENTS; x++) { for (y = 0; y < GAMMA_RESOLUTION; y++) { double t = (double)(y-GAMMA_RESOLUTION/2) / (double)(GAMMA_RESOLUTION/2); t = cos((t*M_PI) + ((n[x]*M_PI)/180.0)); ramp_out[x][y] = (t * 32767) + 32767; } if (--nt[x] < 0) { nd[x] = -nd[x]; nt[x] = rand()%720 + 100; } n[x] += nd[x]; if (n[x] < 0) n[x] += 360; else if (n[x] >= 360) n[x] -= 360; } if (SDL_SetGammaRamp(ramp_out[0], ramp_out[1], ramp_out[2]) < 0){ printf("%s\n", SDL_GetError()); sleep(1); return 1; } SDL_Delay(10); while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_q) cleanup(); break; } } } /* Not reached */ }