Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <SDL/SDL.h>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7.  
  8.     SDL_Surface *screen = NULL, *lines[600] = {NULL};
  9.     SDL_Rect position;
  10.     int i = 0;
  11.     int couleur1[3] = {0,0,0};
  12.     int couleur2[3] = {255,255,255};
  13.     int differences[3] = {0};
  14.     int r = 0, g = 0, b = 0;
  15.  
  16.     differences[0] = (couleur2[0] - couleur1[0]) / 600;
  17.     differences[1] = (couleur2[1] - couleur1[1]) / 600;
  18.     differences[2] = (couleur2[2] - couleur1[2]) / 600;
  19.  
  20.     SDL_Init(SDL_INIT_VIDEO);
  21.  
  22.     screen = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE);
  23.  
  24.     for (i; i < 600 ; i++)
  25.     {
  26.         lines[i] = SDL_CreateRGBSurface(SDL_HWSURFACE, 800, 1, 32, 0, 0, 0, 0);
  27.     }
  28.  
  29.     SDL_WM_SetCaption("Algo dégradé", NULL);
  30.  
  31.     SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 2, 114, 125));
  32.  
  33.     for (i = 0 ; i < 600 ; i++)
  34.     {
  35.  
  36.         r = couleur1[0] + (differences[0] * i);
  37.         g = couleur1[1] + (differences[1] * i);
  38.         b = couleur1[2] + (differences[2] * i);
  39.  
  40.         position.x = 0;
  41.         position.y = i;
  42.         SDL_FillRect(lines[i], NULL, SDL_MapRGB(screen->format, r, g, b));
  43.         SDL_BlitSurface(lines[i], NULL, screen, &position);
  44.     }
  45.  
  46.     SDL_Flip(screen);
  47.     sleep();
  48.  
  49.     for (i = 0 ; i <= 600 ; i++)
  50.         SDL_FreeSurface(lines[i]);
  51.  
  52.     SDL_Quit();
  53.  
  54.     return EXIT_SUCCESS;
  55. }
  56.  
  57. void sleep()
  58. {
  59.     int window = 1;
  60.     SDL_Event event;
  61.  
  62.     while (window)
  63.     {
  64.         SDL_WaitEvent(&event);
  65.         switch(event.type)
  66.         {
  67.             case SDL_QUIT:
  68.                 window= 0;
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement