# this implements a very basic visual oddball task using PsychoPy
# see https://en.wikipedia.org/wiki/Oddball_paradigm for more details

from psychopy import visual, core
import random

screen = visual.Window([800, 600], color='black', units='pix')
fixation = visual.TextStim(screen, text='+', color='white', height=50)
standard = visual.TextStim(screen, text='STANDARD', color='green', height=50)
deviant  = visual.TextStim(screen, text='DEVIANT', color='red', height=50)

fixation.draw()
screen.flip()
core.wait(2)

# present 10 trials of the oddball task
# where 80% of the stimuli are standard and 20% are deviant
for trial in range(10):
    # Randomly choose a stimulus for each trial
    stimulus = random.choice([standard, standard, standard, standard, deviant])

    fixation.draw()
    screen.flip()
    core.wait(0.5)

    stimulus.draw()  # present randomly chosen stimulus
    screen.flip()
    core.wait(0.5)


screen.close()
core.quit()
