using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace PamhagenSysCtrl.Helpers.Pipeline { public class Auger { public double CenterX { get; set; } public double CenterY { get; set; } public double Width { get; set; } public double Height { get; set; } public bool IsActive { set { if (value) { _storyboard?.Resume(); } else { _storyboard?.Pause(); } } } private Polyline? _polyline; private Storyboard? _storyboard; public Auger(double x, double y, double width, double height) { CenterX = x; CenterY = y; Width = width; Height = height; } public void Draw(Canvas canvas) { var d = Height / 4; int n = (int)(Width / d / 4) + 2; _polyline = new Polyline() { Points = [.. Enumerable.Range(0, n).SelectMany(i => new List() { new(i * 4 * d, Height / 2), new((i * 4 + 1) * d, 0), new((i * 4 + 2) * d, Height / 2), new((i * 4 + 3) * d, Height) }), new(n * 4 * d, Height / 2), new(0, Height / 2)], Fill = Brushes.Transparent, Stroke = Brushes.Black, StrokeThickness = 2, }; _polyline.SetValue(Canvas.LeftProperty, 0.0); var slideLeft = new DoubleAnimation { From = 0, To = -d * 4, Duration = new Duration(TimeSpan.FromSeconds(1)), RepeatBehavior = RepeatBehavior.Forever, }; _storyboard = new Storyboard(); _storyboard.Children.Add(slideLeft); Storyboard.SetTarget(slideLeft, _polyline); Storyboard.SetTargetProperty(slideLeft, new PropertyPath(Canvas.LeftProperty)); var clipCanvas = new Canvas() { Width = Width, Height = Height, ClipToBounds = true, }; clipCanvas.SetValue(Canvas.TopProperty, CenterY - Height / 2); clipCanvas.SetValue(Canvas.LeftProperty, CenterX - Width / 2); clipCanvas.Children.Add(_polyline); canvas.Children.Add(clipCanvas); _storyboard.Begin(); _storyboard.Pause(); } } }