程序实现的羊齿叶的图形:
这样类型的叶子,在学校的后山上也经常的见到。每一次打照面的时候,都会为它的优雅而感动……
在学校的东区,化石林内,草地上也可以见到这般的身影的……可虽是在地质大学,又对地质一窍不通,在化石林漫步的时候,就会想,这些古森的化石,曾经的是多么美啊。却都随时间飘逝而去了……
因为爱慕它的美,所以会感动,会神伤;而分形,却在自己的空间里把其美所含有的“序”保留下来……爱美的人们啊,如果您可以使它重新摇曳起来,您怎么肯不动起手来呢?
这是代码(算法参照了有关分形的书),我却希望有一天我可以自己写一个完整的,也包括算法在内;因为我觉得它们就象被关在古堡的公主,我要营救自己的那个:):
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Barnsley
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private Pen greenPen=new Pen(Color.Green,0);
private Random randNum=new Random(unchecked((int)DateTime.Now.Ticks));
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 Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.Info;
this.ClientSize = new System.Drawing.Size(488, 365);
this.Name = "Form1";
this.Text = "羊齿叶";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
protected override void OnPaint(PaintEventArgs e)
{
Barnsley(e);
base.OnPaint(e);
}
private void Barnsley(PaintEventArgs e)
{
Graphics dc= e.Graphics;
int Itn=500000,i=0;
double X=0,Y=0,TempX=0,CurP=0;
double []A={ 0.0,0.85,0.2,-0.15};
double []B={ 0.0,0.04,-0.26,0.28};
double []C={ 0.0,-0.04,0.23,0.26};
double []D={ 0.16,0.85,0.22,0.24};
double []E={ 0.0,0.0,0.0,0.0};
double []F={ 0.0,80.0,80.0,20.0};
double []P={ 0.01,0.85,0.07,0.07};
CurP=randNum.NextDouble();
while(i<Itn)
{
TempX=X;
if(CurP<P[0])
{
X=A[0]*X+B[0]*Y+E[0];
Y=C[0]*TempX+D[0]*Y+F[0];
}
else if(CurP>P[0]&&CurP<(P[0]+P[1]))
{
X=A[1]*X+B[1]*Y+E[1];
Y=C[1]*TempX+D[1]*Y+F[1];
}
else if(CurP>(P[0]+P[1])&&CurP<(P[0]+P[1]+P[2]))
{
X=A[2]*X+B[2]*Y+E[2];
Y=C[2]*TempX+D[2]*Y+F[2];
}
else
{
X=A[3]*X+B[3]*Y+E[3];
Y=C[3]*TempX+D[3]*Y+F[3];
}
dc.DrawEllipse(greenPen,400+(int)X,540-(int)Y,1,1);
CurP=randNum.NextDouble();
i++;
}
}
}
}
下面是两个变形的图形:):
图形1:
double []A={ 0.0,-0.85,0.2,-0.15};
double []B={ 0.0,0.04,-0.26,0.28};
double []C={ 0.0,-0.04,0.23,0.26};
double []D={ 0.16,0.85,0.22,0.24};
double []E={ 0.0,0.0,0.0,0.0};
double []F={ 0.0,80.0,80.0,20.0};
double []P={ 0.01,0.85,0.07,0.07};
图形2:
double []A={ 0.0,-0.95,0.2,-0.15};
double []B={ 0.0,0.04,-0.26,0.28};
double []C={ 0.0,-0.04,0.23,0.26};
double []D={ 0.16,0.85,0.22,0.24};
double []E={ 0.0,0.0,0.0,0.0};
double []F={ 0.0,80.0,80.0,20.0};
double []P={ 0.01,0.85,0.07,0.07};