递归三角形

void Draw( CClientDC *dc,const CPoint& top,const CPoint& left,CPoint &right,int drawLevel )
{
if (drawLevel <= 0)
{
return;
}

dc->MoveTo(top);
dc->LineTo(left);
dc->LineTo(right);
dc->LineTo(top);

CPoint topLeft((top.x+left.x)/2,(top.y+left.y)/2);
CPoint topRight((top.x+right.x)/2,(top.y+right.y)/2);
CPoint leftRight((left.x+right.x)/2,(left.y+right.y)/2);

Draw(dc,top,topLeft,topRight,drawLevel-1);
Draw(dc,left,leftRight,topLeft,drawLevel-1);
Draw(dc,right,topRight,leftRight,drawLevel-1);
}

结果:

image 

其中level = 5;

你可能感兴趣的:(递归)