Guest User

Untitled

a guest
Dec 9th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. public void drawTriangle(PaintEventArgs e, int x, int y, int distance)
  2. {
  3. float angle = 0;
  4.  
  5. SolidBrush brs = new SolidBrush(Color.Green);
  6.  
  7. PointF[] p = new PointF[3];
  8.  
  9. p[0].X = x;
  10.  
  11. p[0].Y = y;
  12.  
  13. p[1].Y = (float)( x + distance * Math.Cos(angle + Math.PI / 3));
  14.  
  15. p[1].X = (float)( y + distance * Math.Sin(angle + Math.PI / 3));
  16.  
  17. p[2].Y = (float)( x + distance * Math.Cos(angle - Math.PI / 3));
  18.  
  19. p[2].X = (float)( y + distance * Math.Sin(angle - Math.PI / 3));
  20.  
  21. e.Graphics.FillPolygon(brs, p);
  22. }
  23.  
  24. p[0].X = x;
  25.  
  26. p[0].Y = y;
  27.  
  28. p[1].X = (float)( x + distance * Math.Cos(angle));
  29.  
  30. p[1].Y = (float)( y + distance * Math.Sin(angle));
  31.  
  32. p[2].X = (float)( x + distance * Math.Cos(angle + Math.PI / 3));
  33.  
  34. p[2].Y = (float)( y + distance * Math.Sin(angle + Math.PI / 3));
  35.  
  36. var size = int.Parse(Console.ReadLine());
  37. for (int i = 1; i <= size; i++)
  38. {
  39. int leftPadding = 1 + (((2 * size - 1) - (2 * i + 1)) / 2);
  40. StringBuilder build = new StringBuilder();
  41. build.Append(new string(Enumerable.Repeat(' ', leftPadding > 0 ? leftPadding: 0).ToArray()));
  42. for (int j = 1; j <= i; j++)
  43. {
  44. build.Append("* ");
  45. }
  46. Console.WriteLine(build.ToString());
  47. }
Add Comment
Please, Sign In to add comment