Вы находитесь на странице: 1из 2

//Códificación del algoritmo de la Junta de Sierpinsky

#include <winbgim.h>
#include <iostream>
#include <stdlib.h>
#include <conio.h>
using namespace std;
typedef struct puntito
{
float x;
float y;
}punto;
punto Mitad(punto p1, punto p2)
{
punto resultado;
resultado.x=(p1.x+p2.x)/2;
resultado.y=(p1.y+p2.y)/2;
return(resultado);
}
void Dibujar_Triangulo_Relleno(punto A,punto B,punto C)
{
int vector[8];
vector[0]=(int)A.x;
vector[1]=(int)A.y;
vector[2]=(int)B.x;
vector[3]=(int)B.y;
vector[4]=(int)C.x;
vector[5]=(int)C.y;
vector[6]=(int)A.x;
vector[7]=(int)A.y;
fillpoly(3,vector);
}

void Dibujar_Sierpinsky( punto A, punto B, punto C,int N )


{
punto AB,BC,CA;
if(N==0)
{
Dibujar_Triangulo_Relleno(A,B,C);

}
else
{
AB = Mitad( A, B );
BC = Mitad( B, C );
CA = Mitad( C, A );
Dibujar_Sierpinsky( A, AB, CA, N-1 );
Dibujar_Sierpinsky( AB, B, BC, N-1 );
Dibujar_Sierpinsky( CA, BC, C, N-1 );
}
}

void waitForLeftMouseClick();

int main()
{
initwindow(800,700); //open a 400x300 graphics window

// delete these lines and replace them with your own code:
settextstyle(0,0,2);
setcolor(RED);
outtextxy(20,100,"Junta de Sierpinsky");
setcolor(GREEN);
outtextxy(60,600,"Clic para terminar");
punto a,b,c;
a.x=300;
a.y=300;
b.x=150;
b.y=450;
c.x=450;
c.y=450;
//Dibujar_Triangulo_Relleno(a,b,c);
for(int i=0;i<=15;i++)
{
Dibujar_Sierpinsky(a,b,c,i);
delay(250);
}

waitForLeftMouseClick(); // use one or the other of these--not both

closegraph(); //close graphics window


return 0;
}

void waitForLeftMouseClick()
{
clearmouseclick(WM_LBUTTONDOWN);
const int DELAY = 50; // Milliseconds of delay between checks
int x, y;
while (!ismouseclick(WM_LBUTTONDOWN))
delay(DELAY);
getmouseclick(WM_LBUTTONDOWN, x, y);
}

Вам также может понравиться