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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
| 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 Проект_моделі_Шуліка
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double[] pt = new double[8];
int i1, j1, i2, j2, move_x, move_y;
double x1, y1, x2, y2;
bool line, circle, move_point, draw;
private void button4_Click(object sender, EventArgs e)
{
++x1;
++x2;
Axis();
if (pt[0] != 0 && pt[1] != 0 && pt[2] != 0 && pt[3] != 0)
DrawCirlce();
if (pt[4] != 0 && pt[5] != 0 && pt[6] != 0 && pt[7] != 0)
DrawEllipse();
pictureBox1.Image = (Image)myBitmap;
}
private void button3_Click(object sender, EventArgs e)
{
++y1;
++y2;
Axis();
if (pt[0] != 0 && pt[1] != 0 && pt[2] != 0 && pt[3] != 0)
DrawCirlce();
if (pt[4] != 0 && pt[5] != 0 && pt[6] != 0 && pt[7] != 0)
DrawEllipse();
pictureBox1.Image = (Image)myBitmap;
}
private void button2_Click(object sender, EventArgs e)
{
--x1;
--x2;
Axis();
if (pt[0] != 0 && pt[1] != 0 && pt[2] != 0 && pt[3] != 0)
DrawCirlce();
if (pt[4] != 0 && pt[5] != 0 && pt[6] != 0 && pt[7] != 0)
DrawEllipse();
pictureBox1.Image = (Image)myBitmap;
}
private void button5_Click(object sender, EventArgs e)
{
--y1;
--y2;
Axis();
if (pt[0] != 0 && pt[1] != 0 && pt[2] != 0 && pt[3] != 0)
DrawCirlce();
if (pt[4] != 0 && pt[5] != 0 && pt[6] != 0 && pt[7] != 0)
DrawEllipse();
pictureBox1.Image = (Image)myBitmap;
}
private void button6_Click(object sender, EventArgs e)
{
if (x2 - x1 <= 2 && y2 - y1 <= 2)
return;
--y1;
++y2;
++x1;
--x2;
Axis();
if (pt[0] != 0 && pt[1] != 0 && pt[2] != 0 && pt[3] != 0)
DrawCirlce();
if (pt[4] != 0 && pt[5] != 0 && pt[6] != 0 && pt[7] != 0)
DrawEllipse();
pictureBox1.Image = (Image)myBitmap;
}
private void button7_Click(object sender, EventArgs e)
{
++y1;
--y2;
--x1;
++x2;
Axis();
if (pt[0] != 0 && pt[1] != 0 && pt[2] != 0 && pt[3] != 0)
DrawCirlce();
if (pt[4] != 0 && pt[5] != 0 && pt[6] != 0 && pt[7] != 0)
DrawEllipse();
pictureBox1.Image = (Image)myBitmap;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
move_point = false;
if (pt[0] != 0 && pt[1] != 0 && pt[2] != 0 && pt[3] != 0)
line = true;
if (pt[4] != 0 && pt[5] != 0 && pt[6] != 0 && pt[7] != 0)
circle = true;
if (!line)
{
pt[0] = ItoX(e.Location.X);
pt[1] = JtoY(e.Location.Y);
}
else if (!circle && line)
{
pt[4] = ItoX(e.Location.X);
pt[5] = JtoY(e.Location.Y);
}
double num1 = ItoX(e.Location.X);
double num2 = JtoY(e.Location.Y);
//for (int i = 0; i < ((IEnumerable<double>)pt).Count<double>() - 1; i += 2)
//{
// if (pt[i] < num1 + 0.2 && pt[i] > num1 - 0.2 && (pt[i + 1] < num2 + 0.2 && pt[i + 1] > num2 - 0.2) && (line || circle))
// {
// move_point = true;
// move_x = i;
// move_y = i + 1;
// }
//}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
Point location = e.Location;
if (e.Button != MouseButtons.Left)
return;
if (move_point && draw && line && circle)
{
g.Clear(Color.White);
Axis();
pt[move_x] = ItoX(e.Location.X);
pt[move_y] = JtoY(e.Location.Y);
DrawEllipse();
DrawCirlce();
pictureBox1.Image = (Image)myBitmap;
}
else if (!line)
{
Axis();
pt[2] = ItoX(e.Location.X);
pt[3] = JtoY(e.Location.Y);
Pen pen = new Pen(Brushes.Black, 2f);
DrawCirlce();
double num = Math.Round(Math.Sqrt((pt[2] - pt[0]) * (pt[2] - pt[0]) + (pt[3] - pt[1]) * (pt[3] - pt[1])), 2);
DrawEllipse();
pictureBox1.Image = (Image)myBitmap;
draw = true;
}
else if (!circle)
{
g.Clear(Color.White);
Axis();
pt[6] = ItoX(e.Location.X);
pt[7] = JtoY(e.Location.Y);
Pen pen = new Pen(Brushes.Black, 2f);
DrawCirlce();
double num = Math.Round(Math.Sqrt((pt[6] - pt[4]) * (pt[6] - pt[4]) + (pt[7] - pt[5]) * (pt[7] - pt[5])), 2);
DrawEllipse();
pictureBox1.Image = (Image)myBitmap;
draw = true;
}
}
private void button8_Click(object sender, EventArgs e)
{
listBox1.Items.Add(pt[0]);
listBox1.Items.Add(pt[1]);
listBox1.Items.Add(pt[2]);
listBox1.Items.Add(pt[3]);
listBox1.Items.Add(pt[4]);
listBox1.Items.Add(pt[5]);
listBox1.Items.Add(pt[6]);
listBox1.Items.Add(pt[7]);
}
private void button1_Click(object sender, EventArgs e)
{
Axis();
if (pt[0] != 0 && pt[1] != 0 && pt[2] != 0 && pt[3] != 0)
DrawCirlce();
if (pt[4] != 0 && pt[5] != 0 && pt[6] != 0 && pt[7] != 0)
DrawEllipse();
pictureBox1.Image = (Image)myBitmap;
}
Bitmap myBitmap;
Graphics g;
int XtoI(double x)
{
return i1 + (int)((x - x1) * (double)(i2 - i1) / (x2 - x1));
}
int YtoJ(double y)
{
return j1 + (int)((y - y1) * (double)(j2 - j1) / (y2 - y1));
}
double ItoX(int i)
{
return Math.Round(x1 + (double)(i - i1) * (x2 - x1) / (double)(i2 - i1), 2);
}
double JtoY(int j)
{
return Math.Round(y1 + (double)(j - j1) * (y2 - y1) / (double)(j2 - j1), 2);
}
private void Form1_Load(object sender, EventArgs e)
{
myBitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g = Graphics.FromImage((Image)myBitmap);
i1 = 0;
j1 = 0;
i2 = pictureBox1.Width;
j2 = pictureBox1.Height;
x1 = -10;
y1 = 10;
x2 = 10;
y2 = -10;
Axis();
line = false;
circle = false;
move_point = false;
draw = false;
pictureBox1.Image = (Image)myBitmap;
}
private void Axis()
{
myBitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g = Graphics.FromImage((Image)myBitmap);
g.Clear(Color.White);
Pen pen = new Pen(Brushes.Black, 3f);
Font font = x2 - x1 <= 30 ? (x2 - x1 <= 20 ? new Font("Century Gothic", 11f, FontStyle.Bold, GraphicsUnit.Pixel) : new Font("Century Gothic", 9f, FontStyle.Bold, GraphicsUnit.Pixel)) : new Font("Century Gothic", 8f, FontStyle.Bold, GraphicsUnit.Pixel);
g.DrawLine(pen, XtoI(0), YtoJ(y1), XtoI(0), YtoJ(y2));
g.DrawLine(pen, XtoI(x1), YtoJ(0), XtoI(x2), YtoJ(0));
for (int i = 0; (double)i <= x2 - x1; ++i)
{
if (x1 + (double)i != 0)
{
g.DrawLine(pen, XtoI(x1 + (double)i), YtoJ(0.15), XtoI(x1 + (double)i), YtoJ(-0.15));
g.DrawString((x1 + (double)i).ToString(), font, (Brush)new SolidBrush(Color.Black), (float)(XtoI(x1 + (double)i) - 3), (float)(YtoJ(-0.15) + 5));
}
}
for (int i = 0; (double)i <= y1 - y2; ++i)
{
if (y2 + (double)i != 0)
{
g.DrawLine(pen, XtoI(0.15), YtoJ(y2 + (double)i), XtoI(-0.15), YtoJ(y2 + (double)i));
g.DrawString((y2 + (double)i).ToString(), font, (Brush)new SolidBrush(Color.Black), (float)(XtoI(-0.15) - 20), (float)(YtoJ(y2 + (double)i) - 5));
}
}
pictureBox1.Image = (Image)myBitmap;
}
private void DrawCirlce()
{
Pen pen = new Pen(Brushes.Red, 2f);
int num = (int)Math.Round(Math.Sqrt((double)((XtoI(pt[2]) - XtoI(pt[0])) * (XtoI(pt[2]) - XtoI(pt[0])) + (YtoJ(pt[3]) - YtoJ(pt[1])) * (YtoJ(pt[3]) - YtoJ(pt[1])))), 2);
g.DrawEllipse(pen, XtoI(pt[0]) - num, YtoJ(pt[1]) - num, 2 * num, 2 * num);
g.FillEllipse(Brushes.Black, XtoI(pt[0]) - 3, YtoJ(pt[1]) - 3, 6, 6);
g.FillEllipse(Brushes.Black, XtoI(pt[2]) - 3, YtoJ(pt[3]) - 3, 6, 6);
}
private void DrawEllipse()
{
Pen pen = new Pen(Brushes.Blue);
int num = (int)Math.Round(Math.Sqrt((double)((XtoI(pt[6]) - XtoI(pt[4])) * (XtoI(pt[6]) - XtoI(pt[4])) + (YtoJ(pt[7]) - YtoJ(pt[5])) * (YtoJ(pt[7]) - YtoJ(pt[5])))), 2);
g.DrawEllipse(pen, XtoI(pt[4]) - num, YtoJ(pt[5]) - num, 2 * num, 2 * num);
g.FillEllipse(Brushes.Black, XtoI(pt[4]) - 3, YtoJ(pt[5]) - 3, 6, 6);
g.FillEllipse(Brushes.Black, XtoI(pt[6]) - 3, YtoJ(pt[7]) - 3, 6, 6);
}
}
} |