// This method performs some animations. private void timer1_Tick(object sender, EventArgs e) { if (tabControl1.SelectedTab == tabPage2) { // Animate the points. PointDataSeries ds = chartPlotter1.DataSeries[0] as PointDataSeries; for (int i = 0; i < ds.Points.Count; i++) { PointDataSeries.ChartPoint s = ds.Points[i]; s.Coords.X += (float)((randGen.NextDouble() - 0.5) / 100.0); s.Coords.Y += (float)((randGen.NextDouble() - 0.5) / 100.0); ds.Points[i] = s; } } else if (tabControl1.SelectedTab == tabPage1) { // Animate the cosine function. if (++tickCounter == 100) { tickCounter = 0; } cosFun.Scale = Math.Sin(tickCounter / 50.0 * Math.PI) * 2.0 + 3.0; } else if (tabControl1.SelectedTab == tabPage5) { if (checkBox3.Checked) { MakeNoise(); } } }
private void trackBar1_Scroll(object sender, EventArgs e) { PointDataSeries ds = chartPlotter1.DataSeries[0] as PointDataSeries; while (ds.Points.Count > trackBar1.Value) { ds.Points.RemoveAt(ds.Points.Count - 1); } while (ds.Points.Count < trackBar1.Value) { PointF coords = new PointF( (float)randGen.NextDouble() - 0.5f, (float)randGen.NextDouble() - 0.5f); Color col = Color.FromArgb( randGen.Next(256), randGen.Next(256), randGen.Next(256)); PointDataSeries.PointShape shape = randGen.Next(2) > 0 ? PointDataSeries.PointShape.Circle : PointDataSeries.PointShape.Square; ds.Points.Add(new PointDataSeries.ChartPoint( coords, col, true, shape)); } }
public Form1() { InitializeComponent(); // Initialize the point chart. PointDataSeries pds = new PointDataSeries(); chartPlotter1.DataSeries.Add(pds); chartPlotter1.VisibleRectangle = new RectangleF(-0.5f, -0.5f, 1.0f, 1.0f); // Initialize the "precomputed" linear function. ListDataSeries ds = new ListDataSeries(100); for (int i = 0; i < 100; i++) { float x = i / 10f - 5f; ds.Data.Add(new PointF(x, -x)); } ds.ForeColor = Color.Red; chartPlotter2.DataSeries.Add(ds); // Initialize the "precomputed" sine function. ds = new ListDataSeries(20); ds.LineWidth = 2.0f; for (int i = 0; i < 20; i++) { float x = i / 2.0f; ds.Data.Add(new PointF(x, 9 * (float)Math.Sin(x))); } ds.ForeColor = Color.Blue; chartPlotter2.DataSeries.Add(ds); // Initialize the linear function. ComputedDataSeries ds2 = new ComputedDataSeries(); ds2.LineWidth = 3.0f; ds2.Function = delegate(double x) { return(x); }; ds2.ForeColor = Color.Green; chartPlotter2.DataSeries.Add(ds2); // Initialize the parametrized cosine function. ds2 = new ComputedDataSeries(); ds2.FunctionObject = cosFun; ds2.AntiAlias = true; chartPlotter2.DataSeries.Add(ds2); // Initialize some plots under the 2D surface. ds2 = new ComputedDataSeries(); ds2.Function = delegate(double arg) { return(Math.Sin(arg) * 5.0); }; ds2.LineWidth = 2; ds2.AntiAlias = true; //chartPlotter3.DataSeries.Add(ds2); // Initialize the 2D surface. Computed2DSeries ds3 = new Computed2DSeries(); /*ds3.Function = delegate(double x, double y) * { * return Color.FromArgb( * (int)((Math.Cos(x / 2.0) + 1.0) * 127.5), * (int)(Math.Abs(Math.Sin(x + y)) * 255.0), * (int)(Math.Abs(Math.Sin(x - y)) * 255.0), * (int)(Math.Abs(Math.Sin(y)) * 255.0)); * };*/ ds3.Function = delegate(double x, double y) { double x0 = x, y0 = y; double x2, y2; int i = 255; while ((x2 = x * x) + (y2 = y * y) < 100.0 && i > 0) { double xnew = x2 - y2 + x0; double ynew = 2 * x * y + y0; x = xnew; y = ynew; i--; } return(Color.FromArgb(i, i, i)); }; chartPlotter3.DataSeries.Add(ds3); chartPlotter3.VisibleRectangle = new RectangleF(-2f, -2f, 4f, 4f); // Initialize the network response function. CreateNetwork(); ds3 = new Computed2DSeries(); ds3.FunctionObject = netFun; netFun.OutputOffset = 0.5; netFun.OutputScale = 0.5; netFun.NeuralNetwork = _network; chartPlotter4.DataSeries.Add(ds3); chartPlotter4.VisibleRectangle = new RectangleF(-1.0f, -1.0f, 2.0f, 2.0f); _neuronLines.ForeColor = Color.White; _neuronLines.ContinuousLine = false; // Initialize the history plotter. chartPlotter5.DataSeries.Add(_historyLines1); chartPlotter5.DataSeries.Add(_historyLines2); _historyLines1.ForeColor = Color.Blue; _historyLines1.StepLengthMode = HistoryDataSeries.LengthMode.Screen; _historyLines1.StepLength = 2.0f; _historyLines2.ForeColor = Color.Red; _historyLines2.StepLength = 0.5f; }