Различные методы рисования круга в Python: Turtle, Matplotlib и Pygame

Вот пример того, как нарисовать круг в Python разными методами:

Метод 1. Использование модуля черепахи

import turtle
# Create a turtle object
t = turtle.Turtle()
# Draw a circle
t.circle(50)
# Keep the window open
turtle.done()

Метод 2: использование библиотеки matplotlib

import matplotlib.pyplot as plt
# Create a figure and axes
fig, ax = plt.subplots()
# Draw a circle
circle = plt.Circle((0.5, 0.5), 0.3, fill=False)
ax.add_artist(circle)
# Set the aspect ratio of the plot to equal
ax.set_aspect('equal')
# Display the plot
plt.show()

Метод 3. Использование библиотеки pygame

import pygame
# Initialize Pygame
pygame.init()
# Set the width and height of the screen
width, height = 500, 500
screen = pygame.display.set_mode((width, height))
# Set the center and radius of the circle
center = (250, 250)
radius = 50
# Draw a circle
pygame.draw.circle(screen, (255, 0, 0), center, radius)
# Update the display
pygame.display.flip()
# Keep the window open
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
# Quit Pygame
pygame.quit()