📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace 递归图形
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Button button8;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.button8 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(128)));
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.pictureBox1.Location = new System.Drawing.Point(24, 24);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(456, 312);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// button1
//
this.button1.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.button1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(192)));
this.button1.Cursor = System.Windows.Forms.Cursors.Hand;
this.button1.ForeColor = System.Drawing.Color.ForestGreen;
this.button1.Location = new System.Drawing.Point(56, 344);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "递归多边形";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.button2.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(192)));
this.button2.Cursor = System.Windows.Forms.Cursors.Hand;
this.button2.ForeColor = System.Drawing.Color.ForestGreen;
this.button2.Location = new System.Drawing.Point(160, 344);
this.button2.Name = "button2";
this.button2.TabIndex = 2;
this.button2.Text = "递归圆";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.button3.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(192)));
this.button3.Cursor = System.Windows.Forms.Cursors.Hand;
this.button3.ForeColor = System.Drawing.Color.ForestGreen;
this.button3.Location = new System.Drawing.Point(264, 344);
this.button3.Name = "button3";
this.button3.TabIndex = 3;
this.button3.Text = "递归三角形";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.button4.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(192)));
this.button4.ForeColor = System.Drawing.Color.Green;
this.button4.Location = new System.Drawing.Point(368, 344);
this.button4.Name = "button4";
this.button4.TabIndex = 4;
this.button4.Text = "递归二叉树";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.button5.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(192)));
this.button5.ForeColor = System.Drawing.Color.Green;
this.button5.Location = new System.Drawing.Point(368, 384);
this.button5.Name = "button5";
this.button5.TabIndex = 8;
this.button5.Text = "分形练习";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button6
//
this.button6.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.button6.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(192)));
this.button6.Cursor = System.Windows.Forms.Cursors.Hand;
this.button6.ForeColor = System.Drawing.Color.ForestGreen;
this.button6.Location = new System.Drawing.Point(264, 384);
this.button6.Name = "button6";
this.button6.TabIndex = 7;
this.button6.Text = "分形";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// button7
//
this.button7.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.button7.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(192)));
this.button7.Cursor = System.Windows.Forms.Cursors.Hand;
this.button7.ForeColor = System.Drawing.Color.ForestGreen;
this.button7.Location = new System.Drawing.Point(160, 384);
this.button7.Name = "button7";
this.button7.TabIndex = 6;
this.button7.Text = "地毯练习";
this.button7.Click += new System.EventHandler(this.button7_Click);
//
// button8
//
this.button8.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.button8.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(192)));
this.button8.Cursor = System.Windows.Forms.Cursors.Hand;
this.button8.ForeColor = System.Drawing.Color.ForestGreen;
this.button8.Location = new System.Drawing.Point(56, 384);
this.button8.Name = "button8";
this.button8.TabIndex = 5;
this.button8.Text = "地毯";
this.button8.Click += new System.EventHandler(this.button8_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.Teal;
this.ClientSize = new System.Drawing.Size(504, 421);
this.Controls.Add(this.button5);
this.Controls.Add(this.button6);
this.Controls.Add(this.button7);
this.Controls.Add(this.button8);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.pictureBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
int n=3;
int level;
double size;
double ratio;
level=4;
size=80f;
ratio=0.4f;
Graphics g1=pictureBox1.CreateGraphics();
Pen p1=new Pen(Color.Blue);
g1.Clear(pictureBox1.BackColor);
Class1 ploy=new Class1();
ploy.setdata(n);
ploy.snow(g1,p1,250,220,n,level,size,ratio);
}
private void button2_Click(object sender, System.EventArgs e)
{
int n;
float r,r1,c=40;
double p=0.9f,f=0.2f;
n=5;
r1=(float)(0.5*479*(1-f)/(1-p));
r=r1/c;
Graphics g=pictureBox1.CreateGraphics();
Pen p1=new Pen(Color.Blue);
g.Clear(pictureBox1.BackColor);
g.DrawEllipse(p1,150-r,130-r,2*r,2*r);
Class2 yuan=new Class2();
yuan.circles(g,p1,150,130,r,n+1);
}
private void button3_Click(object sender, System.EventArgs e)
{
Graphics g1=pictureBox1.CreateGraphics();
Pen p1=new Pen(Color.Blue);
g1.Clear(pictureBox1.BackColor);
int[] points=new int[10];
int n;
float xa,ya,xb,yb,xc,yc;
n=7;
xa=50.0f;ya=80.0f;
xb=500f;yb=80.0f;
xc=50f;yc=360.0f;
g1.DrawLine(p1,xa,ya,xb,yb);
Class3 zfx=new Class3();
zfx.tria(g1,p1,xa,ya,xb,yb,xc,yc,n);
}
private void button4_Click(object sender, System.EventArgs e)
{
Graphics g1=pictureBox1.CreateGraphics();
Pen pen1=new Pen(Color.Blue,3.0f);
g1.Clear(pictureBox1.BackColor);
int n;
n=8;
int ax,ay,bx,by;
ax=0;
bx=0;
ay=-200;
by=-100;
Class4 ercha=new Class4();
ercha.bintree(g1,pen1,ax,ay,bx,by,n);
}
private void button5_Click(object sender, System.EventArgs e)
{
Graphics g1=pictureBox1.CreateGraphics();
Pen p1=new Pen(Color.Blue);
g1.Clear(pictureBox1.BackColor);
int i,n,k;
float pi,theta,x,y,r,x1,y1,xc,yc,sizefactor,xmargin,phi;
k=4;
n=3;
Class6 tigui=new Class6();
sizefactor=1.0f;
if(k<3)
{
xmargin=0.5f*(640-sizefactor*638);
tigui.side(g1,p1,xmargin,240,639-xmargin,240,n);
}
else
{
xc=320;
yc=240;
r=0.9f*yc*sizefactor;
pi=(float)(4*Math.Atan(1.0f));
theta=2*pi/k;
phi=-0.5f*theta;
x1=(float)(320+r*Math.Cos(phi));
y1=(float)(240+r*Math.Sin(phi));
for(i=0;i<k;i++)
{
x=x1;
y=y1;
phi+=theta;
x1=(float)(xc+r*Math.Cos(phi));
y1=(float)(yc+r*Math.Sin(phi));
tigui.side(g1,p1,x,y,x1,y1,n);
}
}
}
private void button6_Click(object sender, System.EventArgs e)
{
Graphics g1=pictureBox1.CreateGraphics();
Pen p1=new Pen(Color.Blue);
g1.Clear(pictureBox1.BackColor);
int i,n,k;
float pi,theta,x,y,r,x1,y1,xc,yc,sizefactor,xmargin,phi;
k=4;
n=5;
Class6 tigui=new Class6();
sizefactor=1.0f;
if(k<3)
{
xmargin=0.5f*(640-sizefactor*638);
tigui.side(g1,p1,xmargin,240,639-xmargin,240,n);
}
else
{
xc=320;
yc=240;
r=0.9f*yc*sizefactor;
pi=(float)(4*Math.Atan(1.0f));
theta=2*pi/k;
phi=-0.5f*theta;
x1=(float)(320+r*Math.Cos(phi));
y1=(float)(240+r*Math.Sin(phi));
for(i=0;i<k;i++)
{
x=x1;
y=y1;
phi+=theta;
x1=(float)(xc+r*Math.Cos(phi));
y1=(float)(yc+r*Math.Sin(phi));
tigui.side(g1,p1,x,y,x1,y1,n);
}
}
}
private void button7_Click(object sender, System.EventArgs e)
{
Graphics g1=pictureBox1.CreateGraphics();
Pen p1=new Pen(Color.Blue);
g1.Clear(pictureBox1.BackColor);
SolidBrush b1=new SolidBrush(Color.Yellow);
Class5 dt=new Class5();
dt.draw(g1,p1,b1,3);
}
private void button8_Click(object sender, System.EventArgs e)
{
Graphics g1=pictureBox1.CreateGraphics();
Pen p1=new Pen(Color.Blue);
g1.Clear(pictureBox1.BackColor);
SolidBrush b1=new SolidBrush(Color.BlanchedAlmond);
Class5 dt=new Class5();
dt.draw(g1,p1,b1,4);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -