基本信息
源码名称:C#画出一棵树(递归算法实例源码)
源码大小:0.05M
文件格式:.rar
开发语言:C#
更新时间:2017-04-18
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 4 元×
微信扫码支付:4 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
C#画出一棵树(主要应用递归算法)
//n为树的级别,xO与y0表示生长点,th表示角度,len表示长度
void drawTree(int n,
double x0, double y0, double leng, double th)
{
if (n == 0) return;
GetTextBox();
double x1 = x0 leng * Math.Cos(th);
double y1 = y0 leng * Math.Sin(th);
drawLine(x0, y0, x1, y1);
drawTree(n - 1, x1, y1, per1 * leng * (0.5 rand()), th th1 * (0.5 rand()));
drawTree(n - 1, x1, y1, per2 * leng * (0.4 rand()), th - th2 * (0.5 rand()));
//if (rand() > 0.6)
// drawTree(n - 1, x1, y1, per2 * leng * (0.4 rand()), th - th2 * (0.5 rand()));
}
void drawLine(double x0, double y0, double x1, double y1)
{
Pen newpen = new Pen(Color.Red, width);
graphics.DrawLine(newpen,(int)x0, (int)y0, (int)x1, (int)y1);
}
C#画出一棵树(主要应用递归算法)
//n为树的级别,xO与y0表示生长点,th表示角度,len表示长度
void drawTree(int n,
double x0, double y0, double leng, double th)
{
if (n == 0) return;
GetTextBox();
double x1 = x0 leng * Math.Cos(th);
double y1 = y0 leng * Math.Sin(th);
drawLine(x0, y0, x1, y1);
drawTree(n - 1, x1, y1, per1 * leng * (0.5 rand()), th th1 * (0.5 rand()));
drawTree(n - 1, x1, y1, per2 * leng * (0.4 rand()), th - th2 * (0.5 rand()));
//if (rand() > 0.6)
// drawTree(n - 1, x1, y1, per2 * leng * (0.4 rand()), th - th2 * (0.5 rand()));
}
void drawLine(double x0, double y0, double x1, double y1)
{
Pen newpen = new Pen(Color.Red, width);
graphics.DrawLine(newpen,(int)x0, (int)y0, (int)x1, (int)y1);
}