intNUM=6;doubleF=sqrt(3)/6.0;doubleMin(doublea,doubleb){return(a2、4,y5;x3=(x2-x1)/3.0+x1;x4=2*(x2-x1)/3.0+x1;y3=(y2-y1)/3.0+y1;y4=2*(y2-y1)/3.0+y1;if(y1<=y2){if(x1=x2)x5=(x1+x2)/2.0+F*fabs(y1-y2);elsex5=(x1+x2)/2.0-F*fabs(y1-y2);}y5=(y1+y2)/2.0-F*fabs(x1-x2);koch(x1,y1,x3
3、,y3,num-1);koch(x3,y3,x5,y5,num-1);koch(x5,y5,x4,y4,num-1);koch(x4,y4,x2,y2,num-1);}voidmain(){intgd,gm;initgraph(&gd,&gm,"");setbkcolor(1);koch(500,300,10,300,NUM);getch();closegraph();}截图:Sierpinski曲线:代码:voidmain(){intgd,gm;initgraph(&gd,&gm,"");setbkcolor(1);koch(500,300,10,300,NU
4、M);getch();closegraph();}#include#includevoidSier_Gasket(intn,intx1,inty1,intx2,inty2,intx3,inty3){inttri[8];if(n==0)return;tri[0]=(x1+x2)/2;tri[1]=(y1+y2)/2;tri[2]=(x2+x3)/2;tri[3]=(y2+y3)/2;tri[4]=(x1+x3)/2;tri[5]=(y1+y3)/2;tri[6]=tri[0];tri[7]=tri[1];moveto(tr
5、i[0],tri[1]);lineto(tri[2],tri[3]);lineto(tri[4],tri[5]);lineto(tri[6],tri[7]);floodfill((x1+x2+x3)/3,(y1+y2+y3)/3,RED);Sier_Gasket(n-1,x1,y1,(x1+x2)/2,(y1+y2)/2,(x1+x3)/2,(y1+y3)/2);Sier_Gasket(n-1,(x1+x2)/2,(y1+y2)/2,x2,y2,(x2+x3)/2,(y2+y3)/2);Sier_Gasket(n-1,(x1+x3)/2,(y1+y3)/2,(x
6、2+x3)/2,(y2+y3)/2,x3,y3);}voidmain(){intgdriver=DETECT,gmode;initgraph(&gdriver,&gmode,"");cleardevice();setfillstyle(1,2);setcolor(RED);moveto(10,420);lineto(10,420);lineto(320,20);lineto(640,420);lineto(10,420);setfillstyle(1,3);Sier_Gasket(1,10,420,320,20,640,420);getch();Sier_Gas
7、ket(2,10,420,320,20,640,420);getch();Sier_Gasket(6,10,420,320,20,640,420);getch();closegraph();}截图:康托三分集:代码:#include#include#include#includevoidCantor(intx1,inty1,intlength,intnum){if(num==0){return;}line(x1,y1,x1+length,y1);Cantor(x1,y1+10,(int)
8、length/3.0,n