Você está na página 1de 2

ESTE EJEMPLO DE GENERACION DE FRACTAL, SE EJECUTA EN DEV C++ COMO UN PROJECTO EN MODO GRAFICO.

#include <winbgim.h> #include <stdio.h> #include<conio.h> void waitForLeftMouseClick(); int n; void mitades(int g, int h, int i, int j,int k,int l,int conta); void triangulo_rec(int a,int b, int c, int d,int e,int f); int main() { initwindow(800,800); //open a 400x300 graphics window

triangulo_rec(1,470,getmaxx()/2,1,640,470); mitades(1,470,getmaxx()/2,1,640,470,1);

// while(!kbhit()); // wait for user to press a key waitForLeftMouseClick(); // use one or the other of these--not both

closegraph(); return 0; }

//close graphics window

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); } void mitades(int g,int h, int i, int j, int k, int l, int conta) { int p1x,p1y,p2x,p2y,p3x,p3y; if(conta<n) { p1x=(g+i)/2; p1y=(h+j)/2; p2x=(g+k)/2;

p2y=(h+l)/2; p3x=(i+k)/2; p3y=(j+l)/2; triangulo_rec(p1x,p1y,p2x,p2y,p3x,p3y); conta++; mitades(g,h,p1x,p1y,p2x,p2y,conta); mitades(p1x,p1y,i,j,p3x,p3y,conta); mitades(p2x,p2y,p3x,p3y,k,l,conta); } } void triangulo_rec(int a,int b,int c,int d,int e,int f) { line(a,b,c,d); line(c,d,e,f); line(a,b,e,f); }

Você também pode gostar