/
MandelbrotForm.cs
executable file
·154 lines (119 loc) · 5.23 KB
/
MandelbrotForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Drawing.Imaging;
namespace Aont
{
public partial class MandelbrotForm : Form
{
public MandelbrotForm()
{
InitializeComponent();
mandelbrot.Progressing += new EventHandler<ProgressingEventArgs>(mandelbrot_Progressing);
}
void mandelbrot_Progressing(object sender, ProgressingEventArgs e)
{
this.progressBar1.Value = e.Percent;
}
MandelbrotCalculator mandelbrot = new MandelbrotCalculator();
void Set()
{
mandelbrot.n_exp = double.Parse(n_settingControl8.Value);
mandelbrot.minX = double.Parse(leftx_settingControl1.Value);
mandelbrot.minY = double.Parse(bottomy_settingControl2.Value);
mandelbrot.MaxX = double.Parse(rightx_settingControl3.Value);
mandelbrot.MaxY = double.Parse(topy_settingControl4.Value);
mandelbrot.Width = int.Parse(width_settingControl9.Value);
mandelbrot.Height = int.Parse(height_settingControl10.Value);
mandelbrot.Loop = int.Parse(loop_settingControl5.Value);
mandelbrot.Infinity = double.Parse(infinity_settingControl6.Value);
mandelbrot.epsilon = double.Parse(epsilon_settingControl7.Value);
InvalidateImage();
}
void InvalidateImage()
{
this.progressBar1.Visible = true;
var Canvas = mandelbrot.setImage();
this.pictureBox1.Image = Canvas;
this.progressBar1.Visible = false;
}
private void set_button_Click(object sender, EventArgs e)
{
Set();
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
switch (e.Button)
{
case MouseButtons.Left:
this.leftx_settingControl1.Value = mandelbrot.getX(e.X * mandelbrot.Width / this.pictureBox1.Width).ToString();
this.bottomy_settingControl2.Value = mandelbrot.getY(e.Y * mandelbrot.Height / this.pictureBox1.Height).ToString();
break;
case MouseButtons.Right:
this.rightx_settingControl3.Value = mandelbrot.getX(e.X * mandelbrot.Width / this.pictureBox1.Width).ToString();
this.topy_settingControl4.Value = mandelbrot.getY(e.Y * mandelbrot.Height / this.pictureBox1.Height).ToString();
break;
default:
break;
}
}
void InvalidateParametersTextBox()
{
this.n_settingControl8.Value = mandelbrot.n_exp.ToString();
this.leftx_settingControl1.Value = mandelbrot.minX.ToString();
this.bottomy_settingControl2.Value = mandelbrot.minY.ToString();
this.rightx_settingControl3.Value = mandelbrot.MaxX.ToString();
this.topy_settingControl4.Value = mandelbrot.MaxY.ToString();
this.width_settingControl9.Value = mandelbrot.Width.ToString();
this.height_settingControl10.Value = mandelbrot.Height.ToString();
this.loop_settingControl5.Value = mandelbrot.Loop.ToString();
this.infinity_settingControl6.Value = mandelbrot.Infinity.ToString();
this.epsilon_settingControl7.Value = mandelbrot.epsilon.ToString();
}
private void MandelbrotForm_Shown(object sender, EventArgs e)
{
InvalidateParametersTextBox();
InvalidateImage();
}
private void saveToolStripButton_Click(object sender, EventArgs e)
{
this.saveFileDialog1.ShowDialog();
}
private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
{
var fn = this.saveFileDialog1.FileName;
ImageFormat format =ImageFormat.Bmp ;
if (fn.ToLower().EndsWith(".jpg") || fn.ToLower().EndsWith(".jpeg"))
format = ImageFormat.Jpeg;
else if (fn.ToLower().EndsWith(".png"))
format = ImageFormat.Png;
else if (fn.ToLower().EndsWith(".gif"))
format = ImageFormat.Gif;
this.pictureBox1.Image.Save(fn, format);
}
private void normalToolStripMenuItem_Click(object sender, EventArgs e)
{
mandelbrot.calctype = CalcType.Argment;
InvalidateImage();
}
private void convergenceAssumptionToolStripMenuItem_Click(object sender, EventArgs e)
{
mandelbrot.calctype = CalcType.ConvergenceArgment;
InvalidateImage();
}
private void reset_button1_Click(object sender, EventArgs e)
{
this.InvalidateParametersTextBox();
}
private void initialToolStripMenuItem_Click(object sender, EventArgs e)
{
this.mandelbrot = new MandelbrotCalculator();
this.InvalidateParametersTextBox();
}
}
}