What Computer Programmers Do When They Take Lsd

Discussion in 'Computers and The Internet' started by AceK, Jun 24, 2016.

  1. AceK

    AceK Scientia Potentia Est

    Messages:
    7,824
    Likes Received:
    958
    idk who wrote this garbage program here .. but it looks like something irq42 might write if they were also a phreak ... and maybe tripping .. but anyways ... oh i think it might be mentioning that you need sdl1.2-dev as a dependency ... but these little things are easy enough to figure out ;)
    Code:
    /******************************************************************************
     * Strobe is a simple program for creating a strobe effect between 2 colors.
     * Different frequencies entrain brainwaves to evoke an altered state of 
     * consiousness in the user.
     * 
     * Author: phr34k 2015
     *
     * Additional comments: hasn't been touched until now, except to say that you
     * run this at your own risk, and that the code is very poor and will rape ur
     * display ... and you know ... do we really need to hit each pixel like that..
     * but we wouldn't want any special pixel to feel ya know .. not quite special 
     * ;) .. but other than that it does what its supposed to do              *^_^*
     * ***************************************************************************/
    
    #include <SDL/SDL.h>
    #include <stdlib.h>
    #include <string.h>
    #include <stdio.h>
    #include <unistd.h>
    #include <assert.h>
    
    #define HRES 1024
    #define VRES 768
    #define NCOLORS 2
    #define MAXFPS 400
    
    Uint16 create_hicolor_pixel(SDL_PixelFormat * fmt, Uint8 red, Uint8 green,
    			  Uint8 blue)
    {
        Uint16 value;
        /* This series of bit shifts uses the information from the SDL_Format
         * structure to correctly compose a 16-bit pixel value from 8-bit RGB */
        value = ((red  >> fmt->Rloss) << fmt->Rshift) +
    	    ((green >> fmt->Gloss) << fmt->Gshift) 	  +
    	    ((blue  >> fmt->Bloss) << fmt->Bshift);
    	    
        return value;
    }
    
    int getargs(int argc, char **argv, int *fps, Uint32 *rgb_color)
    {
    	int error = 0;
    	/* Command line args */
    	if (argc < 4) {
    		fprintf(stderr, "Too few parameters.\n");
    		error = 1;
    	} else if (argc > 4) {
    		fprintf(stderr, "Too many parameters.\n");
    		error = 1;
    	} else {
    		char *endptr;
    		
    		*fps = (int) strtol(*++argv, &endptr, 0);
    		if (endptr == *(argv - 1) || (*fps < 1 || *fps > MAXFPS)) {
    			fprintf(stderr, "Bad frequency value. Try values between 1 - %d\n",
    					MAXFPS);
    			error = 1;
    		}
    		
    		rgb_color[0] = (Uint32) strtol(*++argv, &endptr, 16);
    		if ((endptr == *(argv - 1)) || (rgb_color[0] < 0) || 
    									 (rgb_color[0] > 0xffffff)) {
    			fprintf(stderr, "Bad color value. Must be valid 24bit RGB hex\n");
    			error = 1;
    		}
    		
    		rgb_color[1] = (Uint32) strtol(*++argv, &endptr, 16);
    		if ((endptr == *(argv - 1)) || (rgb_color[1] < 0) || 
    									 (rgb_color[1] > 0xffffff)) {
    			fprintf(stderr, "Bad color value. Must be valid 24bit RGB hex\n");
    			error = 1;
    		}
    	}
    	
    	return error;
    }
    
    void showusageinfo(char *prgname)
    {
    	printf("\nUsage: %s [freq] [color1] [color2]\n\n", prgname);
    	
    	printf("Strobe is a simple program that uses the users monitor to implement a\n"
    		"strobe light effect. The user can set the flash frequency and the two\n"
    		"colors to flash between by passing these to strobe as command line\n"
    		"arguments. Strobe uses the SDL library, and currently displays in\n"
    		"hi-color (16bit) mode. User entered color values are automatically\n"
    		"composed into the correct hi-color format for the user's system.\n\n");
    		
    	printf("The first parameter is the strobe rate (frequency) in hertz or cycles\n"
    		"per second. This parameter takes a decimal value from 1 to MAXFPS.\n"
    		"Flash rates higher than your monitors refresh rate will probably not\n"
    		"display correctly. You may also be limited by the speed of your machine's"
    		"\n\nCPU and video card.\n");
    		
    	printf("The second two parameters shall be 24bit RGB hexadecimal values for\n"
    		"color1 and color2 respectively such as 0xffffff for white, and\n"
    		"0xffff00 for yellow. As of version 0.1 common names of colors are\n"
    		"not supported.\n\n");
    	
    	printf("An example for running strobe at a 15hz strobe rate, with yellow and\n"
    		"a turquois shade of blue as color1 and color2, respectively:\n\n"
    		"strobe 15 0xffff00 0x0080ff\n\n");
    		
    	printf("Pressing the 'ESC' key, or the 'q' key while strobe is running will\n"
    		   "safely exit from the program.\n\n");
    		   
    	printf("Invoke strobe as %s -t [freq] to run strobe in testing mode.\n"
    		"In testing mode, strobe will output on standard error the current\n"
    		"frame number, the execution time for the current frame, and the\n"
    		"average framerate\n\n", prgname);
    }
    
    int main(int argc, char **argv)
    {
        SDL_Surface *screen;
    	SDL_Event	event;
        Uint16 	*scr_pixels;
    	Uint16 	hicolor_color[NCOLORS];
    	Uint32 	rgb_color[NCOLORS];
    	int		coloridx = 0;
    	int x, y, i;
    	int quit = 0, test = 0;
    	int fps, t, framecnt = 0;
    	
    	if (argc > 1 && strcmp(argv[1], "-h") == 0) {
    		showusageinfo(*argv);
    		exit(EXIT_SUCCESS);
    	} else if (argc == 3 && strcmp(argv[1], "-t") == 0) {
    		test = 1;
    	}
    	
    	if (!test && getargs(argc, argv, &fps, rgb_color) != 0) {
    		printf("Usage: %s [freq] [color1] [color2]\n"
    			   "       %s -h to see help info for this program.\n\n",
    			   *argv, *argv);
    		exit(EXIT_FAILURE);
    	} else if (test && argc == 3) {
    		rgb_color[0] = 0xffffff;
    		rgb_color[1] = 0x000000;
    		fps = atoi(argv[2]);
    		if (fps < 1) {
    			fprintf(stderr, "E: framerate cannot be negative.\n");
    			exit(EXIT_FAILURE);
    		}
    	}
    	
        /* Init SDL */
        if (SDL_Init(SDL_INIT_VIDEO) != 0) {
    		fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
    		return 1;
        }
    
        atexit(SDL_Quit);
    	
    	(void) SDL_ShowCursor(SDL_DISABLE);
    	SDL_WM_SetCaption("Strobe", "Strobe");
        
        screen = SDL_SetVideoMode(HRES, VRES, 16, SDL_HWSURFACE  |
    					      SDL_DOUBLEBUF  |
    					      SDL_FULLSCREEN );
        if (screen == NULL) {
    		fprintf(stderr, "Unable to set video mode: %s\n", SDL_GetError());
    		exit(EXIT_FAILURE);
        }
    	
    	/*Initialize hicolor colors*/
    	for (i = 0; i < NCOLORS; ++i) {
    		hicolor_color[i] = create_hicolor_pixel(screen->format,
    					(rgb_color[i] & 0xff0000) >> 16,
    					(rgb_color[i] & 0xff00)   >> 8,
    					(rgb_color[i] & 0xff)     >> 0);
    	}
        
        /* Get a pointer to the video surface's memory. */
        scr_pixels = (Uint16*) screen->pixels;
    
        while (!quit) {
    		t = SDL_GetTicks();
    		if (SDL_PollEvent(&event)) {
    			switch (event.type) {
    				case SDL_QUIT:
    					quit = 1;
    					break;
    				case SDL_KEYDOWN:
    					switch (event.key.keysym.sym) {
    						case SDLK_ESCAPE:
    						case SDLK_q:
    							quit = 1;
    							break;
    					}
    					break;
    			}
    		}
    	
    		SDL_LockSurface(screen);
    		coloridx ^= 1;
    		for(x = 0; x < HRES; ++x) {
    			for(y = 0; y < VRES; ++y) {
    				int offset;
    				
    				offset = (screen->pitch / sizeof hicolor_color[0]) * y + x;
    				scr_pixels[offset] = hicolor_color[coloridx];
    			}
    		}
    		SDL_UnlockSurface(screen);
    		SDL_Flip(screen);
    		
    		assert(SDL_GetTicks() > t);
    		if ((t = SDL_GetTicks() - t) < 1000 / fps) {
    			if (test) {
    				/* Why does this fix fps/gargabe issue? */
    				fprintf(stderr, "frame:%d, t:%d, fps (average): %g\n",
    						++framecnt, t, 1000.0f / ((float) SDL_GetTicks() /
    						framecnt));
    						
    			}
    			SDL_Delay((1000 / fps) - t);
    		} else {
    			if (test) {
    				fprintf(stderr, "frame: %d, t:%d, fps (avgerage): %g,  "
    								"[t >= %d]!\n", 
    						++framecnt, t, 1000.0f / ((float) SDL_GetTicks() /
    						framecnt), 1000/fps); 
    			}
    		}
        }
        
        exit(EXIT_SUCCESS);
    }
    
     
    1 person likes this.
  2. tumbling.dice

    tumbling.dice Visitor

    How do I get this to run on my laptop?
     
  3. AceK

    AceK Scientia Potentia Est

    Messages:
    7,824
    Likes Received:
    958
    compile it with your C compiler of choice. I usually go with GCC. as far as as any MSVC in other words MICROSOFT fuckery .. idk. except i know that the code is cross platform. as far as compiling it as a WIN32 binary .. well idk because i hate Microsoft and try not to have to fuck with their software unless i absolutely have to (but they like feel like they ought be able to fuck with mine lol)

    install vmware ..any linux ... you pick the flavor ... and maybe ask someone who's not tripping for any more difficult questions than this (hint: person.this.istrippin.t < person.this.istrippin.t+86400) ;)
     
    1 person likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice