Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <SDL/SDL.h>
- int main(int argc, char *argv[])
- {
- SDL_Surface *screen = NULL, *lines[600] = {NULL};
- SDL_Rect position;
- int i = 0;
- int couleur1[3] = {0,0,0};
- int couleur2[3] = {255,255,255};
- int differences[3] = {0};
- int r = 0, g = 0, b = 0;
- differences[0] = (couleur2[0] - couleur1[0]) / 600;
- differences[1] = (couleur2[1] - couleur1[1]) / 600;
- differences[2] = (couleur2[2] - couleur1[2]) / 600;
- SDL_Init(SDL_INIT_VIDEO);
- screen = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE);
- for (i; i < 600 ; i++)
- {
- lines[i] = SDL_CreateRGBSurface(SDL_HWSURFACE, 800, 1, 32, 0, 0, 0, 0);
- }
- SDL_WM_SetCaption("Algo dégradé", NULL);
- SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 2, 114, 125));
- for (i = 0 ; i < 600 ; i++)
- {
- r = couleur1[0] + (differences[0] * i);
- g = couleur1[1] + (differences[1] * i);
- b = couleur1[2] + (differences[2] * i);
- position.x = 0;
- position.y = i;
- SDL_FillRect(lines[i], NULL, SDL_MapRGB(screen->format, r, g, b));
- SDL_BlitSurface(lines[i], NULL, screen, &position);
- }
- SDL_Flip(screen);
- sleep();
- for (i = 0 ; i <= 600 ; i++)
- SDL_FreeSurface(lines[i]);
- SDL_Quit();
- return EXIT_SUCCESS;
- }
- void sleep()
- {
- int window = 1;
- SDL_Event event;
- while (window)
- {
- SDL_WaitEvent(&event);
- switch(event.type)
- {
- case SDL_QUIT:
- window= 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement