Accueil > > > Sierpinski\triangle.c
FRACTALE DE SIERPINSKI
Sierpinski\triangle.c
Informations sur ce code source
La fameuse fractale de Sierpinski...
Pas de commentaires :)
Fichier : Sierpinski\triangle.c
Nombre de lignes : 69 lignes
Afficher ce fichier en plein écran
- #include "triangle.h"
- void dessin(struct triangle* arbre,SDL_Surface* fenetre,SDL_Surface* px){
- int i;
- SDL_Rect pos;
- if(arbre->a!=NULL){
- dessin(arbre->a,fenetre,px);
- dessin(arbre->b,fenetre,px);
- dessin(arbre->c,fenetre,px);
- }
- else
- for(i=0; i<3; i++){
- pos=(SDL_Rect){arbre->point[i].x,arbre->point[i].y};
- SDL_BlitSurface(px,NULL,fenetre,&pos);
- }
- return;
- }
- void ramifier(struct triangle* fractale){
- struct coord* p=fractale->point;
- if(fractale->a!=NULL){
- ramifier(fractale->a);
- ramifier(fractale->b);
- ramifier(fractale->c);
- }
- else{
- fractale->a=(struct triangle*)malloc(sizeof(struct triangle));
- *fractale->a=(struct triangle){{{p[0].x,p[0].y},
- {(p[0].x+p[1].x)/2,(p[0].y+p[1].y)/2},
- {(p[0].x+p[2].x)/2,(p[0].y+p[2].y)/2}},NULL,NULL,NULL};
- fractale->b=(struct triangle*)malloc(sizeof(struct triangle));
- *fractale->b=(struct triangle){{{p[1].x,p[1].y},
- {(p[0].x+p[1].x)/2,(p[0].y+p[1].y)/2},
- {(p[1].x+p[2].x)/2,(p[1].y+p[2].y)/2}},NULL,NULL,NULL};
- fractale->c=(struct triangle*)malloc(sizeof(struct triangle));
- *fractale->c=(struct triangle){{{p[2].x,p[2].y},
- {(p[0].x+p[2].x)/2,(p[0].y+p[2].y)/2},
- {(p[1].x+p[2].x)/2,(p[1].y+p[2].y)/2}},NULL,NULL,NULL};
- }
- return;
- }
- void liberer(struct triangle* fractale){
- if(fractale->a!=NULL){
- liberer(fractale->a);
- liberer(fractale->b);
- liberer(fractale->c);
- }
- free(fractale);
- return;
- }
|