Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. import random
  2. import matplotlib.pyplot as plt
  3.  
  4.  
  5. def main():
  6. draw_points()
  7.  
  8.  
  9. def generate_random_points():
  10. number_of_points = 30
  11. points = []
  12. for i in range(0, number_of_points):
  13. x, y = random.randint(1, 30), random.randint(1, 30)
  14. points.append((x, y))
  15. return points
  16.  
  17.  
  18. def draw_points():
  19. points = generate_random_points()
  20. graham(points)
  21. plt.plot(points, 'ro')
  22. plt.ylabel('Tygrysy')
  23. plt.show()
  24.  
  25.  
  26. def minimum(points):
  27. x, y = [], []
  28. for i in range(0,30):
  29. x.append(points[i][0])
  30. y.append(points[i][1])
  31. minimum_index = y.index(min(item for item in y))
  32. return x[minimum_index], y[minimum_index]
  33.  
  34.  
  35. def graham(points):
  36. minimum_x, minimum_y = minimum(points)
  37. x_moved, y_moved = [], []
  38. touple_of_moved_points = []
  39. for i in range(0, 30):
  40. x_moved.append(points[i][0] - minimum_x)
  41. y_moved.append(points[i][1] - minimum_y)
  42. touple_of_moved_points.append((x_moved[i], y_moved[i]))
  43. plt.plot(touple_of_moved_points, 'bo')
  44. plt.ylabel('Tygrysy')
  45.  
  46.  
  47.  
  48. if __name__ == "__main__":
  49. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement