"""A small scene built only from pygame.draw calls.""" import math import pygame WIDTH, HEIGHT = 640, 480 pygame.init() screen = pygame.display.set_mode((WIDTH, HEIGHT)) clock = pygame.time.Clock() def draw_house(surface, x, y): pygame.draw.rect(surface, (210, 120, 90), (x, y, 160, 120)) # walls pygame.draw.polygon(surface, (150, 60, 50), [(x - 15, y), (x + 80, y - 70), (x + 175, y)]) # roof pygame.draw.rect(surface, (90, 60, 40), (x + 62, y + 60, 36, 60)) # door pygame.draw.circle(surface, (244, 197, 49), (x + 90, y + 92), 3) # door knob for wx in (x + 15, x + 115): # windows pygame.draw.rect(surface, (200, 230, 255), (wx, y + 25, 30, 30)) pygame.draw.rect(surface, (60, 40, 30), (wx, y + 25, 30, 30), width=3) pygame.draw.line(surface, (60, 40, 30), (wx + 15, y + 25), (wx + 15, y + 54), 2) def draw_tree(surface, x, y): pygame.draw.rect(surface, (110, 75, 45), (x - 8, y, 16, 60)) pygame.draw.circle(surface, (60, 150, 80), (x, y - 10), 38) pygame.draw.circle(surface, (80, 175, 95), (x - 18, y - 22), 22) t = 0.0 running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False t += clock.tick(60) / 1000 screen.fill((170, 210, 245)) # sky sun_y = 90 + math.sin(t) * 10 pygame.draw.circle(screen, (250, 210, 70), (520, sun_y), 45) # sun for i in range(12): # sun rays angle = t * 0.5 + i * math.tau / 12 start = (520 + math.cos(angle) * 55, sun_y + math.sin(angle) * 55) end = (520 + math.cos(angle) * 75, sun_y + math.sin(angle) * 75) pygame.draw.line(screen, (250, 210, 70), start, end, 4) pygame.draw.ellipse(screen, (255, 255, 255), (80, 60, 140, 50)) # cloud pygame.draw.rect(screen, (100, 170, 90), (0, 360, WIDTH, 120)) # grass draw_house(screen, 220, 240) draw_tree(screen, 110, 300) draw_tree(screen, 500, 310) pygame.draw.lines(screen, (120, 90, 60), False, [(0, 420), (160, 400), (300, 430), (640, 405)], 3) # path pygame.display.flip() pygame.quit()