import pygame import sys import random FPS = 60 WIDTH = 800 HEIGHT = 600 WHITE = (255, 255, 255) pygame.init() pygame.font.init() font = pygame.font.SysFont('Arial', 36) RANDCOLOR = (random.randint(0,255), random.randint(0,255), random.randint(0,255)) clock = pygame.time.Clock() sc = pygame.display.set_mode((WIDTH,HEIGHT)) x = WIDTH/2 y = HEIGHT/2 state = 10 r = 25 sc.fill(WHITE) while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.MOUSEBUTTONDOWN: state = 50 if event.type == pygame.MOUSEBUTTONUP: state = 10 if event.type == pygame.MOUSEMOTION: if state == 50: mouse_x, mouse_y = event.pos pygame.draw.circle(sc, RANDCOLOR, (mouse_x, mouse_y),r) if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: RANDCOLOR = (random.randint(0,255), random.randint(0,255), random.randint(0,255)) text_surface = font.render('Hello, Pygame!', True, RANDCOLOR) sc.blit(text_surface, (x-150, y)) pygame.display.update() clock.tick(FPS)
|