Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <SDL/SDL.h>
- Uint32 get_pixel32( SDL_Surface *surface, int x, int y );
- void put_pixel32( SDL_Surface *surface, int x, int y, Uint32 pixel );
- void putWord(char* table,int pos,int value);
- void pause();
- int main(argc,argv)
- int argc;
- char **argv;
- {
- /*
- printf("hello je m'appelle vincent \n");
- printf("et j'aime les sushis\n");
- printf("argc: ");
- printf("%d",argc);
- printf("\n");
- int i=0;
- while (i<argc)
- {
- printf(argv[i]);
- printf("\n");
- i++;
- }
- */
- //printf("%f %f\n",sin(1.0),sin(3.14159265358979/2.0));
- SDL_Surface *ecran = NULL, *rectangle = NULL;
- SDL_Rect position;
- SDL_Init(SDL_INIT_VIDEO);
- ecran = SDL_SetVideoMode(640,480,32,SDL_HWSURFACE);
- SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format,17,206,112));
- rectangle = SDL_CreateRGBSurface(SDL_HWSURFACE,320,200,32,0,0,0,0);
- SDL_FillRect(rectangle,NULL,SDL_MapRGB(ecran->format,0,0,0));
- position.x=0;position.y=0;
- SDL_BlitSurface(rectangle,NULL,ecran,&position);
- double angle;
- double xx,yy;
- Uint32 color=SDL_MapRGB(ecran->format,0,0,255);
- Uint32 color2=SDL_MapRGB(ecran->format,255,255,255);
- int i,g,x,y;
- double taille;
- for(g=0;g<64;g++)
- {
- taille = (64-g);
- for(i=0;i<256;i++)
- {
- angle = i*3.14159265358979/128;
- x = (int)(16+64+cos(angle)*taille);
- y = (int)(16+64+sin(angle)*taille);
- //x =(int) xx;
- //y =(int) yy;
- if ((i) % 16 == 0)
- {
- put_pixel32(rectangle,x,y,SDL_MapRGB(ecran->format,0,255,255));
- } else
- //put_pixel32(rectangle,x,y,SDL_MapRGB(ecran->format,80,25,90));
- {
- }
- }
- }
- int h,ofs;
- ofs=0;
- char mytable[4*512];
- taille = 32767;
- for (h=0;h<8;h++)
- {
- for(i=0;i<32;i++)
- {
- angle = (i*8+h)*3.14159265358979/128;
- x = (int)(cos(angle)*taille);
- y = (int)(sin(angle)*taille);
- putWord(mytable,ofs,x);
- putWord(mytable,ofs+1,y);
- ofs+=2;
- }
- }
- FILE* fichier = NULL;
- SDL_BlitSurface(rectangle,NULL,ecran,&position);
- SDL_Flip(ecran);
- fichier = fopen("cercle.dat","w");
- for (i=0;i<256*4;i++)
- {
- fputc(mytable[i],fichier);
- }
- fclose(fichier);
- ofs=0;
- taille = 32767;
- for (h=0;h<16;h++)
- {
- for(i=0;i<32;i++)
- {
- angle = (i*16+h)*3.14159265358979/256;
- x = (int)(cos(angle)*taille);
- y = (int)(sin(angle)*taille);
- putWord(mytable,ofs,x);
- putWord(mytable,ofs+1,y);
- ofs+=2;
- }
- }
- fichier = fopen("cerc512.dat","w");
- for (i=0;i<512*4;i++)
- {
- fputc(mytable[i],fichier);
- }
- fclose(fichier);
- ofs=0;
- for (i=0;i<512;i++)
- {
- putWord(mytable,ofs,(int) (sin(i*3.14159265358979/256)*32767));
- ofs+=1;
- }
- fichier=fopen("sinwave.dat","w");
- for (i=0;i<1024;i++)
- {
- fputc(mytable[i],fichier);
- }
- fclose(fichier);
- ofs=0;
- for (i=0;i<512;i++)
- {
- putWord(mytable,ofs,2*((int) (99*cos(i*3.14159265358979/256)+100)));
- ofs+=1;
- }
- fichier=fopen("cosinus","w");
- for (i=0;i<1024;i++)
- {
- fputc(mytable[i],fichier);
- }
- fclose(fichier);
- ofs=0;
- for (i=0;i<512;i++)
- {
- putWord(mytable,ofs,2*((int) (99*sin(i*3.14159265358979/256)+100)));
- ofs+=1;
- }
- fichier=fopen("sinus","w");
- for (i=0;i<1024;i++)
- {
- fputc(mytable[i],fichier);
- }
- fclose(fichier);
- pause();
- SDL_FreeSurface(rectangle);
- SDL_Quit();
- }
- Uint32 get_pixel32( SDL_Surface *surface, int x, int y )
- {
- //Convert the pixels to 32 bit
- Uint32 *pixels = (Uint32 *)surface->pixels;
- //Get the requested pixel
- return pixels[ ( y * surface->w ) + x ]; }
- void put_pixel32( SDL_Surface *surface, int x, int y, Uint32 pixel )
- {
- //Convert the pixels to 32 bit
- Uint32 *pixels = (Uint32 *)surface->pixels;
- //Set the pixel
- pixels[ ( y * surface->w ) + x ] = pixel;
- }
- void putWord(char* table,int pos,int value)
- {
- table[pos*2]=(char)(((value+65536)/256) & 255);
- table[pos*2+1]=(char)(value & 255);
- }
- void pause()
- {
- int continuer=1;
- SDL_Event event;
- SDL_Surface *toto=NULL;
- int px=0;
- int vx=1;
- toto= SDL_CreateRGBSurface(SDL_HWSURFACE,5,5,32,0,0,0,0);
- while (continuer)
- {
- SDL_WaitEvent(&event);
- switch(event.type)
- {
- case SDL_QUIT:
- continuer=0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement