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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| #include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include "header.h"
int main(int argc, char *argv[])
{
srand(time(NULL));
int mabscisse[TAILLE]={0};
int mordonnee[TAILLE]={0};
obtenirSimulation(mabscisse, mordonnee);
initSDL();
SDL_WM_SetCaption("Fractale", NULL);
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
int i;
for (i = 0; i < TAILLE; i++)
{
int x, y;
x=mabscisse[i];
y=mordonnee[i];
if (x<640 && x>0 && y <480 && y>0)
{
setPixel(x, y, SDL_MapRGB(ecran->format, 0, 0, 0));
}
}
actualiser();
attendreTouche();
return EXIT_SUCCESS;
system("PAUSE");
return 0;
}
/* Les fonctions ci-dessous sont relatives à SDL ; je les ai copiées sur un tuto du site. Ce sont celles-ci que je ne parviens pas à mettre dans un fichier "annexe" */
void initSDL(void)
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "Erreur à l'initialisation de la SDL : %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
atexit(SDL_Quit);
ecran = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
if (ecran == NULL) {
fprintf(stderr, "Impossible d'activer le mode graphique : %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
}
void setPixel(int x, int y, Uint32 coul)
{
*((Uint32*)(ecran->pixels) + x + y * ecran->w) = coul;
}
void actualiser(void)
{
SDL_UpdateRect(ecran, 0, 0, 0, 0);
}
void attendreTouche(void)
{
SDL_Event event;
do
SDL_WaitEvent(&event);
while (event.type != SDL_QUIT && event.type != SDL_KEYDOWN);
} |
Partager