-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
107 lines (100 loc) · 2.7 KB
/
Program.cs
File metadata and controls
107 lines (100 loc) · 2.7 KB
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
using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using ZedGraph;
namespace yield
{
class Program
{
private readonly Form form;
private readonly ZedGraphControl chart;
private volatile bool paused;
private volatile bool canceled;
private Thread thread;
private readonly PointPairList originalPoints;
private readonly PointPairList expPoints;
private readonly PointPairList avgPoints;
private readonly PointPairList maxPoints;
public Program()
{
form = new Form
{
WindowState = FormWindowState.Maximized,
Text = "Press any key to pause / resume"
};
chart = new ZedGraphControl()
{
Dock = DockStyle.Fill
};
chart.GraphPane.Title.Text = "Сравнение методов сглаживания";
chart.GraphPane.XAxis.Title.Text = "X";
chart.GraphPane.YAxis.Title.Text = "Y";
chart.GraphPane.XAxis.Scale.MaxAuto = true;
chart.GraphPane.XAxis.Scale.MinAuto = true;
chart.GraphPane.YAxis.Scale.MaxAuto = true;
chart.GraphPane.YAxis.Scale.MinAuto = true;
originalPoints = new PointPairList();
var original = chart.GraphPane.AddCurve("original", originalPoints, Color.Black, SymbolType.None);
original.Line.IsAntiAlias = true;
avgPoints = AddCurve("avg", Color.Blue);
expPoints = AddCurve("exp", Color.Red);
maxPoints = AddCurve("max", Color.Green);
form.Controls.Add(chart);
chart.KeyDown += (sender, args) => paused = !paused;
form.FormClosing += (sender, args) => { canceled = true; };
form.Shown += OnShown;
}
private PointPairList AddCurve(string label, Color color)
{
var curve = new PointPairList();
var line = chart.GraphPane.AddCurve(label, curve, color, SymbolType.None);
line.Line.Width = 3;
line.Line.IsAntiAlias = true;
return curve;
}
private void OnShown(object sender, EventArgs e)
{
thread = new Thread(() =>
{
try
{
foreach (var point in DataSource.GetData(new Random()))
{
if (canceled) return;
var pointCopy = point;
var invokation = form.BeginInvoke((Action)(() => AddPoint(pointCopy)));
while (paused && !canceled) Thread.Sleep(20);
Thread.Sleep(20);
form.EndInvoke(invokation);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
})
{ IsBackground = true };
thread.Start();
}
[STAThread]
static void Main()
{
new Program().Run();
}
private void Run()
{
Application.Run(form);
}
private void AddPoint(DataPoint p)
{
originalPoints.Add(p.X, p.OriginalY);
avgPoints.Add(p.X, p.AvgSmoothedY);
expPoints.Add(p.X, p.ExpSmoothedY);
maxPoints.Add(p.X, p.MaxY);
chart.AxisChange();
chart.Invalidate();
chart.Refresh();
}
}
}