Vitaliy_Novichikhin

2.2.13mycat

Jul 2nd, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.63 KB | None | 0 0
  1. # Import all needed figures for drawing and to plug drawing module:
  2. from matplotlib.patches import Circle, Wedge, Polygon, Ellipse, Arc, Path, PathPatch
  3. import matplotlib.pyplot as plt
  4. # Realise function for drawing figure.
  5. # Use the parametre for transfer of drawing region.
  6.  
  7. def draw_cat(ax):
  8.     #body
  9.     poly = [(3,1), (4, 14), (5,11), (8,11), (9,14), (10,1)]
  10.     polygon = Polygon(poly, fc = 'grey', ec = 'black', lw = '4')
  11.     #fc - facecolor, the fill color of the shape
  12.     # ec - edgecolor, color of the edge of the shape
  13.     #lw - linewidth, width of the border of the shape
  14.     ax.add_patch (polygon)
  15.     #eyes
  16.     circle = Circle((5.3, 8.5), 1.2, fc = 'white', ec = 'black', lw = 4)
  17.     ax.add_patch (circle)
  18.  
  19.     circle = Circle((7.7, 8.5), 1.2, fc = 'white', ec = 'black', lw = 4)
  20.     ax.add_patch (circle)
  21.  
  22.     #pupils of the eyes
  23.     circle = Circle((7, 8.3), 0.1, fc = 'black', ec = 'black', lw = 4)
  24.     ax.add_patch (circle)
  25.  
  26.     circle = Circle((6, 8.3), 0.1, fc = 'black', ec = 'black', lw = 4)
  27.     ax.add_patch (circle)
  28.  
  29.     #nose
  30.     circle = Circle ((6.5, 7.5), 0.3, fc = 'black', ec = 'black', lw = 4)
  31.     ax.add_patch (circle)
  32.  
  33.     #hind legs
  34.     wedge = Wedge((3, 1), 2, 86, 180, fc = 'grey', ec = 'black', lw = 4)
  35.     ax.add_patch (wedge)
  36.  
  37.     wedge = Wedge((10, 1), 2, 0, 94, fc = "grey", ec = 'black', lw = 4)
  38.     ax.add_patch (wedge)
  39.  
  40.     #forepaws
  41.     ellipse = Ellipse((5.5, 1.2), 2, 1.5, fc = 'grey', ec = 'black', lw = 4)
  42.     ax.add_patch (ellipse)
  43.  
  44.     ellipse = Ellipse((7.5, 1.2), 2, 1.5, fc = 'grey', ec = 'black', lw = 4)
  45.     ax.add_patch (ellipse)
  46.  
  47.     #smile
  48.     arc = Arc((6.5, 6.5), 5, 3, 0, 200, 340, lw = 4, fill = False)
  49.     #Is it arc of ellips of circle??????????????????????????????????????
  50.     ax.add_patch (arc)
  51.  
  52.     # line between nose and smile, moustashe
  53.     verticles = [(6.5, 5), (6.5, 7.5), (10, 6), (6.5, 7.5), (10, 6.5), (6.5, 7.5), (10, 7), (6.5, 7.5), (3, 6), (6.5, 7.5), (3, 6.5), (6.5, 7.5), (3, 7)]
  54.     # number 1 is appropriate matplotlib.path.Path.MOVETO command
  55.     # number 2 is appropriate matplotlib.path.Path.LINETO command
  56.     codes = [1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
  57.  
  58.     path = Path(verticles, codes)
  59.     path_patch = PathPatch(path, fill=False, lw=1)
  60.     ax.add_patch(path_patch)
  61.  
  62. #3. Set the size and coordinates of the working area.
  63. # It will compare and match of the drawing
  64. n = 13
  65. m = 15
  66. plt.xlim(0, n)
  67. plt.ylim(0, m)
  68.  
  69. #4. Create the coordinates area where we can show flat figures (ax).
  70. # Сall function draw_cat:
  71. ax = plt.gca()
  72. draw_cat(ax)
  73. plt.show()
  74. #5. Delete all axes and show the picture
  75. ax.axes.set_axis_off()
  76. plt.show()
Add Comment
Please, Sign In to add comment