Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Written by Bini Michele <mibin@tin.it>, 1998
- */
- #include "os.h"
- #include "SDL/SDL.h"
- #include "math.h"
- #ifndef PI
- #define PI 3.14159265358979323846
- #endif
- #define VIDEOX SCREEN_WIDTH
- #define VIDEOY SCREEN_HEIGHT
- #define TABLEX VIDEOX*2
- #define TABLEY VIDEOY*2
- #define TONES 256
- int rands[512];
- int lastRandI = 0;
- static void do_plasma(SDL_Surface*surface,
- double x1,
- double y1,
- double x2,
- double y2,
- double x3,
- double y3,
- unsigned char*t)
- {
- unsigned int
- X1=x1*(TABLEX/2),
- Y1=y1*(TABLEY/2),
- X2=x2*(TABLEX/2),
- Y2=y2*(TABLEY/2),
- X3=x3*(TABLEX/2),
- Y3=y3*(TABLEY/2);
- unsigned int y;
- unsigned char *t1=t+X1+Y1*TABLEX, *t2=t+X2+Y2*TABLEX, *t3=t+X3+Y3*TABLEX;
- for (y=0; y<VIDEOY; y++) {
- unsigned x;
- unsigned char*tmp= ((Uint8*)surface->pixels) + y * surface->pitch;
- unsigned int t=y*TABLEX, tmax=t+VIDEOX;
- for (x=0; t<tmax; t++, tmp++) {
- tmp[0]=t1[t]+t2[t]+t3[t];
- }
- }
- }
- int main ()
- {
- Uint32 video_flags;
- double r[3];
- double R[6];
- SDL_Surface *screen;
- SDL_Color colors[TONES*2];
- unsigned char *t;
- time_t starttime;
- int i, state=0;
- t = (unsigned char *)malloc(TABLEY*TABLEX);
- if ( t == NULL ) {
- printf("Out of memory\n");
- exit(1);
- }
- startcrand(SDL_GetTicks(),9999999);
- printf("Precalculating table...\n");
- {
- int c;
- for (c=0; c<3; c++)
- r[c]=((double)(crand()%1000+1))/300000;
- for (c=0; c<6; c++)
- R[c]=((double)(crand()%1000+1))/5000;
- }
- {
- int y;
- for (y=0 ; y<TABLEY ; y++) {
- int x;
- for (x=0 ; x<TABLEX ; x++) {
- double tmp=(((double)((x-(TABLEX/2))*(x-(TABLEX/2))+(y-(TABLEX/2))*(y-(TABLEX/2))))
- *(PI/(TABLEX*TABLEX+TABLEY*TABLEY)));
- t[y*TABLEX+x]=(sin(sqrt(tmp)*12)+1)*TONES/6;
- }
- }
- }
- /* Inizialize the SDL library */
- if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
- fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
- return 1;
- }
- //atexit(SDL_Quit); // <---- This doesn't work
- screen=SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, NSP_BPP, SDL_SWSURFACE);
- if ( screen == NULL ) {
- fprintf(stderr, "Couldn't initialize video mode: %s\n", SDL_GetError());
- return 1;
- }
- /* Main loop */
- while (SDL_PollEvent(NULL)==0) {
- state++;
- {
- int c;
- int re,ge,be;
- /* for (c=0 ; c<TONES; c++) {
- re=(sin(((double)c)/TONES*6*PI+r[0]*PI*state*PI)+1)*127;
- ge=(sin(((double)c)/TONES*6*PI+r[1]*state*PI)+1)*127;
- be=(sin(((double)c)/TONES*6*PI+r[2]*state*PI)+1)*127;
- //colors[c] = SDL_MapRGB(screen->format, (Uint8)re, (Uint8)ge, (Uint8)be);
- }
- SDL_SetColors(screen, colors, 0, TONES); */ // <---- doensn't work on 16-bit
- }
- if (SDL_LockSurface(screen) <0 ) {
- continue;
- }
- do_plasma(screen,
- (sin(((double)state)*R[0])+1)/2,
- (sin(((double)state)*R[1])+1)/2,
- (sin(((double)state)*R[2])+1)/2,
- (sin(((double)state)*R[3])+1)/2,
- (sin(((double)state)*R[4])+1)/2,
- (sin(((double)state)*R[5])+1)/2, t);
- SDL_UnlockSurface(screen);
- SDL_Flip(screen);
- }
- return 0;
- }
- //RAND functions
- void startcrand(int seed, int max){
- printf("Starting pseudorandom number generator...\n");
- if(seed>max){
- printf("Oops: seed is bigger than max\n");
- exit(-1);
- }
- if(seed == 0){
- printf("Oops: seed is 0 - setting it to 1337\n");
- seed = 1337;
- }
- printf("Seed is ");
- printInt(seed);
- printf("\n");
- int a = 5; //multiplier
- int c = 3; //increment
- int i; //iterator
- printf("Generating random numbers.. \n");
- for(i=0; i<500; i++)
- {
- seed = (a * seed + c) % max;
- rands[i] = seed;
- }
- printf("Done!\n");
- }
- int crand(){
- if(lastRandI > 490)
- lastRandI = 2;
- lastRandI++;
- return rands[lastRandI];
- }
- void printInt(int n){
- char c[128];
- sprintf(c, "%d", n);
- const char* ccharAst;
- char* charAst;
- strcpy(charAst, c);
- ccharAst = charAst;
- printf(ccharAst);
- }
Add Comment
Please, Sign In to add comment