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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
| #include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <time.h>
#include <math.h>
#define TAILLE 250000
void initSDL(void);
void setPixel(int x, int y, Uint32 coul);
void actualiser(void);
void attendreTouche(void);
float produit_abscisse(float (*matrice)[2], float *colonne);
float produit_ordonnee(float (*matrice)[2], float *colonne);
int pileOuFace();
void convolution(float* preabscisse, float* preordonnee, float (*matriceA)[2], float *colonneA, float (*matriceB)[2], float *colonneB);
void transformation(float* preabscisse, float* preordonnee, int* abscisse, int* ordonnee);
void obtenirSimulation(int* abscisse, int* ordonnee);
SDL_Surface *ecran; /* Le pointeur qui va stocker la surface de l'écran */
int main(int argc, char *argv[])
{
srand(time(NULL));
float matriceA[2][2], matriceB[2][2];
float colonneA[2], colonneB[2];
matriceA[0][0]=0.839;
matriceA[0][1]=-0.303;
matriceA[1][0]=0.383;
matriceA[1][1]=0.924;
matriceB[0][0]=-0.161;
matriceB[0][1]=-0.136;
matriceB[1][0]=0.138;
matriceB[1][1]=-0.182;
colonneA[0]=0.232;
colonneA[1]=-0.08;
colonneB[0]=0.921;
colonneB[1]=0.178;
initSDL();
SDL_WM_SetCaption("Fractale", NULL);
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
int j;
float present[2];
present[0]=0;
present[1]=0;
int n;
int x, y;
for (j=0; j<TAILLE-1; j++)
{
n=pileOuFace();
if(n==1)
{
present[0]=produit_abscisse(matriceA, present)+colonneA[0];
present[1]=produit_ordonnee(matriceA, present)+colonneA[1];
}
else
{
present[0]=produit_abscisse(matriceB, present)+colonneB[0];
present[1]=produit_ordonnee(matriceB, present)+colonneB[1];
}
x=floor(640*(1-present[0]));
y=floor(480*(1-present[1]));
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;
}
float produit_abscisse(float (*matrice)[2], float *colonne)
{
float prod1;
prod1=(matrice[0][0] * colonne[0]) + (matrice[0][1] * colonne[1]);
return(prod1);
}
float produit_ordonnee(float (*matrice)[2], float *colonne)
{
float prod2;
prod2=matrice[1][0] * colonne[0] + matrice[1][1] * colonne[1];
return(prod2);
}
int pileOuFace()
{
if ((rand() % 100) <49)
{
return 1;
}
else
{
return 2;
}
}
/* 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