DEV/DEV1.1/TP16:Recursivite/triangle.c

27 lines
764 B
C
Raw Normal View History

2023-01-03 11:27:42 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <graph.h>
#include <string.h>
void TriangleSlerpinski(int n,int x,int y,int xx,int yy,int xxx,int yyy){
if (n==0){
DessinerSegment(x,y,xx,yy);
DessinerSegment(xx,yy,xxx,yyy);
DessinerSegment(xxx,yyy,x,y);
return;
} TriangleSlerpinski(n-1,x,y,xx+((xxx-xx)/4),(yy-((yy-y)/2)),xxx-((xxx-xx)/4),(yyy-((yy-y)/2)));
TriangleSlerpinski(n-1,xx+((xxx-xx)/4),(yy-((yy-y)/2)),xx,yy,xx+((xxx-xx)/2),yyy);
TriangleSlerpinski(n-1,xxx-((xxx-xx)/4),(yyy-((yy-y)/2)),xx+((xxx-xx)/2),yyy,xxx,yyy);
}
int main(int argc, char const *argv[])
{
int n;
n=strtol(argv[1],NULL,10);
InitialiserGraphique();
CreerFenetre(0,0,1000,1000);
TriangleSlerpinski(n,500,0,0,950,1000,950);
Touche();
FermerGraphique();
return 0;
}