-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
165 lines (140 loc) · 4.63 KB
/
Form1.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
155
156
157
158
159
160
161
162
163
164
165
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;
using System.Drawing.Drawing2D;
using Geometry;
using Visual;
using System.Threading;
using System.DirectoryServices.ActiveDirectory;
using System.Security.Cryptography.X509Certificates;
namespace WF;
public partial class Form1 : Form
{
Graphics g;
int countoflines = 0;
List<VisualCurve> lines;
public Form1()
{
InitializeComponent();
lines = new List<VisualCurve>();
}
private void HReflection_checkbox_CheckedChanged(object sender, EventArgs e)
{
Reflection();
panel1.Refresh();
panel2.Refresh();
}
private void VReflection_checkbox_CheckedChanged(object sender, EventArgs e)
{
Reflection();
panel1.Refresh();
panel2.Refresh();
}
private void Reflection()
{
while (lines.Count != countoflines)
{
lines.RemoveAt(lines.Count - 1);
}
if ((HReflection_checkbox.Checked || VReflection_checkbox.Checked))
{
for (int i = 0; i < countoflines; ++i)
{
if (HReflection_checkbox.Checked & VReflection_checkbox.Checked)
{
lines.Add(new VisualCurve(new VerticalReflection(new HorizontalReflection(lines[i], panel1.Width), panel1.Height)));
}
else if (VReflection_checkbox.Checked)
{
lines.Add(new VisualCurve(new VerticalReflection(lines[i], panel1.Height)));
}
else
{
lines.Add(new VisualCurve(new HorizontalReflection(lines[i], panel1.Width)));
}
}
}
}
private void Generate_button_Click(object sender, EventArgs e)
{
Random random = new Random();
Func<int, int, IPoint> createRandomPoint = (min, max) => new Geometry.Point((float)random.Next(min, max), (float)random.Next(min, max));
IPoint a1 = createRandomPoint(200, 500);
IPoint b1 = createRandomPoint(200, 500);
IPoint a = createRandomPoint(200, 500);
IPoint b = createRandomPoint(200, 500);
IPoint c = createRandomPoint(200, 500);
IPoint d = createRandomPoint(200, 500);
while (lines.Count != countoflines)
{
lines.RemoveAt(lines.Count - 1);
}
ICurve line = new Line(a1, b1);
ICurve bezier = new Bezier(a, b, c, d);
lines.Add(new VisualCurve(line));
lines.Add(new VisualCurve(bezier));
countoflines += 2;
Reflection();
panel1.Refresh();
panel2.Refresh();
}
private void Clear_button_Click(object sender, EventArgs e)
{
if (lines.Count == 0) return;
countoflines = 0;
lines.Clear();
panel1.Refresh();
panel2.Refresh();
}
private void panel2_Paint(object sender, PaintEventArgs e)
{
if (lines.Count == 0) return;
IDrawer DottedDraw = new DottedDrawer(e.Graphics);
for (int i = 0; i < lines.Count; ++i)
{
lines[i].Draw(DottedDraw);
}
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
if (lines.Count == 0) return;
IDrawer ContinuousDraw = new ContinuousDrawer(e.Graphics);
for (int i = 0; i < lines.Count; ++i)
{
lines[i].Draw(ContinuousDraw);
}
}
private void ContinuousSave()
{
SVGContinuous svgContinuousDrawer = new SVGContinuous();
foreach (var line in lines)
{
line.Draw(svgContinuousDrawer);
}
string path = Directory.GetCurrentDirectory();
string filePath = Path.Combine(path, "ContinuousLines.svg");
File.WriteAllText(filePath, svgContinuousDrawer.GetContent().ToString() + "</svg>");
}
private void DottedSave()
{
SVGDotted svgDrawerDotted = new SVGDotted();
foreach (var line in lines)
{
line.Draw(svgDrawerDotted);
}
string path = Directory.GetCurrentDirectory();
string filePath = Path.Combine(path, "DottedLines.svg");
File.WriteAllText(filePath, svgDrawerDotted.GetContent().ToString() + "</svg>");
}
private void Save_Button_Clicked(object sender, EventArgs e)
{
ContinuousSave();
DottedSave();
}
}