/* gcc -o psycho psycho.c -I/usr/X11R6/include -L/usr/X11R6/lib -lX11 -lXext -lXxf86vm -lm */ #include #include #include #define GAMMA_COMPONENTS 3 #define M_PI 3.14159265358979323846 /* * Ben Winslow - 9/28/2001 * * Modified Fri Sep 28 20:16:59 CDT 2001 by Zinx Verituse - Psychadelic color cycling :P */ //WORD ramp_in[GAMMA_COMPONENTS][256]; DDGAMMARAMP ramp_in; HDC curdc = NULL; LPDIRECTDRAWGAMMACONTROL gamma; void sighand(int sig) { SetDeviceGammaRamp(curdc, ramp_in); exit(sig); } int main(int argc, char *argv[]) { WORD ramp_out[GAMMA_COMPONENTS][256]; int x, y; int n[GAMMA_COMPONENTS], nd[GAMMA_COMPONENTS], nt[GAMMA_COMPONENTS]; curdc = GetDC(NULL); printf("Fetch ramp\n"); if (GetDeviceGammaRamp(curdc, ramp_in) == FALSE) ;// return 1; signal(SIGSEGV, sighand); signal(SIGTERM, sighand); signal(SIGINT, sighand); printf("init rand\n"); 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; } printf("main loop\n"); for (;;) { for (x = 0; x < GAMMA_COMPONENTS; x++) { for (y = 0; y < 256; y++) { double t = (double)(y-256/2) / (double)(256/2); // t = cos((t*M_PI) + ((n[x]*M_PI)/180.0)); // t = cos((t*(M_PI+M_PI_2)) + ((n[x]*M_PI)/180.0)); t = cos((t*M_PI*0.8) + ((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; } printf("Set ramp\n"); for (x= 0; x < 3; x++) { ramp_out[x][0] = 0; ramp_out[x][255] = 65535; } if (SetDeviceGammaRamp(curdc, ramp_out) == FALSE) { LPVOID lpMsgBuf; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER| FORMAT_MESSAGE_FROM_SYSTEM| FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &lpMsgBuf, 0, NULL); printf("Failed: %s\n", lpMsgBuf); LocalFree(lpMsgBuf); // } else { for (x = 0; x< 3; x++) { printf("%d: ", x); for(y=0;y<256;y++) printf("%d ", ramp_out[x][y]); printf("\n"); } exit(0); } Sleep(10); } /* Not reached */ }