Guest User

Untitled

a guest
Jun 21st, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. private void UpdatePolygon(ref Polygon poly, int value, int posX, int posY, int maxHeight, int historyLength = 30)
  2. {
  3. int v = 100 / maxHeight;
  4. value = value == 0 ? value : value / v;
  5. value = value * -1; // expand up
  6.  
  7. int length = 0;
  8. System.Windows.Point end = new System.Windows.Point(historyLength + posX + 1, posY);
  9.  
  10. // Create a blue and black Brush
  11. SolidColorBrush whiteBrush = new SolidColorBrush();
  12. whiteBrush.Color = Colors.White;
  13. SolidColorBrush blackBrush = new SolidColorBrush();
  14. blackBrush.Color = Colors.Black;
  15.  
  16. // Create a Polygon
  17. if (poly == null)
  18. {
  19. PointCollection polygonPoints = new PointCollection();
  20.  
  21. // Create a collection of points for a polygon
  22. System.Windows.Point Point1 = new System.Windows.Point(posX + 3, posY);
  23. poly = new Polygon();
  24. poly.Stroke = whiteBrush;
  25.  
  26. poly.StrokeThickness = 0.5;
  27. poly.Points.Add(end);
  28.  
  29. polygonPoints.Add(Point1);
  30.  
  31. for (int i = 0; i < historyLength; i++)
  32. {
  33. polygonPoints.Add(new System.Windows.Point(i + posX + 3, posY));
  34. }
  35.  
  36. // Set Polygon.Points properties
  37. poly.Points = polygonPoints;
  38. poly.Name = "poly";
  39.  
  40. // Add Polygon to the page
  41. grid.Children.Add(poly);
  42. poly.Fill = whiteBrush;
  43. }
  44.  
  45. length = poly.Points.Count;
  46.  
  47. poly.Points.RemoveAt(1);
  48.  
  49. for (int i = 1; i < historyLength - 1; i++)
  50. {
  51. System.Windows.Point p = poly.Points[i];
  52. p.X -= 1;
  53. poly.Points[i] = p;
  54. }
  55.  
  56. poly.Points.RemoveAt(length - 2);
  57. poly.Points.Add(new System.Windows.Point((length) + posX, value + posY));
  58. poly.Points.Add(end);
  59. }
Add Comment
Please, Sign In to add comment