Guest User

Untitled

a guest
Jan 19th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. #include <SDL/SDL.h>
  2. #include <stdio.h>
  3.  
  4. void maluj(SDL_Surface *okno,int x, int y, int w, int h, int R, int G, int B)
  5. {
  6. SDL_Rect prostokat;
  7. prostokat.x=x;
  8. prostokat.y=y;
  9. prostokat.w=w;
  10. prostokat.h=h;
  11. SDL_FillRect(okno,&prostokat,SDL_MapRGB(okno->format,R,G,B));
  12. SDL_UpdateRect(okno,x,y,w,h);
  13. return;
  14. }
  15.  
  16.  
  17. int main(int argc,char *argv[])
  18. {
  19.  
  20. SDL_Surface *okno;
  21.  
  22. if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER))
  23. {
  24. printf("%s\n",SDL_GetError());
  25. }
  26.  
  27. else
  28. {
  29. okno=SDL_SetVideoMode(640,480,32,SDL_ANYFORMAT);
  30. if(!okno)
  31. {
  32. printf("%s\n",SDL_GetError());
  33. }
  34.  
  35. else
  36. {
  37.  
  38. SDL_WM_SetCaption("dupa","dupa"); //nazwa okna
  39.  
  40. /*
  41. Wyswietlo na ekranie czone, przechodzi w biole i sie zmniejszo
  42. int R=255,G=255,B=255;
  43. int x=0,y=0;
  44. int w=100, h=100;
  45.  
  46. for(;R>=0;R--,G--,B--,x++,y++,w+=2,h+=2)
  47. {
  48. maluj(okno,x,y,w,h,R,G,B);
  49.  
  50. SDL_Delay(10);
  51. }
  52.  
  53.  
  54. int koniec=0;
  55.  
  56. SDL_Event komunikat;
  57.  
  58. while((!koniec)&&(SDL_WaitEvent(&komunikat)))
  59. {
  60. if(komunikat.type==SDL_QUIT)
  61. {
  62. koniec=~0; //inaczej koniec=1, to samo w sumie
  63. }
  64. }
  65. */
  66.  
  67. int R=255,G=255,B=255;
  68. int x=0,y=0;
  69. int w=100, h=100;
  70. int koniec=0;
  71.  
  72. SDL_Event komunikat;
  73.  
  74. while(!koniec)
  75. {
  76. if(SDL_PollEvent(&komunikat)&&(komunikat.type==SDL_QUIT))
  77. {
  78. koniec=1;
  79. }
  80. R=rand()%256;
  81. G=rand()%256;
  82. B=rand()%256;
  83. x=rand()%640;
  84. y=rand()%480;
  85. w=rand()%640;
  86. h=rand()%480;
  87.  
  88. maluj(okno,x,y,w,h,R,G,B);
  89.  
  90.  
  91.  
  92. SDL_FreeSurface(okno);
  93. }
  94.  
  95.  
  96.  
  97.  
  98. SDL_Quit();
  99. }
  100. return 0;
  101. }
  102. }
Add Comment
Please, Sign In to add comment