C递归算法使用案例——画树

C递归算法使用案例——画树效果图 部分代码 privatevoidd intn doublex0 doubley0 doubleleng doubleth if n 0 return doublex1 x0 leng Math Cos th dou

效果图:

C递归算法使用案例——画树

C递归算法使用案例——画树

部分代码:

private void drawTree(int n, double x0, double y0, double leng, double th) { if (n == 0) return; 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 + ran()), th + th1 * (0.5 + ran())); drawTree(n - 1, x1, y1, per2 * leng * (0.4 + ran()), th - th2 * (0.5 + ran())); if (ran() > 0.6) drawTree(n - 1, x1, y1, per2 * leng * (0.4 + ran()), th - th2 * (0.5 + ran())); } private void drawLine(double x0, double y0, double x1, double y1) { graphics.DrawLine(Pens.Blue, (int)x0, (int)y0, (int)x1, (int)y1); }

源码地址:

https://download.csdn.net/download/u0/

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/234019.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号