public void Draw(EasingFunctionBase easingFunction) { canvas1.Children.Clear(); var pathSegments = new PathSegmentCollection(); for (double i = 0; i < 1; i += SamplingInterval) { double x = i * canvas1.Width; double y = easingFunction.Ease(i) * canvas1.Height; var segment = new LineSegment(); segment.Point = new Point(x, y); pathSegments.Add(segment); } var p = new Path(); p.Stroke = new SolidColorBrush(Colors.Black); p.StrokeThickness = 3; var figures = new PathFigureCollection(); figures.Add(new PathFigure() { Segments = pathSegments }); p.Data = new PathGeometry() { Figures = figures }; canvas1.Children.Add(p); }
// Plots a graph of the passed easing function using the given sampling interval on the "Graph" Canvas control private void PlotEasingFunctionGraph(EasingFunctionBase easingFunction, double samplingInterval) { UISettings UserSettings = new UISettings(); Graph.Children.Clear(); Path path = new Path(); PathGeometry pathGeometry = new PathGeometry(); PathFigure pathFigure = new PathFigure() { StartPoint = new Point(0, 0) }; PathSegmentCollection pathSegmentCollection = new PathSegmentCollection(); // Note that an easing function is just like a regular function that operates on doubles. // Here we plot the range of the easing function's output on the y-axis of a graph. for (double i = 0; i < 1; i += samplingInterval) { double x = i * GraphContainer.Width; double y = easingFunction.Ease(i) * GraphContainer.Height; LineSegment segment = new LineSegment(); segment.Point = new Point(x, y); pathSegmentCollection.Add(segment); } pathFigure.Segments = pathSegmentCollection; pathGeometry.Figures.Add(pathFigure); path.Data = pathGeometry; path.Stroke = new SolidColorBrush(UserSettings.UIElementColor(UIElementType.ButtonText)); path.StrokeThickness = 1; // Add the path to the Canvas Graph.Children.Add(path); }