ASP.NET使用递归算法实现画树程序
来源:互联网 发布:nginx 别名配置 编辑:程序博客网 时间:2024/06/05 18:10
实现效果如下:(随机生成)
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApplication5{ public partial class Form1 : Form{ public Form1() { this.AutoScaleBaseSize = new Size(6, 14); this.ClientSize = new Size(600, 400); this.Paint += new PaintEventHandler(this.Form1_Paint);//注册paint事件 this.Click+=new EventHandler(this.Redraw);//注册单击事件 } private void Redraw(object sender, EventArgs e) { this.Invalidate();//使窗口重绘 } private void Form1_Paint(object sender, PaintEventArgs e) { graphics = e.Graphics ; drawTree( 10, 200, 310, 100, -PI/2 ); } private Graphics graphics; const double PI = Math.PI; double th1 = 40 * Math.PI / 180; double th2 = 30 * Math.PI / 180; double per1 = 0.6; double per2 = 0.7; Random rnd = new Random(); double rand() { return rnd.NextDouble(); } 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, n/2); drawTree( n - 1, x1, y1, per1 * leng*(0.5+rand()), th + th1*(0.5+rand()) );//使用递归算法反复执行drawTree方法,直到n=0,跳出 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, int width ){ graphics.DrawLine( new Pen(Color.Blue, width ), (int)x0, (int)y0, (int)x1, (int)y1 ); }}}
0 0
- ASP.NET使用递归算法实现画树程序
- Asp.Net 使用“递归算法”生成目录树的JSON格式(值得收藏)
- C#,asp.net 递归算法初始化树节点
- ASP.Net应用递归算法案例
- 使用递归算法实现树结构
- asp.net 2.0 中递归树的实现
- asp.net实现打包程序
- 使用递归算法实现汉诺塔
- ASP.NET 计划任务(不使用外接程序,.net内部机制实现)
- ASP.NET 计划任务(不使用外接程序,.net内部机制实现)
- ASP.NET定时执行任务 (不使用外接程序,.net内部机制实现)
- 用递归算法实现ASP程序用fso对硬盘上某个路径下目录和文件的遍历
- ASP.NET 递归 生成树 TreeView
- ASP.NET递归添加树节点
- ASP.NET通过递归添加树(Treeview)
- ASP.Net、C#实现网页小偷程序
- ASP.Net、C#实现网页小偷程序
- ASP.NET程序中用Repeater实现分页
- git版本控制开发流程小结笔记(一)
- 39. Combination Sum Medium
- 解决API<21时 GridLayout平均分配格行/列的问题
- JSON字符串和java对象的互转
- 关于事件的小题
- ASP.NET使用递归算法实现画树程序
- LeetCode121. Best Time to Buy and Sell Stock
- Swift 构造过程 1
- magento获得产品的custom option信息 Getting all custom options of a product
- 子树
- linux 设置gedit文本编辑器-字体颜色、显示行号、插件、制表符等
- 在一个整型数组中有两个数 a 、b值出现一次,其他数都出现两次。求出 a 和 b
- Qt下双屏的显示方法
- 汇编指令之CMOVcc-----CMOVG