public LaneDisplay() { InitializeComponent(); var fill = BoatColor.Clone(); fill.Opacity = 0.5; boat.Stroke = Brushes.Black; boat.Fill = fill; canvas.Children.Add(boat); canvas.Loaded += Canvas_Loaded; }
private void HandleDistanceChanged() { var canvasWidth = canvas.ActualWidth; var canvasHeight = canvas.ActualHeight; canvas.Background = WaterColor; //paint the lines var smallLines = GetLines(10, BaseDistance, MaxDistance, canvasWidth, 1.0); foreach (var line in smallLines) { canvas.Children.Add(line); } var bigLines = GetLines(100, BaseDistance, MaxDistance, canvasWidth, 3.0); foreach (var line in bigLines) { canvas.Children.Add(line); } //do not paint the boat when it is outside of our range to display if (Math.Abs(CurrentDistance) > MaxDistance) { return; } //paint the boat var currentPosPoint = (canvasWidth / 2.0) + ((CurrentDistance / MaxDistance) * (canvasWidth / 2.0)); var actualBoatSize = 8.2; var canvasBoatSize = (actualBoatSize / (MaxDistance * 2.0)) * canvasWidth; var upperBounds = canvasHeight / 4.0; var lowerBounds = canvasHeight - (canvasHeight / 4.0); var upperBoundsBack = canvasHeight / 3.0; var lowerBoundsBack = canvasHeight - (canvasHeight / 3.0); var points = new PointCollection(); points.Add(new Point(currentPosPoint, canvasHeight / 2.0)); points.Add(new Point(currentPosPoint - canvasBoatSize / 2.0, upperBounds)); points.Add(new Point(currentPosPoint - canvasBoatSize, upperBoundsBack)); points.Add(new Point(currentPosPoint - canvasBoatSize, lowerBoundsBack)); points.Add(new Point(currentPosPoint - canvasBoatSize / 2.0, lowerBounds)); boat.Points = points; //display the boat redder when it is making pace, bluer when it slows down var limitedPaceProgression = Math.Abs(PaceProgression); if (limitedPaceProgression > 10.0) { limitedPaceProgression = 10.0; //a change in pace for more than 10 seconds should be displayed in bright color. Doesn't matter if its just 11 seconds or 60 seconds } if (limitedPaceProgression < 1.0) { limitedPaceProgression = 0.0; //do not display every small change in pace... Boats are lighting up left and right if we don't cap that } byte red = 0; byte green = 0; byte blue = 0; var modifier = (byte)((limitedPaceProgression / 10.0) * 255.0); if (PaceProgression > 0.0) { blue += modifier; } else { red += modifier; } boat.Stroke = new SolidColorBrush(new Color() { A = 255, R = red, G = green, B = blue }); var fill = BoatColor.Clone(); fill.Opacity = 0.5; boat.Fill = fill; boat.StrokeThickness = 6.0; canvas.InvalidateVisual(); }