-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstroopTest.py
More file actions
69 lines (56 loc) · 1.97 KB
/
stroopTest.py
File metadata and controls
69 lines (56 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import pygame
import random
import time
pygame.init()
# Set up display
screen = pygame.display.set_mode((600, 400))
pygame.display.set_caption("Stroop Test")
# Define colors
colors = {'RED': (255, 0, 0), 'GREEN': (0, 255, 0), 'BLUE': (0, 0, 255), 'YELLOW': (255, 255, 0)}
color_names = list(colors.keys())
font = pygame.font.SysFont(None, 80)
def draw_text(word, color):
screen.fill((255, 255, 255))
text = font.render(word, True, color)
rect = text.get_rect(center=(300, 200))
screen.blit(text, rect)
pygame.display.flip()
def stroop_trial():
word = random.choice(color_names)
ink = colors[random.choice(color_names)]
correct_color = [k for k, v in colors.items() if v == ink][0]
draw_text(word, ink)
start_time = time.time()
waiting = True
user_input = None
while waiting:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_r:
user_input = 'RED'
waiting = False
elif event.key == pygame.K_g:
user_input = 'GREEN'
waiting = False
elif event.key == pygame.K_b:
user_input = 'BLUE'
waiting = False
elif event.key == pygame.K_y:
user_input = 'YELLOW'
waiting = False
elif event.type == pygame.QUIT:
pygame.quit()
exit()
reaction_time = time.time() - start_time
correct = (user_input == correct_color)
return reaction_time, correct
# Run 5 trials
results = []
for i in range(5):
pygame.time.delay(1000)
rt, correct = stroop_trial()
results.append((rt, correct))
pygame.quit()
# Print results
for i, (rt, correct) in enumerate(results):
print(f"Trial {i+1}: {'Correct' if correct else 'Wrong'} – Reaction Time: {rt:.2f} seconds")