1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| #include "output.h"
#include "temperature.h"
#include <math.h>
static void pause();
SDL_Surface* screen;
void maindraw(int m, int n)
{
init_output(m, n);
update_output( m, n);
}
void init_output(int m, int n)
{
if (SDL_Init(SDL_INIT_VIDEO < 0))
{
printf("ERROR : Initialisation SDL\n");
exit(-1);
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(m*10, // height in pixels
n*10, // width in pixels
32, // bits-per-pixel ** DONT TOUCH **
SDL_SWSURFACE // rendering mode ** DONT TOUCH **
);
if (screen == NULL)
{
printf("ERROR : Video Mode");
exit(EXIT_FAILURE);
}
SDL_WM_SetCaption("heat bugs",""); // window title
}
/* Peint les températures dans la grille. */
void update_output(int m, int n)
{
SDL_Rect position;
position.x = 0;
position.y = 0;
SDL_Surface* cellule = SDL_CreateRGBSurface(SDL_HWSURFACE, 10, 10, 32, 0, 0, 0, 0);
double max= maximum( m, n);
double min= minimum( m, n);
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
cellule = SDL_CreateRGBSurface(SDL_HWSURFACE, 10, 10, 32, 0, 0, 0, 0);
int tmp = floor(((get_temperature(i,j)-20)*255/(max-20)));
position.x = 10 * j;
position.y = 10 * i;
SDL_FillRect(cellule, NULL, SDL_MapRGB(screen->format, tmp, 0, 255-tmp)); // Colorie la cellule en fct de la temperature (rouge -> bleu)
SDL_BlitSurface(cellule, NULL, screen, &position);
SDL_Flip(screen); // Mise a jour de l'ecran
SDL_FreeSurface(cellule); // libere la surface
}
}
SDL_Quit;
} |
Partager