Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jackbrookes
Created April 13, 2021 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackbrookes/812ac589f250fbcb27eb8c1522caa6ad to your computer and use it in GitHub Desktop.
Save jackbrookes/812ac589f250fbcb27eb8c1522caa6ad to your computer and use it in GitHub Desktop.
import pygame
import random
clr_red = (255, 0, 0)
clr_green = (0, 255, 0)
clr_blue = (0, 0, 255)
txt_red = "red"
txt_green = "green"
txt_blue = "blue"
trials = []
for colour in (clr_red, clr_green, clr_blue):
for text in (txt_red, txt_green, txt_blue):
trials.append((colour, text))
random.shuffle(trials)
# Setup
pygame.init()
screen = pygame.display.set_mode((640, 480))
font = pygame.font.SysFont(pygame.font.get_default_font(), 96)
clock = pygame.time.Clock()
screen.fill((255, 255, 255))
for trial in trials:
# Grab independent variables from the trial
colour = trial[0]
text = trial[1]
# Create text
text_img = font.render(text, True, colour)
text_rect = text_img.get_rect()
text_rect.center = (320, 240)
screen.blit(text_img, text_rect)
end_time = pygame.time.get_ticks() + 1000 # 1.0 second
while pygame.time.get_ticks() < end_time:
for event in pygame.event.get():
pass
pygame.display.flip()
# Create blank screen
screen.fill((255, 255, 255))
end_time = pygame.time.get_ticks() + 500 # 0.5 seconds
while pygame.time.get_ticks() < end_time:
for event in pygame.event.get():
pass
pygame.display.flip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment