import pygame import pygame.locals import random pygame.init() sz = 100 screen=pygame.display.set_mode((3 * sz, 3 * sz)) pygame.display.set_caption('Drawing') clr = (0, 0, 0) wht = (255,255,255) def draw(): # clear screen screen.fill((255,255,255)) # circle(surface, color, center, radius, width=0) pygame.draw.circle(screen, clr, (int(sz * 1.5), sz), int(sz * 0.5)) pygame.draw.circle(screen, wht, (int(sz * 1.25), sz), int(sz * 0.24)) pygame.draw.circle(screen, wht, (int(sz * 1.75), sz), int(sz * 0.24)) pygame.draw.circle(screen, clr, (int(sz * 1.5), int(sz * 1.7)), int(sz * 0.5), 2) # rect(surface, color, rect) where rect = (left, top, width, height) pygame.draw.rect(screen, wht, (sz, sz, sz, int(sz * 0.7))) if (random.randint(1, 10) > 1): pygame.draw.circle(screen, clr, (int(sz * 1.25), sz), int(sz * 0.05)) pygame.draw.circle(screen, clr, (int(sz * 1.75), sz), int(sz * 0.05)) # line(surface, color, start_pos, end_pos) pygame.draw.line(screen, clr, (sz, sz), (sz, int(sz*1.7)), 2) pygame.draw.line(screen, clr, (sz * 2 - 2, sz), (sz * 2 - 2, int(sz*1.7)), 2) pygame.draw.line(screen, clr, (int(sz * 1.45), int(sz * 1.55)), (int(sz*1.5), int(sz*1.65)), 2) pygame.draw.line(screen, clr, (int(sz * 1.55), int(sz * 1.55)), (int(sz*1.5), int(sz*1.65)), 2) clock = pygame.time.Clock() running = True while running: for event in pygame.event.get(): if event.type == pygame.locals.QUIT: running = False # ignore all other events draw() pygame.display.update() # time delay # from the raspberry spoon game # https://www.pygame.org/docs/ref/time.html clock.tick(6) pygame.quit()