Advertisement
glokyfull

create table for circles of dots

Dec 18th, 2015
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <SDL/SDL.h>
  5.  
  6. Uint32 get_pixel32( SDL_Surface *surface, int x, int y );
  7. void put_pixel32( SDL_Surface *surface, int x, int y, Uint32 pixel );
  8. void putWord(char* table,int pos,int value);
  9. void pause();
  10.  
  11. int main(argc,argv)
  12. int argc;
  13. char **argv;
  14. {
  15. /*
  16. printf("hello je m'appelle vincent \n");
  17. printf("et j'aime les sushis\n");
  18. printf("argc: ");
  19. printf("%d",argc);
  20. printf("\n");
  21. int i=0;
  22. while (i<argc)
  23. {
  24. printf(argv[i]);
  25. printf("\n");
  26. i++;
  27. }
  28. */
  29. //printf("%f %f\n",sin(1.0),sin(3.14159265358979/2.0));
  30.  
  31. SDL_Surface *ecran = NULL, *rectangle = NULL;
  32. SDL_Rect position;
  33. SDL_Init(SDL_INIT_VIDEO);
  34. ecran = SDL_SetVideoMode(640,480,32,SDL_HWSURFACE);
  35. SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format,17,206,112));
  36. rectangle = SDL_CreateRGBSurface(SDL_HWSURFACE,320,200,32,0,0,0,0);
  37. SDL_FillRect(rectangle,NULL,SDL_MapRGB(ecran->format,0,0,0));
  38.  
  39.  
  40. position.x=0;position.y=0;
  41.  
  42. SDL_BlitSurface(rectangle,NULL,ecran,&position);
  43.  
  44. double angle;
  45. double xx,yy;
  46. Uint32 color=SDL_MapRGB(ecran->format,0,0,255);
  47. Uint32 color2=SDL_MapRGB(ecran->format,255,255,255);
  48. int i,g,x,y;
  49. double taille;
  50. for(g=0;g<64;g++)
  51. {
  52. taille = (64-g);
  53. for(i=0;i<256;i++)
  54. {
  55.  
  56. angle = i*3.14159265358979/128;
  57. x = (int)(16+64+cos(angle)*taille);
  58. y = (int)(16+64+sin(angle)*taille);
  59. //x =(int) xx;
  60. //y =(int) yy;
  61. if ((i) % 16 == 0)
  62. {
  63. put_pixel32(rectangle,x,y,SDL_MapRGB(ecran->format,0,255,255));
  64. } else
  65. //put_pixel32(rectangle,x,y,SDL_MapRGB(ecran->format,80,25,90));
  66. {
  67.  
  68. }
  69. }
  70. }
  71. int h,ofs;
  72. ofs=0;
  73. char mytable[4*512];
  74.  
  75.  
  76. taille = 32767;
  77. for (h=0;h<8;h++)
  78. {
  79. for(i=0;i<32;i++)
  80. {
  81.  
  82. angle = (i*8+h)*3.14159265358979/128;
  83. x = (int)(cos(angle)*taille);
  84. y = (int)(sin(angle)*taille);
  85.  
  86. putWord(mytable,ofs,x);
  87. putWord(mytable,ofs+1,y);
  88. ofs+=2;
  89.  
  90. }
  91.  
  92. }
  93. FILE* fichier = NULL;
  94.  
  95.  
  96. SDL_BlitSurface(rectangle,NULL,ecran,&position);
  97.  
  98. SDL_Flip(ecran);
  99.  
  100. fichier = fopen("cercle.dat","w");
  101. for (i=0;i<256*4;i++)
  102. {
  103. fputc(mytable[i],fichier);
  104. }
  105. fclose(fichier);
  106.  
  107. ofs=0;
  108. taille = 32767;
  109. for (h=0;h<16;h++)
  110. {
  111. for(i=0;i<32;i++)
  112. {
  113.  
  114. angle = (i*16+h)*3.14159265358979/256;
  115. x = (int)(cos(angle)*taille);
  116. y = (int)(sin(angle)*taille);
  117.  
  118. putWord(mytable,ofs,x);
  119. putWord(mytable,ofs+1,y);
  120. ofs+=2;
  121.  
  122. }
  123.  
  124. }
  125.  
  126.  
  127. fichier = fopen("cerc512.dat","w");
  128. for (i=0;i<512*4;i++)
  129. {
  130. fputc(mytable[i],fichier);
  131. }
  132. fclose(fichier);
  133.  
  134.  
  135.  
  136.  
  137.  
  138. ofs=0;
  139. for (i=0;i<512;i++)
  140. {
  141. putWord(mytable,ofs,(int) (sin(i*3.14159265358979/256)*32767));
  142. ofs+=1;
  143. }
  144. fichier=fopen("sinwave.dat","w");
  145. for (i=0;i<1024;i++)
  146. {
  147. fputc(mytable[i],fichier);
  148. }
  149. fclose(fichier);
  150.  
  151.  
  152. ofs=0;
  153. for (i=0;i<512;i++)
  154. {
  155. putWord(mytable,ofs,2*((int) (99*cos(i*3.14159265358979/256)+100)));
  156. ofs+=1;
  157. }
  158. fichier=fopen("cosinus","w");
  159. for (i=0;i<1024;i++)
  160. {
  161. fputc(mytable[i],fichier);
  162. }
  163. fclose(fichier);
  164.  
  165.  
  166. ofs=0;
  167. for (i=0;i<512;i++)
  168. {
  169. putWord(mytable,ofs,2*((int) (99*sin(i*3.14159265358979/256)+100)));
  170. ofs+=1;
  171. }
  172. fichier=fopen("sinus","w");
  173. for (i=0;i<1024;i++)
  174. {
  175. fputc(mytable[i],fichier);
  176. }
  177. fclose(fichier);
  178.  
  179.  
  180.  
  181.  
  182.  
  183. pause();
  184. SDL_FreeSurface(rectangle);
  185. SDL_Quit();
  186.  
  187.  
  188. }
  189.  
  190. Uint32 get_pixel32( SDL_Surface *surface, int x, int y )
  191. {
  192. //Convert the pixels to 32 bit
  193. Uint32 *pixels = (Uint32 *)surface->pixels;
  194. //Get the requested pixel
  195. return pixels[ ( y * surface->w ) + x ]; }
  196.  
  197. void put_pixel32( SDL_Surface *surface, int x, int y, Uint32 pixel )
  198. {
  199. //Convert the pixels to 32 bit
  200. Uint32 *pixels = (Uint32 *)surface->pixels;
  201. //Set the pixel
  202. pixels[ ( y * surface->w ) + x ] = pixel;
  203. }
  204.  
  205. void putWord(char* table,int pos,int value)
  206. {
  207. table[pos*2]=(char)(((value+65536)/256) & 255);
  208. table[pos*2+1]=(char)(value & 255);
  209. }
  210. void pause()
  211. {
  212. int continuer=1;
  213. SDL_Event event;
  214. SDL_Surface *toto=NULL;
  215.  
  216. int px=0;
  217. int vx=1;
  218.  
  219. toto= SDL_CreateRGBSurface(SDL_HWSURFACE,5,5,32,0,0,0,0);
  220.  
  221. while (continuer)
  222. {
  223. SDL_WaitEvent(&event);
  224. switch(event.type)
  225. {
  226. case SDL_QUIT:
  227. continuer=0;
  228. }
  229.  
  230. }
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement