Advertisement
Guest User

Untitled

a guest
Dec 9th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. public void Draw_tree(double level, double x, double y, double angle1, double angle2, double coefficient)
  2. {
  3. angle1 = angle1 * pi / 180;
  4. angle2 = angle2 * pi / 180;
  5. double length = (y - y / 3 * 2);
  6. double x1 = x, y1 = y / 3 * 2, x2 = x, y2 = y / 3 * 2;
  7. double xLeft, yLeft, xRight, yRight;
  8. if (level == 0) graph.DrawLine(pen, (int)x, (int)y, (int)x, (int)(y * 2 / 3));
  9. else
  10. {
  11. xLeft = x1 - length * Math.Cos(pi / 2 - angle1) * coefficient;
  12. yLeft = y1 - length * Math.Sin(pi / 2 - angle1) * coefficient;
  13. xRight = x2 + length * Math.Cos(pi / 2 - angle2) * coefficient;
  14. yRight = y2 - length * Math.Sin(pi / 2 - angle2) * coefficient;
  15.  
  16. graph.DrawLine(pen, (int)x1, (int)y1, (int)xLeft, (int)yLeft);
  17. graph.DrawLine(pen, (int)x2, (int)y2, (int)xRight, (int)yRight);
  18.  
  19. x1 = xLeft;
  20. y1 = yLeft;
  21. x2 = xRight;
  22. y2 = yRight;
  23.  
  24. Draw_tree(level - 1, x1, y1, angle1, angle2, coefficient);
  25. Draw_tree(level - 1, x2, y2, angle1, angle2, coefficient);
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement