Skip to main content

CircleBug — wiki

#circle.py
import pygame

def draw_outlined_circle2(surf, color, origin, radius, thickness):
    width = radius * 2 + thickness * 2
    background = (0, 0, 0, 0)
    circle = pygame.Surface((width, width)).convert_alpha()
    rect = circle.get_rect()
    circle.fill(background)
    pygame.draw.circle(circle, color, rect.center, radius)
    pygame.draw.circle(circle, background, rect.center, radius - thickness)
    surf.blit(circle, (origin[0] - (rect.w / 2), origin[1] - (rect.w / 2)))

def draw_outlined_circle0(surf, color, origin, radius, thickness):
    pygame.draw.circle(surf, color, origin, radius)
    pygame.draw.circle(surf, (0, 0, 0, 255), origin, radius - thickness)

surf = pygame.Surface((2000,2000))
radius = 508
thickness = 50
draw_with_pygame = True


pygame.init()
screen = pygame.display.set_mode((1024, 768))
pygame.display.set_caption('space - toggle draw with pygame(red), escape - quit')
pygame.display.flip()

pygame.draw.circle(surf, pygame.Color("red"), (500, 500), radius, thickness)

screen.blit(surf, (0,0))
pygame.display.flip()
going = True

while going:
    events = pygame.event.get()
    for e in events:
        if (e.type == pygame.QUIT or
           (e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE)):
            going = False
        if e.type == pygame.KEYDOWN and e.key == pygame.K_SPACE:
            draw_with_pygame = not draw_with_pygame
            if draw_with_pygame:
                pygame.draw.circle(surf, pygame.Color("red"), (500, 500), radius, thickness)
            else:
                draw_outlined_circle2(surf, pygame.Color("white"), (750, 750), radius, thickness)
            screen.blit(surf, (0,0))
            color_name = 'red' if draw_with_pygame else 'white'
            msg = 'space - toggle draw with pygame(%s):%s, escape - quit' % (color_name, draw_with_pygame)
            pygame.display.set_caption(msg)
pygame.display.flip()