Guest User

Functions that do pretty things inside windows

a guest
Mar 16th, 2018
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 KB | None | 0 0
  1.  
  2. //function that returns random floats
  3. float frand() {
  4.     srand(time(NULL));
  5.     return (float)((rand() % 100 + 1) % (rand() % 10 + 1)) / 10;
  6. }
  7.  
  8. //function that does pretty things inside any window
  9. void illusion(SDL_Window *window) {
  10.     const int screen_width = 500;
  11.     const int screen_height = 500;
  12.     SDL_Renderer *renderer = SDL_CreateRenderer(window, 0, SDL_RENDERER_ACCELERATED);
  13.     SDL_Rect rectangle, rectangle2;
  14.     //default values
  15.     bool quit = false;
  16.    
  17.     double rect1_x = screen_width / 2, rect1_y = screen_height / 2, rect1_width = 5, rect1_height = 5;
  18.     double rect2_x = screen_width / 2, rect2_y = screen_height / 2, rect2_width = 5, rect2_height = 5;
  19.    
  20.     while (quit == false)
  21.     {
  22.  
  23.         float p = frand(), q = frand(), r = frand(), s = frand();
  24.         SDL_Event event;
  25.         while (SDL_PollEvent(&event))
  26.             if (event.type == SDL_QUIT) quit = true;
  27.         rectangle.x = rect1_x, rectangle.y = rect1_y, rectangle.h = rect1_height, rectangle.w = rect1_width;
  28.  
  29.         SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
  30.         SDL_RenderFillRect(renderer, &rectangle);
  31.         rect1_x -= p;
  32.         rect1_y -= q;
  33.         rect1_width += p*2;
  34.         rect1_height += q*2;
  35.         if (rect1_x < 0 || rect1_y < 0)
  36.         {
  37.             rect1_height = 0;
  38.             rect1_width = 0;
  39.             rect1_x = 0;
  40.             rect1_y = 0;
  41.             if (rect1_x < 250 || rect1_y < 250)
  42.             {
  43.                 rectangle2.x = rect2_x;
  44.                 rectangle2.y = rect2_y;
  45.                 rectangle2.h = rect2_height;
  46.                 rectangle2.w = rect2_width;
  47.  
  48.                 SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
  49.                 SDL_RenderFillRect(renderer, &rectangle2);
  50.                 rect2_x -= r;
  51.                 rect2_y -= s;
  52.                 rect2_width += 2*r;
  53.                 rect2_height += 2*s;
  54.             }
  55.         }
  56.         if (rect2_x < 0 || rect2_y < 0)
  57.         {
  58.             rect2_height = 0;
  59.             rect2_width = 0;
  60.             rect2_x = 250;
  61.             rect2_y = 250;
  62.             rect1_height = 5;
  63.             rect1_width = 5;
  64.             rect1_x = 250;
  65.             rect1_y = 250;
  66.             SDL_Delay(rand() % 10);
  67.         }
  68.         SDL_RenderPresent(renderer);
  69.     }
  70. }
  71.  
  72. /*
  73. YOU can randomize almost everything! colors! delays!! sprites!! shaders!!! :P
  74. shapes are tough to randomise, I am just a noob in sdl :(
  75. */
Add Comment
Please, Sign In to add comment