📄 fmain.cs
字号:
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// btnDraw
//
this.btnDraw.Location = new System.Drawing.Point(20, 48);
this.btnDraw.Name = "btnDraw";
this.btnDraw.Size = new System.Drawing.Size(136, 23);
this.btnDraw.TabIndex = 20;
this.btnDraw.Text = "Draw";
this.btnDraw.Click += new System.EventHandler(this.btnDraw_Click);
//
// groupBox1
//
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label7,
this.txtReal,
this.label6});
this.groupBox1.Location = new System.Drawing.Point(8, 88);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(160, 152);
this.groupBox1.TabIndex = 22;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Display Center";
//
// FMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(760, 777);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.pictureBox,
this.panel1});
this.Menu = this.mainMenu1;
this.Name = "FMain";
this.Text = "Fractals";
this.Closing += new System.ComponentModel.CancelEventHandler(this.FMain_Closing);
this.panel1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new FMain());
}
private void mnuFileSave_Click(object sender, System.EventArgs e)
{
ImageFormat format = ImageFormat.Jpeg;
int nFilterIndex = -1;
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Image Files (JPEG, GIF, BMP, etc.)|" +
"*.jpg;*.jpeg;*.gif;*.bmp;*.tif;*.tiff;*.png|" +
"JPEG files (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
"GIF Files (*.gif)|*.gif|" +
"BMP Files (*.bmp)|*.bmp|" +
"TIFF Files (*.tif;*.tiff)|*.tif;*.tiff|" +
"PNG Files (*.png)|*.png|" +
"All files (*.*)|*.*";
if( nFilterIndex != -1 )
{
sfd.FilterIndex = nFilterIndex;
}
if( sfd.ShowDialog () == DialogResult.OK )
{
String fileName = sfd.FileName;
if( fileName.Length != 0 )
{
nFilterIndex = sfd.FilterIndex;
switch( nFilterIndex )
{
case 1:
format = ImageFormat.Jpeg;
break;
case 2:
format = ImageFormat.Jpeg;
break;
case 3:
format = ImageFormat.Gif;
break;
case 4:
format = ImageFormat.Bmp;
break;
case 5:
format = ImageFormat.Tiff;
break;
case 6:
format = ImageFormat.Png;
break;
case 7:
format = ImageFormat.Jpeg;
fileName += ".jpg";
break;
default:
break;
}
switch( _DrawMode )
{
case DrawMode.Mandelbrot:
_man.SaveBitmap( fileName, format );
break;
case DrawMode.Julia:
_jul.SaveBitmap( fileName, format );
break;
}
}
}
}
private void mnuFileExit_Click(object sender, System.EventArgs e)
{
Close();
}
private void mnuDrawMandelbrot_Click(object sender, System.EventArgs e)
{
DrawMandelbrot();
}
private void DrawMandelbrot()
{
Cursor = Cursors.WaitCursor;
if( _DrawMode != DrawMode.Mandelbrot )
{
if( _jul != null )
{
_jul.DisableMouseHandlers();
}
_DrawMode = DrawMode.Mandelbrot;
groupBox2.Visible = false;
label1.Text = "Mandelbrot";
}
else
{
InitMandelbrot();
}
_man.Start( pictureBox );
Cursor = Cursors.Default;
}
private void InitMandelbrot()
{
_man.RealCenter = double.Parse( txtReal.Text );
_man.ImgCenter = double.Parse( txtImaginary.Text );
_man.Scale = double.Parse( txtScale.Text );
_man.Iterations = int.Parse( txtIterations.Text );
}
private void UpdateManReadouts( double realCenter, double imgCenter, double scale )
{
txtReal.Text = realCenter.ToString();
txtImaginary.Text = imgCenter.ToString();
txtScale.Text = scale.ToString();
}
private void mnuDrawJulia_Click(object sender, System.EventArgs e)
{
DrawJulia();
}
private void DrawJulia()
{
Cursor = Cursors.WaitCursor;
if( _DrawMode != DrawMode.Julia )
{
if( _man != null )
{
_man.DisableMouseHandlers();
}
_DrawMode = DrawMode.Julia;
groupBox2.Visible = true;
label1.Text = "Julia";
_jul.RealC = double.Parse( txtReal.Text );
_jul.ImgC = double.Parse( txtImaginary.Text );
txtRealC.Text = txtReal.Text;
txtImaginaryC.Text = txtImaginary.Text;
_jul.RealCenter = 0.0;
_jul.ImgCenter = 0.0;
_jul.Scale = 0.01;
_jul.Iterations = 512;
}
else
{
InitJulia();
}
_jul.Start( pictureBox );;
Cursor = Cursors.Default;
}
private void InitJulia()
{
_jul.RealC = double.Parse( txtRealC.Text );
_jul.ImgC = double.Parse( txtImaginaryC.Text );
_jul.RealCenter = double.Parse( txtReal.Text );
_jul.ImgCenter = double.Parse( txtImaginary.Text );
_jul.Scale = double.Parse( txtScale.Text );
_jul.Iterations = int.Parse( txtIterations.Text );
}
private void UpdateJuliaReadouts( double realCenter, double imgCenter, double scale )
{
txtReal.Text = realCenter.ToString();
txtImaginary.Text = imgCenter.ToString();
txtScale.Text = scale.ToString();
txtIterations.Text = _jul.Iterations.ToString();
}
private void btnZoomIn_Click(object sender, System.EventArgs e)
{
switch( _DrawMode )
{
case DrawMode.Mandelbrot:
InitMandelbrot();
_man.ZoomIn();
break;
case DrawMode.Julia:
InitJulia();
_jul.ZoomIn();
break;
}
}
private void btnZoomOut_Click(object sender, System.EventArgs e)
{
switch( _DrawMode )
{
case DrawMode.Mandelbrot:
InitMandelbrot();
_man.ZoomOut();
break;
case DrawMode.Julia:
InitJulia();
_jul.ZoomOut();
break;
}
}
private void mnuSetColors_Click(object sender, System.EventArgs e)
{
FColor c = new FColor();
switch( _DrawMode )
{
case DrawMode.Mandelbrot:
c.ColorMap = _man.ColorMap;
break;
case DrawMode.Julia:
c.ColorMap = _jul.ColorMap;
break;
}
if( c.ShowDialog( this ) == DialogResult.OK )
{
switch( _DrawMode )
{
case DrawMode.Mandelbrot:
_man.ColorMap = c.ColorMap;
break;
case DrawMode.Julia:
_jul.ColorMap = c.ColorMap;
break;
}
}
}
private void btnDraw_Click(object sender, System.EventArgs e)
{
switch( _DrawMode )
{
case DrawMode.Mandelbrot:
DrawMandelbrot();
break;
case DrawMode.Julia:
DrawJulia();
break;
}
}
private void mnuFileSaveJulia_Click(object sender, System.EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Julia Parameter Files (julia)|" +
"*.julia|" +
"All files (*.*)|*.*";
if( sfd.ShowDialog () == DialogResult.OK )
{
_jul.SaveSettings( sfd.FileName );
}
}
private void mnuFileSaveMandelbrot_Click(object sender, System.EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Mandelbrot Parameter Files (mandelbrot)|" +
"*.mandelbrot|" +
"All files (*.*)|*.*";
if( sfd.ShowDialog () == DialogResult.OK )
{
_man.SaveSettings( sfd.FileName );
}
}
private void mnuFileLoadJulia_Click(object sender, System.EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog ();
ofd.Filter = "Julia Parameter Files (julia)|" +
"*.julia|" +
"All files (*.*)|*.*";
if( ofd.ShowDialog () == DialogResult.OK )
{
String fileName = ofd.FileName;
if( fileName.Length != 0 )
{
_jul.ReadSettings( ofd.FileName );
if( _DrawMode != DrawMode.Julia )
{
if( _man != null )
{
_man.DisableMouseHandlers();
}
_DrawMode = DrawMode.Julia;
groupBox2.Visible = true;
label1.Text = "Julia";
}
txtScale.Text = _jul.Scale.ToString();
txtReal.Text = _jul.RealCenter.ToString();
txtImaginary.Text = _jul.ImgCenter.ToString();
txtIterations.Text = _jul.Iterations.ToString();
txtRealC.Text = _jul.RealC.ToString();
txtImaginaryC.Text = _jul.ImgC.ToString();
_jul.Start( pictureBox );
}
}
}
private void mnuFileLoadMandelbrot_Click(object sender, System.EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog ();
ofd.Filter = "Mandelbrot Parameter Files (mandelbrot)|" +
"*.mandelbrot|" +
"All files (*.*)|*.*";
if( ofd.ShowDialog () == DialogResult.OK )
{
String fileName = ofd.FileName;
if( fileName.Length != 0 )
{
_man.ReadSettings( ofd.FileName );
if( _DrawMode != DrawMode.Mandelbrot )
{
if( _jul != null )
{
_jul.DisableMouseHandlers();
}
_DrawMode = DrawMode.Mandelbrot;
groupBox2.Visible = false;
label1.Text = "Mandelbrot";
}
txtScale.Text = _man.Scale.ToString();
txtReal.Text = _man.RealCenter.ToString();
txtImaginary.Text = _man.ImgCenter.ToString();
txtIterations.Text = _man.Iterations.ToString();
_man.Start( pictureBox );
}
}
}
private void FMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if( _man != null )
{
_man.Kill();
}
if( _jul != null )
{
_jul.Kill();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -