You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.9 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Signal_Generator
{
/// <summary>
/// Логика взаимодействия для TaskWindow.xaml
/// </summary>
public partial class TaskWindow : Window
{
MultiSignal currentMultiSignal;
public TaskWindow(MultiSignal s)
{
InitializeComponent();
currentMultiSignal = s;
}
public void drawSignal(MultiSignal s)
{
double lastX = 0, lastY = 0;
double w = signalGraph_Canvas.ActualWidth;
for (int i = 0; i != (int)w; i++)
{
double y = s.currentAmplitude(i / 5.0);
drawLine(lastX, lastY, i, y);
lastX = i;
lastY = y;
}
}
public void drawLine (double x1, double y1, double x2, double y2)
{
Line l = new Line();
l.StrokeThickness = 1;
l.Stroke = Brushes.Red;
l.X1 = x1;
l.Y1 = remap(y1);
l.X2 = x2;
l.Y2 = remap(y2);
signalGraph_Canvas.Children.Add(l);
}
public double remap (double x, double oldMin = -100.0, double oldMax = 100.0, double newMin = 100.0, double newMax = 0.0)
{
newMin = signalGraph_Canvas.ActualHeight;
return newMin + (x - oldMin) * (newMax - newMin) / (oldMax - oldMin);
}
private void start_Button_Click(object sender, RoutedEventArgs e)
{
drawSignal(currentMultiSignal);
}
}
}