Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void UpdatePolygon(ref Polygon poly, int value, int posX, int posY, int maxHeight, int historyLength = 30)
- {
- int v = 100 / maxHeight;
- value = value == 0 ? value : value / v;
- value = value * -1; // expand up
- int length = 0;
- System.Windows.Point end = new System.Windows.Point(historyLength + posX + 1, posY);
- // Create a blue and black Brush
- SolidColorBrush whiteBrush = new SolidColorBrush();
- whiteBrush.Color = Colors.White;
- SolidColorBrush blackBrush = new SolidColorBrush();
- blackBrush.Color = Colors.Black;
- // Create a Polygon
- if (poly == null)
- {
- PointCollection polygonPoints = new PointCollection();
- // Create a collection of points for a polygon
- System.Windows.Point Point1 = new System.Windows.Point(posX + 3, posY);
- poly = new Polygon();
- poly.Stroke = whiteBrush;
- poly.StrokeThickness = 0.5;
- poly.Points.Add(end);
- polygonPoints.Add(Point1);
- for (int i = 0; i < historyLength; i++)
- {
- polygonPoints.Add(new System.Windows.Point(i + posX + 3, posY));
- }
- // Set Polygon.Points properties
- poly.Points = polygonPoints;
- poly.Name = "poly";
- // Add Polygon to the page
- grid.Children.Add(poly);
- poly.Fill = whiteBrush;
- }
- length = poly.Points.Count;
- poly.Points.RemoveAt(1);
- for (int i = 1; i < historyLength - 1; i++)
- {
- System.Windows.Point p = poly.Points[i];
- p.X -= 1;
- poly.Points[i] = p;
- }
- poly.Points.RemoveAt(length - 2);
- poly.Points.Add(new System.Windows.Point((length) + posX, value + posY));
- poly.Points.Add(end);
- }
Add Comment
Please, Sign In to add comment