C++分形树绘制

/*参考孙博文的《分形算法与程序设计:Visual C++实现》*/

 C++分形树绘制_第1张图片

/*程序代码,使用VC2005以上版本编译*/

#include 
#include 
#include 
#include 
extern "C" WINBASEAPI HWND WINAPI GetConsoleWindow (); 
#define PI 3.1415926
const double arg=15*PI/180;
HDC hdc;
void drawTree(int px,int py,double ang,double l,short width)
{
	double rn=rand()%10*(PI/180);
	int rm=rand()%9;
	if(rm>5)
		rn=0;
	if(width<1)
		width=1;
	int x=px+(int)(l*cos(ang));
	int y=py-(int)(l*sin(ang));
	MoveToEx(hdc,px,py,NULL);
	LineTo(hdc,x,y);
	if(l<20)
		return;
	drawTree(x,y,ang-arg+rn,0.82*l,width+2);
	drawTree(x,y,ang+arg+rn,0.82*l,width-2);

}
int main(int argc, char** argv) {
	system("color 2c");
	hdc=GetDC(GetConsoleWindow());
	drawTree(300,400,PI/2,75,12);
	system("pause");
	return 0;
}

你可能感兴趣的:(VC++)