Untitled
unknown
plain_text
2 years ago
1.2 kB
4
Indexable
import pygame # initialize Pygame pygame.init() # set the size of the screen screen_width = 400 screen_height = 400 screen = pygame.display.set_mode((screen_width, screen_height)) # define the colors red = (255, 0, 0) white = (255, 255, 255) # draw the hat hat_width = 100 hat_height = 100 hat_pos_x = (screen_width - hat_width) // 2 hat_pos_y = (screen_height - hat_height) // 2 pygame.draw.rect(screen, red, (hat_pos_x, hat_pos_y, hat_width, hat_height)) # draw the brim of the hat brim_width = 150 brim_height = 50 brim_pos_x = (screen_width - brim_width) // 2 brim_pos_y = hat_pos_y + hat_height pygame.draw.rect(screen, red, (brim_pos_x, brim_pos_y, brim_width, brim_height)) # draw a white circle on the front of the hat circle_radius = 20 circle_pos_x = (screen_width - circle_radius) // 2 circle_pos_y = hat_pos_y + (hat_height - circle_radius) // 2 pygame.draw.circle(screen, white, (circle_pos_x, circle_pos_y), circle_radius) # update the screen pygame.display.update() # wait for the user to close the window running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # quit Pygame pygame.quit()
Editor is loading...