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

效果图:

《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/u012408847/10743413

    原文作者:递归算法
    原文地址: https://blog.csdn.net/u012408847/article/details/83377482
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞