Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.0 kB
3
Indexable
Never
import matplotlib.pyplot as plt
import numpy as np

def generate_cat():
    # Head
    head = plt.Circle((0.5, 0.5), 0.3, color='gray', ec='black')

    # Ears
    left_ear = plt.Polygon([[0.35, 0.8], [0.4, 0.65], [0.3, 0.65]], color='gray', ec='black')
    right_ear = plt.Polygon([[0.65, 0.8], [0.6, 0.65], [0.7, 0.65]], color='gray', ec='black')

    # Eyes
    left_eye = plt.Circle((0.4, 0.55), 0.05, color='white', ec='black')
    right_eye = plt.Circle((0.6, 0.55), 0.05, color='white', ec='black')
    left_pupil = plt.Circle((0.4, 0.55), 0.02, color='black')
    right_pupil = plt.Circle((0.6, 0.55), 0.02, color='black')

    # Nose
    nose = plt.Polygon([[0.5, 0.45], [0.48, 0.43], [0.52, 0.43]], color='pink', ec='black')

    # Mouth
    mouth_left = plt.Line2D([0.48, 0.47], [0.43, 0.4], color='black')
    mouth_right = plt.Line2D([0.52, 0.53], [0.43, 0.4], color='black')

    # Whiskers
    whisker_left1 = plt.Line2D([0.3, 0.45], [0.45, 0.45], color='black')
    whisker_left2 = plt.Line2D([0.3, 0.45], [0.43, 0.43], color='black')
    whisker_left3 = plt.Line2D([0.3, 0.45], [0.47, 0.47], color='black')

    whisker_right1 = plt.Line2D([0.7, 0.55], [0.45, 0.45], color='black')
    whisker_right2 = plt.Line2D([0.7, 0.55], [0.43, 0.43], color='black')
    whisker_right3 = plt.Line2D([0.7, 0.55], [0.47, 0.47], color='black')

    fig, ax = plt.subplots()
    ax.add_patch(head)
    ax.add_patch(left_ear)
    ax.add_patch(right_ear)
    ax.add_patch(left_eye)
    ax.add_patch(right_eye)
    ax.add_patch(left_pupil)
    ax.add_patch(right_pupil)
    ax.add_patch(nose)
    ax.add_line(mouth_left)
    ax.add_line(mouth_right)
    ax.add_line(whisker_left1)
    ax.add_line(whisker_left2)
    ax.add_line(whisker_left3)
    ax.add_line(whisker_right1)
    ax.add_line(whisker_right2)
    ax.add_line(whisker_right3)

    ax.set_aspect('equal')
    ax.set_xlim(0, 1)
    ax.set_ylim(0, 1)
    ax.axis('off')

    plt.show()

generate_cat()
Leave a Comment