0

I am new to pygame and making an illustrator. I know to how to make an circle in pygame using pygame.draw.circle() but how do i draw a oval in pygame?

1 Answers1

1

You can draw an ellipse with pygame.draw.ellipse:

import 
pygame.init()

screen = pygame.display.set_mode((300, 300))
clock = pygame.time.Clock()

run = True
while run:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False 

    screen.fill(0)
    pygame.draw.ellipse(screen, "red", (50, 100, 200, 100), 3)
    pygame.display.flip()
    clock.tick(60)

pygame.quit()
exit()

See also drawing a diagonal ellipse with pygame


You can also use this with the code from one of your previous questions (How to remove the previous rect draw in pygame?):

import pygame 
pygame.init()

window = pygame.display.set_mode((1000, 700), pygame.RESIZABLE)
clock = pygame.time.Clock()
pygame.display.set_caption("Illustrator")

def main():
    run = True
    rectangles = []
    start_of_new_rect = None
    while run:
        clock.tick(100)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False
                
            if event.type == pygame.MOUSEBUTTONDOWN:
                start_of_new_rect = event.pos
                print(start_of_new_rect)
                
            if event.type == pygame.MOUSEBUTTONUP:
                w = event.pos[0] - start_of_new_rect[0]
                h = event.pos[1] - start_of_new_rect[1] 
                new_rect = pygame.Rect(*start_of_new_rect, w, h)
                new_rect.normalize()
                rectangles.append(new_rect)
                start_of_new_rect = None
   
        window.fill("white")

        # draw the scene
        for r in rectangles:
            pygame.draw.ellipse(window, "blue", r)
        if start_of_new_rect:
            mx, my = pygame.mouse.get_pos()
            new_rect = pygame.Rect(*start_of_new_rect, mx - start_of_new_rect[0],  my - start_of_new_rect[1])
            new_rect.normalize()
            pygame.draw.ellipse(window, "blue", new_rect)

        pygame.display.flip()

    pygame.quit()

if __name__ == "__main__":
    main()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174