#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This experiment was created using PsychoPy3 Experiment Builder (v2024.2.4),
    on april 01, 2025, at 16:28
If you publish work using this script the most relevant publication is:

    Peirce J, Gray JR, Simpson S, MacAskill M, Höchenberger R, Sogo H, Kastman E, Lindeløv JK. (2019) 
        PsychoPy2: Experiments in behavior made easy Behav Res 51: 195. 
        https://doi.org/10.3758/s13428-018-01193-y

"""

# --- Import packages ---
from psychopy import locale_setup
from psychopy import prefs
from psychopy import plugins
plugins.activatePlugins()
prefs.hardware['audioLib'] = 'ptb'
prefs.hardware['audioLatencyMode'] = '3'
from psychopy import sound, gui, visual, core, data, event, logging, clock, colors, layout, hardware
from psychopy.tools import environmenttools
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
                                STOPPED, FINISHED, PRESSED, RELEASED, FOREVER, priority)

import numpy as np  # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
                   sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle, choice as randchoice
import os  # handy system and path functions
import sys  # to get file system encoding

import psychopy.iohub as io
from psychopy.hardware import keyboard

# --- Setup global variables (available in all functions) ---
# create a device manager to handle hardware (keyboards, mice, mirophones, speakers, etc.)
deviceManager = hardware.DeviceManager()
# ensure that relative paths start from the same directory as this script
_thisDir = os.path.dirname(os.path.abspath(__file__))
# store info about the experiment session
psychopyVersion = '2024.2.4'
expName = 'ExperimentPart1'  # from the Builder filename that created this script
# information about this experiment
expInfo = {
    'participant': f"{randint(0, 999999):06.0f}",
    'session': '001',
    'date|hid': data.getDateStr(),
    'expName|hid': expName,
    'psychopyVersion|hid': psychopyVersion,
}

# --- Define some variables which will change depending on pilot mode ---
'''
To run in pilot mode, either use the run/pilot toggle in Builder, Coder and Runner, 
or run the experiment with `--pilot` as an argument. To change what pilot 
#mode does, check out the 'Pilot mode' tab in preferences.
'''
# work out from system args whether we are running in pilot mode
PILOTING = core.setPilotModeFromArgs()
# start off with values from experiment settings
_fullScr = True
_winSize = [1536, 960]
# if in pilot mode, apply overrides according to preferences
if PILOTING:
    # force windowed mode
    if prefs.piloting['forceWindowed']:
        _fullScr = False
        # set window size
        _winSize = prefs.piloting['forcedWindowSize']

def showExpInfoDlg(expInfo):
    """
    Show participant info dialog.
    Parameters
    ==========
    expInfo : dict
        Information about this experiment.
    
    Returns
    ==========
    dict
        Information about this experiment.
    """
    # show participant info dialog
    dlg = gui.DlgFromDict(
        dictionary=expInfo, sortKeys=False, title=expName, alwaysOnTop=True
    )
    if dlg.OK == False:
        core.quit()  # user pressed cancel
    # return expInfo
    return expInfo


def setupData(expInfo, dataDir=None):
    """
    Make an ExperimentHandler to handle trials and saving.
    
    Parameters
    ==========
    expInfo : dict
        Information about this experiment, created by the `setupExpInfo` function.
    dataDir : Path, str or None
        Folder to save the data to, leave as None to create a folder in the current directory.    
    Returns
    ==========
    psychopy.data.ExperimentHandler
        Handler object for this experiment, contains the data to save and information about 
        where to save it to.
    """
    # remove dialog-specific syntax from expInfo
    for key, val in expInfo.copy().items():
        newKey, _ = data.utils.parsePipeSyntax(key)
        expInfo[newKey] = expInfo.pop(key)
    
    # data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
    if dataDir is None:
        dataDir = _thisDir
    filename = u'data/%s_%s_%s' % (expInfo['participant'], expName, expInfo['date'])
    # make sure filename is relative to dataDir
    if os.path.isabs(filename):
        dataDir = os.path.commonprefix([dataDir, filename])
        filename = os.path.relpath(filename, dataDir)
    
    # an ExperimentHandler isn't essential but helps with data saving
    thisExp = data.ExperimentHandler(
        name=expName, version='',
        extraInfo=expInfo, runtimeInfo=None,
        originPath='C:\\Users\\credo\\Documents\\Color\\Routines\\ExperimentPart1\\ExperimentPart1.py',
        savePickle=True, saveWideText=True,
        dataFileName=dataDir + os.sep + filename, sortColumns='time'
    )
    thisExp.setPriority('thisRow.t', priority.CRITICAL)
    thisExp.setPriority('expName', priority.LOW)
    # return experiment handler
    return thisExp


def setupLogging(filename):
    """
    Setup a log file and tell it what level to log at.
    
    Parameters
    ==========
    filename : str or pathlib.Path
        Filename to save log file and data files as, doesn't need an extension.
    
    Returns
    ==========
    psychopy.logging.LogFile
        Text stream to receive inputs from the logging system.
    """
    # set how much information should be printed to the console / app
    if PILOTING:
        logging.console.setLevel(
            prefs.piloting['pilotConsoleLoggingLevel']
        )
    else:
        logging.console.setLevel('warning')
    # save a log file for detail verbose info
    logFile = logging.LogFile(filename+'.log')
    if PILOTING:
        logFile.setLevel(
            prefs.piloting['pilotLoggingLevel']
        )
    else:
        logFile.setLevel(
            logging.getLevel('info')
        )
    
    return logFile


def setupWindow(expInfo=None, win=None):
    """
    Setup the Window
    
    Parameters
    ==========
    expInfo : dict
        Information about this experiment, created by the `setupExpInfo` function.
    win : psychopy.visual.Window
        Window to setup - leave as None to create a new window.
    
    Returns
    ==========
    psychopy.visual.Window
        Window in which to run this experiment.
    """
    if PILOTING:
        logging.debug('Fullscreen settings ignored as running in pilot mode.')
    
    if win is None:
        # if not given a window to setup, make one
        win = visual.Window(
            size=_winSize, fullscr=_fullScr, screen=0,
            winType='pyglet', allowGUI=True, allowStencil=True,
            monitor='testMonitor', color=[-0.7255, -0.7647, -0.7647], colorSpace='rgb',
            backgroundImage='', backgroundFit='none',
            blendMode='avg', useFBO=True,
            units='height',
            checkTiming=False  # we're going to do this ourselves in a moment
        )
    else:
        # if we have a window, just set the attributes which are safe to set
        win.color = [-0.7255, -0.7647, -0.7647]
        win.colorSpace = 'rgb'
        win.backgroundImage = ''
        win.backgroundFit = 'none'
        win.units = 'height'
    if expInfo is not None:
        # get/measure frame rate if not already in expInfo
        if win._monitorFrameRate is None:
            win._monitorFrameRate = win.getActualFrameRate(infoMsg='Attempting to measure frame rate of screen, please wait...')
        expInfo['frameRate'] = win._monitorFrameRate
    win.hideMessage()
    # show a visual indicator if we're in piloting mode
    if PILOTING and prefs.piloting['showPilotingIndicator']:
        win.showPilotingIndicator()
    
    return win


def setupDevices(expInfo, thisExp, win):
    """
    Setup whatever devices are available (mouse, keyboard, speaker, eyetracker, etc.) and add them to 
    the device manager (deviceManager)
    
    Parameters
    ==========
    expInfo : dict
        Information about this experiment, created by the `setupExpInfo` function.
    thisExp : psychopy.data.ExperimentHandler
        Handler object for this experiment, contains the data to save and information about 
        where to save it to.
    win : psychopy.visual.Window
        Window in which to run this experiment.
    Returns
    ==========
    bool
        True if completed successfully.
    """
    # --- Setup input devices ---
    ioConfig = {}
    
    # Setup iohub keyboard
    ioConfig['Keyboard'] = dict(use_keymap='psychopy')
    
    # Setup iohub experiment
    ioConfig['Experiment'] = dict(filename=thisExp.dataFileName)
    
    # Start ioHub server
    ioServer = io.launchHubServer(window=win, **ioConfig)
    
    # store ioServer object in the device manager
    deviceManager.ioServer = ioServer
    
    # create a default keyboard (e.g. to check for escape)
    if deviceManager.getDevice('defaultKeyboard') is None:
        deviceManager.addDevice(
            deviceClass='keyboard', deviceName='defaultKeyboard', backend='iohub'
        )
    # return True if completed successfully
    return True

def pauseExperiment(thisExp, win=None, timers=[], playbackComponents=[]):
    """
    Pause this experiment, preventing the flow from advancing to the next routine until resumed.
    
    Parameters
    ==========
    thisExp : psychopy.data.ExperimentHandler
        Handler object for this experiment, contains the data to save and information about 
        where to save it to.
    win : psychopy.visual.Window
        Window for this experiment.
    timers : list, tuple
        List of timers to reset once pausing is finished.
    playbackComponents : list, tuple
        List of any components with a `pause` method which need to be paused.
    """
    # if we are not paused, do nothing
    if thisExp.status != PAUSED:
        return
    
    # start a timer to figure out how long we're paused for
    pauseTimer = core.Clock()
    # pause any playback components
    for comp in playbackComponents:
        comp.pause()
    # make sure we have a keyboard
    defaultKeyboard = deviceManager.getDevice('defaultKeyboard')
    if defaultKeyboard is None:
        defaultKeyboard = deviceManager.addKeyboard(
            deviceClass='keyboard',
            deviceName='defaultKeyboard',
            backend='ioHub',
        )
    # run a while loop while we wait to unpause
    while thisExp.status == PAUSED:
        # check for quit (typically the Esc key)
        if defaultKeyboard.getKeys(keyList=['escape']):
            endExperiment(thisExp, win=win)
        # sleep 1ms so other threads can execute
        clock.time.sleep(0.001)
    # if stop was requested while paused, quit
    if thisExp.status == FINISHED:
        endExperiment(thisExp, win=win)
    # resume any playback components
    for comp in playbackComponents:
        comp.play()
    # reset any timers
    for timer in timers:
        timer.addTime(-pauseTimer.getTime())


def run(expInfo, thisExp, win, globalClock=None, thisSession=None):
    """
    Run the experiment flow.
    
    Parameters
    ==========
    expInfo : dict
        Information about this experiment, created by the `setupExpInfo` function.
    thisExp : psychopy.data.ExperimentHandler
        Handler object for this experiment, contains the data to save and information about 
        where to save it to.
    psychopy.visual.Window
        Window in which to run this experiment.
    globalClock : psychopy.core.clock.Clock or None
        Clock to get global time from - supply None to make a new one.
    thisSession : psychopy.session.Session or None
        Handle of the Session object this experiment is being run from, if any.
    """
    # mark experiment as started
    thisExp.status = STARTED
    # make sure window is set to foreground to prevent losing focus
    win.winHandle.activate()
    # make sure variables created by exec are available globally
    exec = environmenttools.setExecEnvironment(globals())
    # get device handles from dict of input devices
    ioServer = deviceManager.ioServer
    # get/create a default keyboard (e.g. to check for escape)
    defaultKeyboard = deviceManager.getDevice('defaultKeyboard')
    if defaultKeyboard is None:
        deviceManager.addDevice(
            deviceClass='keyboard', deviceName='defaultKeyboard', backend='ioHub'
        )
    eyetracker = deviceManager.getDevice('eyetracker')
    # make sure we're running in the directory for this experiment
    os.chdir(_thisDir)
    # get filename from ExperimentHandler for convenience
    filename = thisExp.dataFileName
    frameTolerance = 0.001  # how close to onset before 'same' frame
    endExpNow = False  # flag for 'escape' or other condition => quit the exp
    # get frame duration from frame rate in expInfo
    if 'frameRate' in expInfo and expInfo['frameRate'] is not None:
        frameDur = 1.0 / round(expInfo['frameRate'])
    else:
        frameDur = 1.0 / 60.0  # could not measure, so guess
    
    # Start Code - component code to be run after the window creation
    
    # --- Initialize components for Routine "BlackWhite" ---
    text = visual.TextStim(win=win, name='text',
        text='Get ready to memorize a pattern. It will be shown on the next screen.',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=0.0);
    Base = visual.ImageStim(
        win=win,
        name='Base', 
        image='C:/Users/credo/Documents/Color/Patterns/ControlBaseline/d_BasePattern.png', mask=None, anchor='center',
        ori=0.0, pos=(0, 0), draggable=False, size=(0.5, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-1.0)
    text_2 = visual.TextStim(win=win, name='text_2',
        text='Get ready to solve a simple math question. It will be shown on the next screen.',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=-2.0);
    text_3 = visual.TextStim(win=win, name='text_3',
        text='246 + 32 - 15',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=-3.0);
    textbox = visual.TextBox2(
         win, text=None, placeholder='Enter answer here', font='Arial',
         ori=0.0, pos=(0, -0.3), draggable=False,      letterHeight=0.05,
         size=(0.5, 0.5), borderWidth=2.0,
         color='white', colorSpace='rgb',
         opacity=None,
         bold=False, italic=False,
         lineSpacing=1.0, speechPoint=None,
         padding=0.0, alignment='center',
         anchor='center', overflow='visible',
         fillColor=None, borderColor=None,
         flipHoriz=False, flipVert=False, languageStyle='LTR',
         editable=True,
         name='textbox',
         depth=-4, autoLog=True,
    )
    text_4 = visual.TextStim(win=win, name='text_4',
        text='Still remember the pattern? Now, let’s see if you can recognize it among four others.',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=-5.0);
    a_Distractor = visual.ImageStim(
        win=win,
        name='a_Distractor', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/ControlBaseline/a_Distractor.png', mask=None, anchor='center',
        ori=0.0, pos=(-0.8, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-6.0)
    b_Distractor = visual.ImageStim(
        win=win,
        name='b_Distractor', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/ControlBaseline/b_Distractor.png', mask=None, anchor='center',
        ori=0.0, pos=(-0.4, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-7.0)
    c_Distractor = visual.ImageStim(
        win=win,
        name='c_Distractor', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/ControlBaseline/c_Distractor.png', mask=None, anchor='center',
        ori=0.0, pos=(0, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-8.0)
    d_Base = visual.ImageStim(
        win=win,
        name='d_Base', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/ControlBaseline/d_BasePattern.png', mask=None, anchor='center',
        ori=0.0, pos=(0.4, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-9.0)
    e_Distractor = visual.ImageStim(
        win=win,
        name='e_Distractor', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/ControlBaseline/e_Distractor.png', mask=None, anchor='center',
        ori=0.0, pos=(0.8, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-10.0)
    mouse = event.Mouse(win=win)
    x, y = [None, None]
    mouse.mouseClock = core.Clock()
    
    # --- Initialize components for Routine "RedWhite" ---
    text_5 = visual.TextStim(win=win, name='text_5',
        text='Get ready to memorize the next pattern. It will be shown on the next screen.',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=0.0);
    Base_2 = visual.ImageStim(
        win=win,
        name='Base_2', 
        image='C:/Users/credo/Documents/Color/Patterns/RedWhite/c_Base.png', mask=None, anchor='center',
        ori=0.0, pos=(0, 0), draggable=False, size=(0.5, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-1.0)
    text_6 = visual.TextStim(win=win, name='text_6',
        text='Get ready to solve a simple math question. It will be shown on the next screen.',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=-2.0);
    text_7 = visual.TextStim(win=win, name='text_7',
        text='574 + 23 - 38',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=-3.0);
    textbox_2 = visual.TextBox2(
         win, text=None, placeholder='Enter answer here', font='Arial',
         ori=0.0, pos=(0, -0.3), draggable=False,      letterHeight=0.05,
         size=(0.5, 0.5), borderWidth=2.0,
         color='white', colorSpace='rgb',
         opacity=None,
         bold=False, italic=False,
         lineSpacing=1.0, speechPoint=None,
         padding=0.0, alignment='center',
         anchor='center', overflow='visible',
         fillColor=None, borderColor=None,
         flipHoriz=False, flipVert=False, languageStyle='LTR',
         editable=True,
         name='textbox_2',
         depth=-4, autoLog=True,
    )
    text_8 = visual.TextStim(win=win, name='text_8',
        text='Still remember the pattern? Now, let’s see if you can recognize it among four others.',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=-5.0);
    a_Distractor_2 = visual.ImageStim(
        win=win,
        name='a_Distractor_2', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/RedWhite/a_Distractor.png', mask=None, anchor='center',
        ori=0.0, pos=(-0.8, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-6.0)
    b_Distractor_2 = visual.ImageStim(
        win=win,
        name='b_Distractor_2', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/RedWhite/b_Distractor.png', mask=None, anchor='center',
        ori=0.0, pos=(-0.4, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-7.0)
    c_Base = visual.ImageStim(
        win=win,
        name='c_Base', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/RedWhite/c_Base.png', mask=None, anchor='center',
        ori=0.0, pos=(0, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-8.0)
    d_Distractor_2 = visual.ImageStim(
        win=win,
        name='d_Distractor_2', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/RedWhite/d_Distractor.png', mask=None, anchor='center',
        ori=0.0, pos=(0.4, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-9.0)
    e_Distractor_2 = visual.ImageStim(
        win=win,
        name='e_Distractor_2', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/RedWhite/e_Distractor.png', mask=None, anchor='center',
        ori=0.0, pos=(0.8, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-10.0)
    mouse_2 = event.Mouse(win=win)
    x, y = [None, None]
    mouse_2.mouseClock = core.Clock()
    
    # --- Initialize components for Routine "BlueWhite" ---
    text_9 = visual.TextStim(win=win, name='text_9',
        text='Get ready to memorize the next pattern. It will be shown on the next screen.',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=0.0);
    Base_3 = visual.ImageStim(
        win=win,
        name='Base_3', 
        image='C:/Users/credo/Documents/Color/Patterns/BlueWhite/BWB.png', mask=None, anchor='center',
        ori=0.0, pos=(0, 0), draggable=False, size=(0.5, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-1.0)
    text_10 = visual.TextStim(win=win, name='text_10',
        text='Get ready to solve a simple math question. It will be shown on the next screen.',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=-2.0);
    text_11 = visual.TextStim(win=win, name='text_11',
        text='167 + 45 - 29',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=-3.0);
    textbox_3 = visual.TextBox2(
         win, text=None, placeholder='Enter answer here', font='Arial',
         ori=0.0, pos=(0, -0.3), draggable=False,      letterHeight=0.05,
         size=(0.5, 0.5), borderWidth=2.0,
         color='white', colorSpace='rgb',
         opacity=None,
         bold=False, italic=False,
         lineSpacing=1.0, speechPoint=None,
         padding=0.0, alignment='center',
         anchor='center', overflow='visible',
         fillColor=None, borderColor=None,
         flipHoriz=False, flipVert=False, languageStyle='LTR',
         editable=True,
         name='textbox_3',
         depth=-4, autoLog=True,
    )
    text_12 = visual.TextStim(win=win, name='text_12',
        text='Still remember the pattern? Now, let’s see if you can recognize it among four others.',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=-5.0);
    a_Distractor_3 = visual.ImageStim(
        win=win,
        name='a_Distractor_3', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/BlueWhite/BWD1.png', mask=None, anchor='center',
        ori=0.0, pos=(-0.8, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-6.0)
    b_Base = visual.ImageStim(
        win=win,
        name='b_Base', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/BlueWhite/BWB.png', mask=None, anchor='center',
        ori=0.0, pos=(-0.4, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-7.0)
    c_Distractor_3 = visual.ImageStim(
        win=win,
        name='c_Distractor_3', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/BlueWhite/BWD2.png', mask=None, anchor='center',
        ori=0.0, pos=(0, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-8.0)
    d_Distractor_3 = visual.ImageStim(
        win=win,
        name='d_Distractor_3', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/BlueWhite/BWD3.png', mask=None, anchor='center',
        ori=0.0, pos=(0.4, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-9.0)
    e_Distractor_3 = visual.ImageStim(
        win=win,
        name='e_Distractor_3', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/BlueWhite/BWD4.png', mask=None, anchor='center',
        ori=0.0, pos=(0.8, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-10.0)
    mouse_3 = event.Mouse(win=win)
    x, y = [None, None]
    mouse_3.mouseClock = core.Clock()
    
    # --- Initialize components for Routine "RedGreen" ---
    text_13 = visual.TextStim(win=win, name='text_13',
        text='Get ready to memorize the next pattern. It will be shown on the next screen.',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=0.0);
    Base_4 = visual.ImageStim(
        win=win,
        name='Base_4', 
        image='C:/Users/credo/Documents/Color/Patterns/RedGreen/RGB.png', mask=None, anchor='center',
        ori=0.0, pos=(0, 0), draggable=False, size=(0.5, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-1.0)
    text_14 = visual.TextStim(win=win, name='text_14',
        text='Get ready to solve a simple math question. It will be shown on the next screen.',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=-2.0);
    text_15 = visual.TextStim(win=win, name='text_15',
        text='264 - 48 + 33',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=-3.0);
    textbox_4 = visual.TextBox2(
         win, text=None, placeholder='Enter answer here', font='Arial',
         ori=0.0, pos=(0, -0.3), draggable=False,      letterHeight=0.05,
         size=(0.5, 0.5), borderWidth=2.0,
         color='white', colorSpace='rgb',
         opacity=None,
         bold=False, italic=False,
         lineSpacing=1.0, speechPoint=None,
         padding=0.0, alignment='center',
         anchor='center', overflow='visible',
         fillColor=None, borderColor=None,
         flipHoriz=False, flipVert=False, languageStyle='LTR',
         editable=True,
         name='textbox_4',
         depth=-4, autoLog=True,
    )
    text_16 = visual.TextStim(win=win, name='text_16',
        text='Still remember the pattern? Now, let’s see if you can recognize it among four others.',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=-5.0);
    a_Distractor_4 = visual.ImageStim(
        win=win,
        name='a_Distractor_4', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/RedGreen/RGD1.png', mask=None, anchor='center',
        ori=0.0, pos=(-0.8, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-6.0)
    b_Distractor_4 = visual.ImageStim(
        win=win,
        name='b_Distractor_4', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/RedGreen/RGD2.png', mask=None, anchor='center',
        ori=0.0, pos=(-0.4, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-7.0)
    c_Distractor_4 = visual.ImageStim(
        win=win,
        name='c_Distractor_4', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/RedGreen/RGD3.png', mask=None, anchor='center',
        ori=0.0, pos=(0, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-8.0)
    d_Distractor_4 = visual.ImageStim(
        win=win,
        name='d_Distractor_4', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/RedGreen/RGD4.png', mask=None, anchor='center',
        ori=0.0, pos=(0.4, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-9.0)
    e_Base = visual.ImageStim(
        win=win,
        name='e_Base', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/RedGreen/RGB.png', mask=None, anchor='center',
        ori=0.0, pos=(0.8, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-10.0)
    mouse_4 = event.Mouse(win=win)
    x, y = [None, None]
    mouse_4.mouseClock = core.Clock()
    
    # --- Initialize components for Routine "YellowBlack" ---
    text_17 = visual.TextStim(win=win, name='text_17',
        text='Get ready to memorize the next pattern. It will be shown on the next screen.',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=0.0);
    Base_5 = visual.ImageStim(
        win=win,
        name='Base_5', 
        image='C:/Users/credo/Documents/Color/Patterns/YellowBlack/YBB.png', mask=None, anchor='center',
        ori=0.0, pos=(0, 0), draggable=False, size=(0.5, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-1.0)
    text_18 = visual.TextStim(win=win, name='text_18',
        text='Get ready to solve a simple math question. It will be shown on the next screen.',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=-2.0);
    text_19 = visual.TextStim(win=win, name='text_19',
        text='352 - 57 + 44',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=-3.0);
    textbox_5 = visual.TextBox2(
         win, text=None, placeholder='Enter answer here', font='Arial',
         ori=0.0, pos=(0, -0.3), draggable=False,      letterHeight=0.05,
         size=(0.5, 0.5), borderWidth=2.0,
         color='white', colorSpace='rgb',
         opacity=None,
         bold=False, italic=False,
         lineSpacing=1.0, speechPoint=None,
         padding=0.0, alignment='center',
         anchor='center', overflow='visible',
         fillColor=None, borderColor=None,
         flipHoriz=False, flipVert=False, languageStyle='LTR',
         editable=True,
         name='textbox_5',
         depth=-4, autoLog=True,
    )
    text_20 = visual.TextStim(win=win, name='text_20',
        text='Still remember the pattern? Now, let’s see if you can recognize it among four others.',
        font='Arial',
        pos=(0, 0), draggable=False, height=0.05, wrapWidth=None, ori=0.0, 
        color='white', colorSpace='rgb', opacity=None, 
        languageStyle='LTR',
        depth=-5.0);
    a_Base = visual.ImageStim(
        win=win,
        name='a_Base', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/YellowBlack/YBB.png', mask=None, anchor='center',
        ori=0.0, pos=(-0.8, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-6.0)
    b_Distractor_5 = visual.ImageStim(
        win=win,
        name='b_Distractor_5', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/YellowBlack/YBD1.png', mask=None, anchor='center',
        ori=0.0, pos=(-0.4, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-7.0)
    c_Distractor_5 = visual.ImageStim(
        win=win,
        name='c_Distractor_5', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/YellowBlack/YBD2.png', mask=None, anchor='center',
        ori=0.0, pos=(0, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-8.0)
    d_Distractor_5 = visual.ImageStim(
        win=win,
        name='d_Distractor_5', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/YellowBlack/YBD3.png', mask=None, anchor='center',
        ori=0.0, pos=(0.4, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-9.0)
    e_Distractor_5 = visual.ImageStim(
        win=win,
        name='e_Distractor_5', units='norm', 
        image='C:/Users/credo/Documents/Color/Patterns/YellowBlack/YBD4.png', mask=None, anchor='center',
        ori=0.0, pos=(0.8, 0), draggable=False, size=(0.3, 0.5),
        color=[1,1,1], colorSpace='rgb', opacity=None,
        flipHoriz=False, flipVert=False,
        texRes=128.0, interpolate=True, depth=-10.0)
    mouse_5 = event.Mouse(win=win)
    x, y = [None, None]
    mouse_5.mouseClock = core.Clock()
    
    # create some handy timers
    
    # global clock to track the time since experiment started
    if globalClock is None:
        # create a clock if not given one
        globalClock = core.Clock()
    if isinstance(globalClock, str):
        # if given a string, make a clock accoridng to it
        if globalClock == 'float':
            # get timestamps as a simple value
            globalClock = core.Clock(format='float')
        elif globalClock == 'iso':
            # get timestamps in ISO format
            globalClock = core.Clock(format='%Y-%m-%d_%H:%M:%S.%f%z')
        else:
            # get timestamps in a custom format
            globalClock = core.Clock(format=globalClock)
    if ioServer is not None:
        ioServer.syncClock(globalClock)
    logging.setDefaultClock(globalClock)
    # routine timer to track time remaining of each (possibly non-slip) routine
    routineTimer = core.Clock()
    win.flip()  # flip window to reset last flip timer
    # store the exact time the global clock started
    expInfo['expStart'] = data.getDateStr(
        format='%Y-%m-%d %Hh%M.%S.%f %z', fractionalSecondDigits=6
    )
    
    # --- Prepare to start Routine "BlackWhite" ---
    # create an object to store info about Routine BlackWhite
    BlackWhite = data.Routine(
        name='BlackWhite',
        components=[text, Base, text_2, text_3, textbox, text_4, a_Distractor, b_Distractor, c_Distractor, d_Base, e_Distractor, mouse],
    )
    BlackWhite.status = NOT_STARTED
    continueRoutine = True
    # update component parameters for each repeat
    textbox.reset()
    # setup some python lists for storing info about the mouse
    mouse.x = []
    mouse.y = []
    mouse.leftButton = []
    mouse.midButton = []
    mouse.rightButton = []
    mouse.time = []
    mouse.clicked_name = []
    gotValidClick = False  # until a click is received
    # store start times for BlackWhite
    BlackWhite.tStartRefresh = win.getFutureFlipTime(clock=globalClock)
    BlackWhite.tStart = globalClock.getTime(format='float')
    BlackWhite.status = STARTED
    thisExp.addData('BlackWhite.started', BlackWhite.tStart)
    BlackWhite.maxDuration = None
    # keep track of which components have finished
    BlackWhiteComponents = BlackWhite.components
    for thisComponent in BlackWhite.components:
        thisComponent.tStart = None
        thisComponent.tStop = None
        thisComponent.tStartRefresh = None
        thisComponent.tStopRefresh = None
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
    # reset timers
    t = 0
    _timeToFirstFrame = win.getFutureFlipTime(clock="now")
    frameN = -1
    
    # --- Run Routine "BlackWhite" ---
    BlackWhite.forceEnded = routineForceEnded = not continueRoutine
    while continueRoutine and routineTimer.getTime() < 175.0:
        # get current time
        t = routineTimer.getTime()
        tThisFlip = win.getFutureFlipTime(clock=routineTimer)
        tThisFlipGlobal = win.getFutureFlipTime(clock=None)
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        
        # *text* updates
        
        # if text is starting this frame...
        if text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            text.frameNStart = frameN  # exact frame index
            text.tStart = t  # local t and not account for scr refresh
            text.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text.started')
            # update status
            text.status = STARTED
            text.setAutoDraw(True)
        
        # if text is active this frame...
        if text.status == STARTED:
            # update params
            pass
        
        # if text is stopping this frame...
        if text.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text.tStartRefresh + 5.0-frameTolerance:
                # keep track of stop time/frame for later
                text.tStop = t  # not accounting for scr refresh
                text.tStopRefresh = tThisFlipGlobal  # on global time
                text.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text.stopped')
                # update status
                text.status = FINISHED
                text.setAutoDraw(False)
        
        # *Base* updates
        
        # if Base is starting this frame...
        if Base.status == NOT_STARTED and tThisFlip >= 5.0-frameTolerance:
            # keep track of start time/frame for later
            Base.frameNStart = frameN  # exact frame index
            Base.tStart = t  # local t and not account for scr refresh
            Base.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(Base, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'Base.started')
            # update status
            Base.status = STARTED
            Base.setAutoDraw(True)
        
        # if Base is active this frame...
        if Base.status == STARTED:
            # update params
            pass
        
        # if Base is stopping this frame...
        if Base.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > Base.tStartRefresh + 10.0-frameTolerance:
                # keep track of stop time/frame for later
                Base.tStop = t  # not accounting for scr refresh
                Base.tStopRefresh = tThisFlipGlobal  # on global time
                Base.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'Base.stopped')
                # update status
                Base.status = FINISHED
                Base.setAutoDraw(False)
        
        # *text_2* updates
        
        # if text_2 is starting this frame...
        if text_2.status == NOT_STARTED and tThisFlip >= 15.0-frameTolerance:
            # keep track of start time/frame for later
            text_2.frameNStart = frameN  # exact frame index
            text_2.tStart = t  # local t and not account for scr refresh
            text_2.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text_2, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text_2.started')
            # update status
            text_2.status = STARTED
            text_2.setAutoDraw(True)
        
        # if text_2 is active this frame...
        if text_2.status == STARTED:
            # update params
            pass
        
        # if text_2 is stopping this frame...
        if text_2.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text_2.tStartRefresh + 5.0-frameTolerance:
                # keep track of stop time/frame for later
                text_2.tStop = t  # not accounting for scr refresh
                text_2.tStopRefresh = tThisFlipGlobal  # on global time
                text_2.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text_2.stopped')
                # update status
                text_2.status = FINISHED
                text_2.setAutoDraw(False)
        
        # *text_3* updates
        
        # if text_3 is starting this frame...
        if text_3.status == NOT_STARTED and tThisFlip >= 20.0-frameTolerance:
            # keep track of start time/frame for later
            text_3.frameNStart = frameN  # exact frame index
            text_3.tStart = t  # local t and not account for scr refresh
            text_3.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text_3, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text_3.started')
            # update status
            text_3.status = STARTED
            text_3.setAutoDraw(True)
        
        # if text_3 is active this frame...
        if text_3.status == STARTED:
            # update params
            pass
        
        # if text_3 is stopping this frame...
        if text_3.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text_3.tStartRefresh + 30.0-frameTolerance:
                # keep track of stop time/frame for later
                text_3.tStop = t  # not accounting for scr refresh
                text_3.tStopRefresh = tThisFlipGlobal  # on global time
                text_3.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text_3.stopped')
                # update status
                text_3.status = FINISHED
                text_3.setAutoDraw(False)
        
        # *textbox* updates
        
        # if textbox is starting this frame...
        if textbox.status == NOT_STARTED and tThisFlip >= 20.0-frameTolerance:
            # keep track of start time/frame for later
            textbox.frameNStart = frameN  # exact frame index
            textbox.tStart = t  # local t and not account for scr refresh
            textbox.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(textbox, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'textbox.started')
            # update status
            textbox.status = STARTED
            textbox.setAutoDraw(True)
        
        # if textbox is active this frame...
        if textbox.status == STARTED:
            # update params
            pass
        
        # if textbox is stopping this frame...
        if textbox.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > textbox.tStartRefresh + 30.0-frameTolerance:
                # keep track of stop time/frame for later
                textbox.tStop = t  # not accounting for scr refresh
                textbox.tStopRefresh = tThisFlipGlobal  # on global time
                textbox.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'textbox.stopped')
                # update status
                textbox.status = FINISHED
                textbox.setAutoDraw(False)
        
        # *text_4* updates
        
        # if text_4 is starting this frame...
        if text_4.status == NOT_STARTED and tThisFlip >= 50.0-frameTolerance:
            # keep track of start time/frame for later
            text_4.frameNStart = frameN  # exact frame index
            text_4.tStart = t  # local t and not account for scr refresh
            text_4.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text_4, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text_4.started')
            # update status
            text_4.status = STARTED
            text_4.setAutoDraw(True)
        
        # if text_4 is active this frame...
        if text_4.status == STARTED:
            # update params
            pass
        
        # if text_4 is stopping this frame...
        if text_4.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text_4.tStartRefresh + 5.0-frameTolerance:
                # keep track of stop time/frame for later
                text_4.tStop = t  # not accounting for scr refresh
                text_4.tStopRefresh = tThisFlipGlobal  # on global time
                text_4.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text_4.stopped')
                # update status
                text_4.status = FINISHED
                text_4.setAutoDraw(False)
        
        # *a_Distractor* updates
        
        # if a_Distractor is starting this frame...
        if a_Distractor.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            a_Distractor.frameNStart = frameN  # exact frame index
            a_Distractor.tStart = t  # local t and not account for scr refresh
            a_Distractor.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(a_Distractor, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'a_Distractor.started')
            # update status
            a_Distractor.status = STARTED
            a_Distractor.setAutoDraw(True)
        
        # if a_Distractor is active this frame...
        if a_Distractor.status == STARTED:
            # update params
            pass
        
        # if a_Distractor is stopping this frame...
        if a_Distractor.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > a_Distractor.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                a_Distractor.tStop = t  # not accounting for scr refresh
                a_Distractor.tStopRefresh = tThisFlipGlobal  # on global time
                a_Distractor.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'a_Distractor.stopped')
                # update status
                a_Distractor.status = FINISHED
                a_Distractor.setAutoDraw(False)
        
        # *b_Distractor* updates
        
        # if b_Distractor is starting this frame...
        if b_Distractor.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            b_Distractor.frameNStart = frameN  # exact frame index
            b_Distractor.tStart = t  # local t and not account for scr refresh
            b_Distractor.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(b_Distractor, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'b_Distractor.started')
            # update status
            b_Distractor.status = STARTED
            b_Distractor.setAutoDraw(True)
        
        # if b_Distractor is active this frame...
        if b_Distractor.status == STARTED:
            # update params
            pass
        
        # if b_Distractor is stopping this frame...
        if b_Distractor.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > b_Distractor.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                b_Distractor.tStop = t  # not accounting for scr refresh
                b_Distractor.tStopRefresh = tThisFlipGlobal  # on global time
                b_Distractor.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'b_Distractor.stopped')
                # update status
                b_Distractor.status = FINISHED
                b_Distractor.setAutoDraw(False)
        
        # *c_Distractor* updates
        
        # if c_Distractor is starting this frame...
        if c_Distractor.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            c_Distractor.frameNStart = frameN  # exact frame index
            c_Distractor.tStart = t  # local t and not account for scr refresh
            c_Distractor.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(c_Distractor, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'c_Distractor.started')
            # update status
            c_Distractor.status = STARTED
            c_Distractor.setAutoDraw(True)
        
        # if c_Distractor is active this frame...
        if c_Distractor.status == STARTED:
            # update params
            pass
        
        # if c_Distractor is stopping this frame...
        if c_Distractor.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > c_Distractor.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                c_Distractor.tStop = t  # not accounting for scr refresh
                c_Distractor.tStopRefresh = tThisFlipGlobal  # on global time
                c_Distractor.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'c_Distractor.stopped')
                # update status
                c_Distractor.status = FINISHED
                c_Distractor.setAutoDraw(False)
        
        # *d_Base* updates
        
        # if d_Base is starting this frame...
        if d_Base.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            d_Base.frameNStart = frameN  # exact frame index
            d_Base.tStart = t  # local t and not account for scr refresh
            d_Base.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(d_Base, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'd_Base.started')
            # update status
            d_Base.status = STARTED
            d_Base.setAutoDraw(True)
        
        # if d_Base is active this frame...
        if d_Base.status == STARTED:
            # update params
            pass
        
        # if d_Base is stopping this frame...
        if d_Base.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > d_Base.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                d_Base.tStop = t  # not accounting for scr refresh
                d_Base.tStopRefresh = tThisFlipGlobal  # on global time
                d_Base.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'd_Base.stopped')
                # update status
                d_Base.status = FINISHED
                d_Base.setAutoDraw(False)
        
        # *e_Distractor* updates
        
        # if e_Distractor is starting this frame...
        if e_Distractor.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            e_Distractor.frameNStart = frameN  # exact frame index
            e_Distractor.tStart = t  # local t and not account for scr refresh
            e_Distractor.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(e_Distractor, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'e_Distractor.started')
            # update status
            e_Distractor.status = STARTED
            e_Distractor.setAutoDraw(True)
        
        # if e_Distractor is active this frame...
        if e_Distractor.status == STARTED:
            # update params
            pass
        
        # if e_Distractor is stopping this frame...
        if e_Distractor.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > e_Distractor.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                e_Distractor.tStop = t  # not accounting for scr refresh
                e_Distractor.tStopRefresh = tThisFlipGlobal  # on global time
                e_Distractor.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'e_Distractor.stopped')
                # update status
                e_Distractor.status = FINISHED
                e_Distractor.setAutoDraw(False)
        # *mouse* updates
        
        # if mouse is starting this frame...
        if mouse.status == NOT_STARTED and t >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            mouse.frameNStart = frameN  # exact frame index
            mouse.tStart = t  # local t and not account for scr refresh
            mouse.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(mouse, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.addData('mouse.started', t)
            # update status
            mouse.status = STARTED
            mouse.mouseClock.reset()
            prevButtonState = mouse.getPressed()  # if button is down already this ISN'T a new click
        
        # if mouse is stopping this frame...
        if mouse.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > mouse.tStartRefresh + 175.0-frameTolerance:
                # keep track of stop time/frame for later
                mouse.tStop = t  # not accounting for scr refresh
                mouse.tStopRefresh = tThisFlipGlobal  # on global time
                mouse.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.addData('mouse.stopped', t)
                # update status
                mouse.status = FINISHED
        if mouse.status == STARTED:  # only update if started and not finished!
            buttons = mouse.getPressed()
            if buttons != prevButtonState:  # button state changed?
                prevButtonState = buttons
                if sum(buttons) > 0:  # state changed to a new click
                    # check if the mouse was inside our 'clickable' objects
                    gotValidClick = False
                    clickableList = environmenttools.getFromNames([a_Distractor, b_Distractor, c_Distractor, d_Base, e_Distractor], namespace=locals())
                    for obj in clickableList:
                        # is this object clicked on?
                        if obj.contains(mouse):
                            gotValidClick = True
                            mouse.clicked_name.append(obj.name)
                    if not gotValidClick:
                        mouse.clicked_name.append(None)
                    x, y = mouse.getPos()
                    mouse.x.append(x)
                    mouse.y.append(y)
                    buttons = mouse.getPressed()
                    mouse.leftButton.append(buttons[0])
                    mouse.midButton.append(buttons[1])
                    mouse.rightButton.append(buttons[2])
                    mouse.time.append(mouse.mouseClock.getTime())
                    if gotValidClick:
                        continueRoutine = False  # end routine on response
        
        # check for quit (typically the Esc key)
        if defaultKeyboard.getKeys(keyList=["escape"]):
            thisExp.status = FINISHED
        if thisExp.status == FINISHED or endExpNow:
            endExperiment(thisExp, win=win)
            return
        # pause experiment here if requested
        if thisExp.status == PAUSED:
            pauseExperiment(
                thisExp=thisExp, 
                win=win, 
                timers=[routineTimer], 
                playbackComponents=[]
            )
            # skip the frame we paused on
            continue
        
        # check if all components have finished
        if not continueRoutine:  # a component has requested a forced-end of Routine
            BlackWhite.forceEnded = routineForceEnded = True
            break
        continueRoutine = False  # will revert to True if at least one component still running
        for thisComponent in BlackWhite.components:
            if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
                continueRoutine = True
                break  # at least one component has not yet finished
        
        # refresh the screen
        if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
            win.flip()
    
    # --- Ending Routine "BlackWhite" ---
    for thisComponent in BlackWhite.components:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    # store stop times for BlackWhite
    BlackWhite.tStop = globalClock.getTime(format='float')
    BlackWhite.tStopRefresh = tThisFlipGlobal
    thisExp.addData('BlackWhite.stopped', BlackWhite.tStop)
    thisExp.addData('textbox.text',textbox.text)
    # store data for thisExp (ExperimentHandler)
    thisExp.addData('mouse.x', mouse.x)
    thisExp.addData('mouse.y', mouse.y)
    thisExp.addData('mouse.leftButton', mouse.leftButton)
    thisExp.addData('mouse.midButton', mouse.midButton)
    thisExp.addData('mouse.rightButton', mouse.rightButton)
    thisExp.addData('mouse.time', mouse.time)
    thisExp.addData('mouse.clicked_name', mouse.clicked_name)
    # using non-slip timing so subtract the expected duration of this Routine (unless ended on request)
    if BlackWhite.maxDurationReached:
        routineTimer.addTime(-BlackWhite.maxDuration)
    elif BlackWhite.forceEnded:
        routineTimer.reset()
    else:
        routineTimer.addTime(-175.000000)
    thisExp.nextEntry()
    
    # --- Prepare to start Routine "RedWhite" ---
    # create an object to store info about Routine RedWhite
    RedWhite = data.Routine(
        name='RedWhite',
        components=[text_5, Base_2, text_6, text_7, textbox_2, text_8, a_Distractor_2, b_Distractor_2, c_Base, d_Distractor_2, e_Distractor_2, mouse_2],
    )
    RedWhite.status = NOT_STARTED
    continueRoutine = True
    # update component parameters for each repeat
    textbox_2.reset()
    # setup some python lists for storing info about the mouse_2
    mouse_2.x = []
    mouse_2.y = []
    mouse_2.leftButton = []
    mouse_2.midButton = []
    mouse_2.rightButton = []
    mouse_2.time = []
    mouse_2.clicked_name = []
    gotValidClick = False  # until a click is received
    # store start times for RedWhite
    RedWhite.tStartRefresh = win.getFutureFlipTime(clock=globalClock)
    RedWhite.tStart = globalClock.getTime(format='float')
    RedWhite.status = STARTED
    thisExp.addData('RedWhite.started', RedWhite.tStart)
    RedWhite.maxDuration = None
    # keep track of which components have finished
    RedWhiteComponents = RedWhite.components
    for thisComponent in RedWhite.components:
        thisComponent.tStart = None
        thisComponent.tStop = None
        thisComponent.tStartRefresh = None
        thisComponent.tStopRefresh = None
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
    # reset timers
    t = 0
    _timeToFirstFrame = win.getFutureFlipTime(clock="now")
    frameN = -1
    
    # --- Run Routine "RedWhite" ---
    RedWhite.forceEnded = routineForceEnded = not continueRoutine
    while continueRoutine and routineTimer.getTime() < 175.0:
        # get current time
        t = routineTimer.getTime()
        tThisFlip = win.getFutureFlipTime(clock=routineTimer)
        tThisFlipGlobal = win.getFutureFlipTime(clock=None)
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        
        # *text_5* updates
        
        # if text_5 is starting this frame...
        if text_5.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            text_5.frameNStart = frameN  # exact frame index
            text_5.tStart = t  # local t and not account for scr refresh
            text_5.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text_5, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text_5.started')
            # update status
            text_5.status = STARTED
            text_5.setAutoDraw(True)
        
        # if text_5 is active this frame...
        if text_5.status == STARTED:
            # update params
            pass
        
        # if text_5 is stopping this frame...
        if text_5.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text_5.tStartRefresh + 5.0-frameTolerance:
                # keep track of stop time/frame for later
                text_5.tStop = t  # not accounting for scr refresh
                text_5.tStopRefresh = tThisFlipGlobal  # on global time
                text_5.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text_5.stopped')
                # update status
                text_5.status = FINISHED
                text_5.setAutoDraw(False)
        
        # *Base_2* updates
        
        # if Base_2 is starting this frame...
        if Base_2.status == NOT_STARTED and tThisFlip >= 5.0-frameTolerance:
            # keep track of start time/frame for later
            Base_2.frameNStart = frameN  # exact frame index
            Base_2.tStart = t  # local t and not account for scr refresh
            Base_2.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(Base_2, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'Base_2.started')
            # update status
            Base_2.status = STARTED
            Base_2.setAutoDraw(True)
        
        # if Base_2 is active this frame...
        if Base_2.status == STARTED:
            # update params
            pass
        
        # if Base_2 is stopping this frame...
        if Base_2.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > Base_2.tStartRefresh + 10.0-frameTolerance:
                # keep track of stop time/frame for later
                Base_2.tStop = t  # not accounting for scr refresh
                Base_2.tStopRefresh = tThisFlipGlobal  # on global time
                Base_2.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'Base_2.stopped')
                # update status
                Base_2.status = FINISHED
                Base_2.setAutoDraw(False)
        
        # *text_6* updates
        
        # if text_6 is starting this frame...
        if text_6.status == NOT_STARTED and tThisFlip >= 15.0-frameTolerance:
            # keep track of start time/frame for later
            text_6.frameNStart = frameN  # exact frame index
            text_6.tStart = t  # local t and not account for scr refresh
            text_6.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text_6, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text_6.started')
            # update status
            text_6.status = STARTED
            text_6.setAutoDraw(True)
        
        # if text_6 is active this frame...
        if text_6.status == STARTED:
            # update params
            pass
        
        # if text_6 is stopping this frame...
        if text_6.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text_6.tStartRefresh + 5.0-frameTolerance:
                # keep track of stop time/frame for later
                text_6.tStop = t  # not accounting for scr refresh
                text_6.tStopRefresh = tThisFlipGlobal  # on global time
                text_6.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text_6.stopped')
                # update status
                text_6.status = FINISHED
                text_6.setAutoDraw(False)
        
        # *text_7* updates
        
        # if text_7 is starting this frame...
        if text_7.status == NOT_STARTED and tThisFlip >= 20.0-frameTolerance:
            # keep track of start time/frame for later
            text_7.frameNStart = frameN  # exact frame index
            text_7.tStart = t  # local t and not account for scr refresh
            text_7.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text_7, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text_7.started')
            # update status
            text_7.status = STARTED
            text_7.setAutoDraw(True)
        
        # if text_7 is active this frame...
        if text_7.status == STARTED:
            # update params
            pass
        
        # if text_7 is stopping this frame...
        if text_7.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text_7.tStartRefresh + 30.0-frameTolerance:
                # keep track of stop time/frame for later
                text_7.tStop = t  # not accounting for scr refresh
                text_7.tStopRefresh = tThisFlipGlobal  # on global time
                text_7.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text_7.stopped')
                # update status
                text_7.status = FINISHED
                text_7.setAutoDraw(False)
        
        # *textbox_2* updates
        
        # if textbox_2 is starting this frame...
        if textbox_2.status == NOT_STARTED and tThisFlip >= 20.0-frameTolerance:
            # keep track of start time/frame for later
            textbox_2.frameNStart = frameN  # exact frame index
            textbox_2.tStart = t  # local t and not account for scr refresh
            textbox_2.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(textbox_2, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'textbox_2.started')
            # update status
            textbox_2.status = STARTED
            textbox_2.setAutoDraw(True)
        
        # if textbox_2 is active this frame...
        if textbox_2.status == STARTED:
            # update params
            pass
        
        # if textbox_2 is stopping this frame...
        if textbox_2.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > textbox_2.tStartRefresh + 30.0-frameTolerance:
                # keep track of stop time/frame for later
                textbox_2.tStop = t  # not accounting for scr refresh
                textbox_2.tStopRefresh = tThisFlipGlobal  # on global time
                textbox_2.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'textbox_2.stopped')
                # update status
                textbox_2.status = FINISHED
                textbox_2.setAutoDraw(False)
        
        # *text_8* updates
        
        # if text_8 is starting this frame...
        if text_8.status == NOT_STARTED and tThisFlip >= 50.0-frameTolerance:
            # keep track of start time/frame for later
            text_8.frameNStart = frameN  # exact frame index
            text_8.tStart = t  # local t and not account for scr refresh
            text_8.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text_8, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text_8.started')
            # update status
            text_8.status = STARTED
            text_8.setAutoDraw(True)
        
        # if text_8 is active this frame...
        if text_8.status == STARTED:
            # update params
            pass
        
        # if text_8 is stopping this frame...
        if text_8.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text_8.tStartRefresh + 5.0-frameTolerance:
                # keep track of stop time/frame for later
                text_8.tStop = t  # not accounting for scr refresh
                text_8.tStopRefresh = tThisFlipGlobal  # on global time
                text_8.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text_8.stopped')
                # update status
                text_8.status = FINISHED
                text_8.setAutoDraw(False)
        
        # *a_Distractor_2* updates
        
        # if a_Distractor_2 is starting this frame...
        if a_Distractor_2.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            a_Distractor_2.frameNStart = frameN  # exact frame index
            a_Distractor_2.tStart = t  # local t and not account for scr refresh
            a_Distractor_2.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(a_Distractor_2, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'a_Distractor_2.started')
            # update status
            a_Distractor_2.status = STARTED
            a_Distractor_2.setAutoDraw(True)
        
        # if a_Distractor_2 is active this frame...
        if a_Distractor_2.status == STARTED:
            # update params
            pass
        
        # if a_Distractor_2 is stopping this frame...
        if a_Distractor_2.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > a_Distractor_2.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                a_Distractor_2.tStop = t  # not accounting for scr refresh
                a_Distractor_2.tStopRefresh = tThisFlipGlobal  # on global time
                a_Distractor_2.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'a_Distractor_2.stopped')
                # update status
                a_Distractor_2.status = FINISHED
                a_Distractor_2.setAutoDraw(False)
        
        # *b_Distractor_2* updates
        
        # if b_Distractor_2 is starting this frame...
        if b_Distractor_2.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            b_Distractor_2.frameNStart = frameN  # exact frame index
            b_Distractor_2.tStart = t  # local t and not account for scr refresh
            b_Distractor_2.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(b_Distractor_2, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'b_Distractor_2.started')
            # update status
            b_Distractor_2.status = STARTED
            b_Distractor_2.setAutoDraw(True)
        
        # if b_Distractor_2 is active this frame...
        if b_Distractor_2.status == STARTED:
            # update params
            pass
        
        # if b_Distractor_2 is stopping this frame...
        if b_Distractor_2.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > b_Distractor_2.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                b_Distractor_2.tStop = t  # not accounting for scr refresh
                b_Distractor_2.tStopRefresh = tThisFlipGlobal  # on global time
                b_Distractor_2.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'b_Distractor_2.stopped')
                # update status
                b_Distractor_2.status = FINISHED
                b_Distractor_2.setAutoDraw(False)
        
        # *c_Base* updates
        
        # if c_Base is starting this frame...
        if c_Base.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            c_Base.frameNStart = frameN  # exact frame index
            c_Base.tStart = t  # local t and not account for scr refresh
            c_Base.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(c_Base, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'c_Base.started')
            # update status
            c_Base.status = STARTED
            c_Base.setAutoDraw(True)
        
        # if c_Base is active this frame...
        if c_Base.status == STARTED:
            # update params
            pass
        
        # if c_Base is stopping this frame...
        if c_Base.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > c_Base.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                c_Base.tStop = t  # not accounting for scr refresh
                c_Base.tStopRefresh = tThisFlipGlobal  # on global time
                c_Base.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'c_Base.stopped')
                # update status
                c_Base.status = FINISHED
                c_Base.setAutoDraw(False)
        
        # *d_Distractor_2* updates
        
        # if d_Distractor_2 is starting this frame...
        if d_Distractor_2.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            d_Distractor_2.frameNStart = frameN  # exact frame index
            d_Distractor_2.tStart = t  # local t and not account for scr refresh
            d_Distractor_2.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(d_Distractor_2, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'd_Distractor_2.started')
            # update status
            d_Distractor_2.status = STARTED
            d_Distractor_2.setAutoDraw(True)
        
        # if d_Distractor_2 is active this frame...
        if d_Distractor_2.status == STARTED:
            # update params
            pass
        
        # if d_Distractor_2 is stopping this frame...
        if d_Distractor_2.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > d_Distractor_2.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                d_Distractor_2.tStop = t  # not accounting for scr refresh
                d_Distractor_2.tStopRefresh = tThisFlipGlobal  # on global time
                d_Distractor_2.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'd_Distractor_2.stopped')
                # update status
                d_Distractor_2.status = FINISHED
                d_Distractor_2.setAutoDraw(False)
        
        # *e_Distractor_2* updates
        
        # if e_Distractor_2 is starting this frame...
        if e_Distractor_2.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            e_Distractor_2.frameNStart = frameN  # exact frame index
            e_Distractor_2.tStart = t  # local t and not account for scr refresh
            e_Distractor_2.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(e_Distractor_2, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'e_Distractor_2.started')
            # update status
            e_Distractor_2.status = STARTED
            e_Distractor_2.setAutoDraw(True)
        
        # if e_Distractor_2 is active this frame...
        if e_Distractor_2.status == STARTED:
            # update params
            pass
        
        # if e_Distractor_2 is stopping this frame...
        if e_Distractor_2.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > e_Distractor_2.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                e_Distractor_2.tStop = t  # not accounting for scr refresh
                e_Distractor_2.tStopRefresh = tThisFlipGlobal  # on global time
                e_Distractor_2.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'e_Distractor_2.stopped')
                # update status
                e_Distractor_2.status = FINISHED
                e_Distractor_2.setAutoDraw(False)
        # *mouse_2* updates
        
        # if mouse_2 is starting this frame...
        if mouse_2.status == NOT_STARTED and t >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            mouse_2.frameNStart = frameN  # exact frame index
            mouse_2.tStart = t  # local t and not account for scr refresh
            mouse_2.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(mouse_2, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.addData('mouse_2.started', t)
            # update status
            mouse_2.status = STARTED
            mouse_2.mouseClock.reset()
            prevButtonState = mouse_2.getPressed()  # if button is down already this ISN'T a new click
        
        # if mouse_2 is stopping this frame...
        if mouse_2.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > mouse_2.tStartRefresh + 175.0-frameTolerance:
                # keep track of stop time/frame for later
                mouse_2.tStop = t  # not accounting for scr refresh
                mouse_2.tStopRefresh = tThisFlipGlobal  # on global time
                mouse_2.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.addData('mouse_2.stopped', t)
                # update status
                mouse_2.status = FINISHED
        if mouse_2.status == STARTED:  # only update if started and not finished!
            buttons = mouse_2.getPressed()
            if buttons != prevButtonState:  # button state changed?
                prevButtonState = buttons
                if sum(buttons) > 0:  # state changed to a new click
                    # check if the mouse was inside our 'clickable' objects
                    gotValidClick = False
                    clickableList = environmenttools.getFromNames([a_Distractor_2, b_Distractor_2, c_Base, d_Distractor_2, e_Distractor_2], namespace=locals())
                    for obj in clickableList:
                        # is this object clicked on?
                        if obj.contains(mouse_2):
                            gotValidClick = True
                            mouse_2.clicked_name.append(obj.name)
                    if not gotValidClick:
                        mouse_2.clicked_name.append(None)
                    x, y = mouse_2.getPos()
                    mouse_2.x.append(x)
                    mouse_2.y.append(y)
                    buttons = mouse_2.getPressed()
                    mouse_2.leftButton.append(buttons[0])
                    mouse_2.midButton.append(buttons[1])
                    mouse_2.rightButton.append(buttons[2])
                    mouse_2.time.append(mouse_2.mouseClock.getTime())
                    if gotValidClick:
                        continueRoutine = False  # end routine on response
        
        # check for quit (typically the Esc key)
        if defaultKeyboard.getKeys(keyList=["escape"]):
            thisExp.status = FINISHED
        if thisExp.status == FINISHED or endExpNow:
            endExperiment(thisExp, win=win)
            return
        # pause experiment here if requested
        if thisExp.status == PAUSED:
            pauseExperiment(
                thisExp=thisExp, 
                win=win, 
                timers=[routineTimer], 
                playbackComponents=[]
            )
            # skip the frame we paused on
            continue
        
        # check if all components have finished
        if not continueRoutine:  # a component has requested a forced-end of Routine
            RedWhite.forceEnded = routineForceEnded = True
            break
        continueRoutine = False  # will revert to True if at least one component still running
        for thisComponent in RedWhite.components:
            if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
                continueRoutine = True
                break  # at least one component has not yet finished
        
        # refresh the screen
        if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
            win.flip()
    
    # --- Ending Routine "RedWhite" ---
    for thisComponent in RedWhite.components:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    # store stop times for RedWhite
    RedWhite.tStop = globalClock.getTime(format='float')
    RedWhite.tStopRefresh = tThisFlipGlobal
    thisExp.addData('RedWhite.stopped', RedWhite.tStop)
    thisExp.addData('textbox_2.text',textbox_2.text)
    # store data for thisExp (ExperimentHandler)
    thisExp.addData('mouse_2.x', mouse_2.x)
    thisExp.addData('mouse_2.y', mouse_2.y)
    thisExp.addData('mouse_2.leftButton', mouse_2.leftButton)
    thisExp.addData('mouse_2.midButton', mouse_2.midButton)
    thisExp.addData('mouse_2.rightButton', mouse_2.rightButton)
    thisExp.addData('mouse_2.time', mouse_2.time)
    thisExp.addData('mouse_2.clicked_name', mouse_2.clicked_name)
    # using non-slip timing so subtract the expected duration of this Routine (unless ended on request)
    if RedWhite.maxDurationReached:
        routineTimer.addTime(-RedWhite.maxDuration)
    elif RedWhite.forceEnded:
        routineTimer.reset()
    else:
        routineTimer.addTime(-175.000000)
    thisExp.nextEntry()
    
    # --- Prepare to start Routine "BlueWhite" ---
    # create an object to store info about Routine BlueWhite
    BlueWhite = data.Routine(
        name='BlueWhite',
        components=[text_9, Base_3, text_10, text_11, textbox_3, text_12, a_Distractor_3, b_Base, c_Distractor_3, d_Distractor_3, e_Distractor_3, mouse_3],
    )
    BlueWhite.status = NOT_STARTED
    continueRoutine = True
    # update component parameters for each repeat
    textbox_3.reset()
    # setup some python lists for storing info about the mouse_3
    mouse_3.x = []
    mouse_3.y = []
    mouse_3.leftButton = []
    mouse_3.midButton = []
    mouse_3.rightButton = []
    mouse_3.time = []
    mouse_3.clicked_name = []
    gotValidClick = False  # until a click is received
    # store start times for BlueWhite
    BlueWhite.tStartRefresh = win.getFutureFlipTime(clock=globalClock)
    BlueWhite.tStart = globalClock.getTime(format='float')
    BlueWhite.status = STARTED
    thisExp.addData('BlueWhite.started', BlueWhite.tStart)
    BlueWhite.maxDuration = None
    # keep track of which components have finished
    BlueWhiteComponents = BlueWhite.components
    for thisComponent in BlueWhite.components:
        thisComponent.tStart = None
        thisComponent.tStop = None
        thisComponent.tStartRefresh = None
        thisComponent.tStopRefresh = None
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
    # reset timers
    t = 0
    _timeToFirstFrame = win.getFutureFlipTime(clock="now")
    frameN = -1
    
    # --- Run Routine "BlueWhite" ---
    BlueWhite.forceEnded = routineForceEnded = not continueRoutine
    while continueRoutine and routineTimer.getTime() < 175.0:
        # get current time
        t = routineTimer.getTime()
        tThisFlip = win.getFutureFlipTime(clock=routineTimer)
        tThisFlipGlobal = win.getFutureFlipTime(clock=None)
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        
        # *text_9* updates
        
        # if text_9 is starting this frame...
        if text_9.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            text_9.frameNStart = frameN  # exact frame index
            text_9.tStart = t  # local t and not account for scr refresh
            text_9.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text_9, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text_9.started')
            # update status
            text_9.status = STARTED
            text_9.setAutoDraw(True)
        
        # if text_9 is active this frame...
        if text_9.status == STARTED:
            # update params
            pass
        
        # if text_9 is stopping this frame...
        if text_9.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text_9.tStartRefresh + 5.0-frameTolerance:
                # keep track of stop time/frame for later
                text_9.tStop = t  # not accounting for scr refresh
                text_9.tStopRefresh = tThisFlipGlobal  # on global time
                text_9.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text_9.stopped')
                # update status
                text_9.status = FINISHED
                text_9.setAutoDraw(False)
        
        # *Base_3* updates
        
        # if Base_3 is starting this frame...
        if Base_3.status == NOT_STARTED and tThisFlip >= 5.0-frameTolerance:
            # keep track of start time/frame for later
            Base_3.frameNStart = frameN  # exact frame index
            Base_3.tStart = t  # local t and not account for scr refresh
            Base_3.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(Base_3, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'Base_3.started')
            # update status
            Base_3.status = STARTED
            Base_3.setAutoDraw(True)
        
        # if Base_3 is active this frame...
        if Base_3.status == STARTED:
            # update params
            pass
        
        # if Base_3 is stopping this frame...
        if Base_3.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > Base_3.tStartRefresh + 10.0-frameTolerance:
                # keep track of stop time/frame for later
                Base_3.tStop = t  # not accounting for scr refresh
                Base_3.tStopRefresh = tThisFlipGlobal  # on global time
                Base_3.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'Base_3.stopped')
                # update status
                Base_3.status = FINISHED
                Base_3.setAutoDraw(False)
        
        # *text_10* updates
        
        # if text_10 is starting this frame...
        if text_10.status == NOT_STARTED and tThisFlip >= 15.0-frameTolerance:
            # keep track of start time/frame for later
            text_10.frameNStart = frameN  # exact frame index
            text_10.tStart = t  # local t and not account for scr refresh
            text_10.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text_10, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text_10.started')
            # update status
            text_10.status = STARTED
            text_10.setAutoDraw(True)
        
        # if text_10 is active this frame...
        if text_10.status == STARTED:
            # update params
            pass
        
        # if text_10 is stopping this frame...
        if text_10.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text_10.tStartRefresh + 5.0-frameTolerance:
                # keep track of stop time/frame for later
                text_10.tStop = t  # not accounting for scr refresh
                text_10.tStopRefresh = tThisFlipGlobal  # on global time
                text_10.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text_10.stopped')
                # update status
                text_10.status = FINISHED
                text_10.setAutoDraw(False)
        
        # *text_11* updates
        
        # if text_11 is starting this frame...
        if text_11.status == NOT_STARTED and tThisFlip >= 20.0-frameTolerance:
            # keep track of start time/frame for later
            text_11.frameNStart = frameN  # exact frame index
            text_11.tStart = t  # local t and not account for scr refresh
            text_11.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text_11, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text_11.started')
            # update status
            text_11.status = STARTED
            text_11.setAutoDraw(True)
        
        # if text_11 is active this frame...
        if text_11.status == STARTED:
            # update params
            pass
        
        # if text_11 is stopping this frame...
        if text_11.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text_11.tStartRefresh + 30.0-frameTolerance:
                # keep track of stop time/frame for later
                text_11.tStop = t  # not accounting for scr refresh
                text_11.tStopRefresh = tThisFlipGlobal  # on global time
                text_11.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text_11.stopped')
                # update status
                text_11.status = FINISHED
                text_11.setAutoDraw(False)
        
        # *textbox_3* updates
        
        # if textbox_3 is starting this frame...
        if textbox_3.status == NOT_STARTED and tThisFlip >= 20.0-frameTolerance:
            # keep track of start time/frame for later
            textbox_3.frameNStart = frameN  # exact frame index
            textbox_3.tStart = t  # local t and not account for scr refresh
            textbox_3.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(textbox_3, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'textbox_3.started')
            # update status
            textbox_3.status = STARTED
            textbox_3.setAutoDraw(True)
        
        # if textbox_3 is active this frame...
        if textbox_3.status == STARTED:
            # update params
            pass
        
        # if textbox_3 is stopping this frame...
        if textbox_3.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > textbox_3.tStartRefresh + 30.0-frameTolerance:
                # keep track of stop time/frame for later
                textbox_3.tStop = t  # not accounting for scr refresh
                textbox_3.tStopRefresh = tThisFlipGlobal  # on global time
                textbox_3.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'textbox_3.stopped')
                # update status
                textbox_3.status = FINISHED
                textbox_3.setAutoDraw(False)
        
        # *text_12* updates
        
        # if text_12 is starting this frame...
        if text_12.status == NOT_STARTED and tThisFlip >= 50.0-frameTolerance:
            # keep track of start time/frame for later
            text_12.frameNStart = frameN  # exact frame index
            text_12.tStart = t  # local t and not account for scr refresh
            text_12.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text_12, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text_12.started')
            # update status
            text_12.status = STARTED
            text_12.setAutoDraw(True)
        
        # if text_12 is active this frame...
        if text_12.status == STARTED:
            # update params
            pass
        
        # if text_12 is stopping this frame...
        if text_12.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text_12.tStartRefresh + 5.0-frameTolerance:
                # keep track of stop time/frame for later
                text_12.tStop = t  # not accounting for scr refresh
                text_12.tStopRefresh = tThisFlipGlobal  # on global time
                text_12.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text_12.stopped')
                # update status
                text_12.status = FINISHED
                text_12.setAutoDraw(False)
        
        # *a_Distractor_3* updates
        
        # if a_Distractor_3 is starting this frame...
        if a_Distractor_3.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            a_Distractor_3.frameNStart = frameN  # exact frame index
            a_Distractor_3.tStart = t  # local t and not account for scr refresh
            a_Distractor_3.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(a_Distractor_3, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'a_Distractor_3.started')
            # update status
            a_Distractor_3.status = STARTED
            a_Distractor_3.setAutoDraw(True)
        
        # if a_Distractor_3 is active this frame...
        if a_Distractor_3.status == STARTED:
            # update params
            pass
        
        # if a_Distractor_3 is stopping this frame...
        if a_Distractor_3.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > a_Distractor_3.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                a_Distractor_3.tStop = t  # not accounting for scr refresh
                a_Distractor_3.tStopRefresh = tThisFlipGlobal  # on global time
                a_Distractor_3.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'a_Distractor_3.stopped')
                # update status
                a_Distractor_3.status = FINISHED
                a_Distractor_3.setAutoDraw(False)
        
        # *b_Base* updates
        
        # if b_Base is starting this frame...
        if b_Base.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            b_Base.frameNStart = frameN  # exact frame index
            b_Base.tStart = t  # local t and not account for scr refresh
            b_Base.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(b_Base, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'b_Base.started')
            # update status
            b_Base.status = STARTED
            b_Base.setAutoDraw(True)
        
        # if b_Base is active this frame...
        if b_Base.status == STARTED:
            # update params
            pass
        
        # if b_Base is stopping this frame...
        if b_Base.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > b_Base.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                b_Base.tStop = t  # not accounting for scr refresh
                b_Base.tStopRefresh = tThisFlipGlobal  # on global time
                b_Base.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'b_Base.stopped')
                # update status
                b_Base.status = FINISHED
                b_Base.setAutoDraw(False)
        
        # *c_Distractor_3* updates
        
        # if c_Distractor_3 is starting this frame...
        if c_Distractor_3.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            c_Distractor_3.frameNStart = frameN  # exact frame index
            c_Distractor_3.tStart = t  # local t and not account for scr refresh
            c_Distractor_3.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(c_Distractor_3, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'c_Distractor_3.started')
            # update status
            c_Distractor_3.status = STARTED
            c_Distractor_3.setAutoDraw(True)
        
        # if c_Distractor_3 is active this frame...
        if c_Distractor_3.status == STARTED:
            # update params
            pass
        
        # if c_Distractor_3 is stopping this frame...
        if c_Distractor_3.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > c_Distractor_3.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                c_Distractor_3.tStop = t  # not accounting for scr refresh
                c_Distractor_3.tStopRefresh = tThisFlipGlobal  # on global time
                c_Distractor_3.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'c_Distractor_3.stopped')
                # update status
                c_Distractor_3.status = FINISHED
                c_Distractor_3.setAutoDraw(False)
        
        # *d_Distractor_3* updates
        
        # if d_Distractor_3 is starting this frame...
        if d_Distractor_3.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            d_Distractor_3.frameNStart = frameN  # exact frame index
            d_Distractor_3.tStart = t  # local t and not account for scr refresh
            d_Distractor_3.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(d_Distractor_3, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'd_Distractor_3.started')
            # update status
            d_Distractor_3.status = STARTED
            d_Distractor_3.setAutoDraw(True)
        
        # if d_Distractor_3 is active this frame...
        if d_Distractor_3.status == STARTED:
            # update params
            pass
        
        # if d_Distractor_3 is stopping this frame...
        if d_Distractor_3.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > d_Distractor_3.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                d_Distractor_3.tStop = t  # not accounting for scr refresh
                d_Distractor_3.tStopRefresh = tThisFlipGlobal  # on global time
                d_Distractor_3.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'd_Distractor_3.stopped')
                # update status
                d_Distractor_3.status = FINISHED
                d_Distractor_3.setAutoDraw(False)
        
        # *e_Distractor_3* updates
        
        # if e_Distractor_3 is starting this frame...
        if e_Distractor_3.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            e_Distractor_3.frameNStart = frameN  # exact frame index
            e_Distractor_3.tStart = t  # local t and not account for scr refresh
            e_Distractor_3.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(e_Distractor_3, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'e_Distractor_3.started')
            # update status
            e_Distractor_3.status = STARTED
            e_Distractor_3.setAutoDraw(True)
        
        # if e_Distractor_3 is active this frame...
        if e_Distractor_3.status == STARTED:
            # update params
            pass
        
        # if e_Distractor_3 is stopping this frame...
        if e_Distractor_3.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > e_Distractor_3.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                e_Distractor_3.tStop = t  # not accounting for scr refresh
                e_Distractor_3.tStopRefresh = tThisFlipGlobal  # on global time
                e_Distractor_3.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'e_Distractor_3.stopped')
                # update status
                e_Distractor_3.status = FINISHED
                e_Distractor_3.setAutoDraw(False)
        # *mouse_3* updates
        
        # if mouse_3 is starting this frame...
        if mouse_3.status == NOT_STARTED and t >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            mouse_3.frameNStart = frameN  # exact frame index
            mouse_3.tStart = t  # local t and not account for scr refresh
            mouse_3.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(mouse_3, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.addData('mouse_3.started', t)
            # update status
            mouse_3.status = STARTED
            mouse_3.mouseClock.reset()
            prevButtonState = mouse_3.getPressed()  # if button is down already this ISN'T a new click
        
        # if mouse_3 is stopping this frame...
        if mouse_3.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > mouse_3.tStartRefresh + 175.0-frameTolerance:
                # keep track of stop time/frame for later
                mouse_3.tStop = t  # not accounting for scr refresh
                mouse_3.tStopRefresh = tThisFlipGlobal  # on global time
                mouse_3.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.addData('mouse_3.stopped', t)
                # update status
                mouse_3.status = FINISHED
        if mouse_3.status == STARTED:  # only update if started and not finished!
            buttons = mouse_3.getPressed()
            if buttons != prevButtonState:  # button state changed?
                prevButtonState = buttons
                if sum(buttons) > 0:  # state changed to a new click
                    # check if the mouse was inside our 'clickable' objects
                    gotValidClick = False
                    clickableList = environmenttools.getFromNames([a_Distractor_3, b_Base, c_Distractor_3, d_Distractor_3, e_Distractor_3], namespace=locals())
                    for obj in clickableList:
                        # is this object clicked on?
                        if obj.contains(mouse_3):
                            gotValidClick = True
                            mouse_3.clicked_name.append(obj.name)
                    if not gotValidClick:
                        mouse_3.clicked_name.append(None)
                    x, y = mouse_3.getPos()
                    mouse_3.x.append(x)
                    mouse_3.y.append(y)
                    buttons = mouse_3.getPressed()
                    mouse_3.leftButton.append(buttons[0])
                    mouse_3.midButton.append(buttons[1])
                    mouse_3.rightButton.append(buttons[2])
                    mouse_3.time.append(mouse_3.mouseClock.getTime())
                    if gotValidClick:
                        continueRoutine = False  # end routine on response
        
        # check for quit (typically the Esc key)
        if defaultKeyboard.getKeys(keyList=["escape"]):
            thisExp.status = FINISHED
        if thisExp.status == FINISHED or endExpNow:
            endExperiment(thisExp, win=win)
            return
        # pause experiment here if requested
        if thisExp.status == PAUSED:
            pauseExperiment(
                thisExp=thisExp, 
                win=win, 
                timers=[routineTimer], 
                playbackComponents=[]
            )
            # skip the frame we paused on
            continue
        
        # check if all components have finished
        if not continueRoutine:  # a component has requested a forced-end of Routine
            BlueWhite.forceEnded = routineForceEnded = True
            break
        continueRoutine = False  # will revert to True if at least one component still running
        for thisComponent in BlueWhite.components:
            if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
                continueRoutine = True
                break  # at least one component has not yet finished
        
        # refresh the screen
        if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
            win.flip()
    
    # --- Ending Routine "BlueWhite" ---
    for thisComponent in BlueWhite.components:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    # store stop times for BlueWhite
    BlueWhite.tStop = globalClock.getTime(format='float')
    BlueWhite.tStopRefresh = tThisFlipGlobal
    thisExp.addData('BlueWhite.stopped', BlueWhite.tStop)
    thisExp.addData('textbox_3.text',textbox_3.text)
    # store data for thisExp (ExperimentHandler)
    thisExp.addData('mouse_3.x', mouse_3.x)
    thisExp.addData('mouse_3.y', mouse_3.y)
    thisExp.addData('mouse_3.leftButton', mouse_3.leftButton)
    thisExp.addData('mouse_3.midButton', mouse_3.midButton)
    thisExp.addData('mouse_3.rightButton', mouse_3.rightButton)
    thisExp.addData('mouse_3.time', mouse_3.time)
    thisExp.addData('mouse_3.clicked_name', mouse_3.clicked_name)
    # using non-slip timing so subtract the expected duration of this Routine (unless ended on request)
    if BlueWhite.maxDurationReached:
        routineTimer.addTime(-BlueWhite.maxDuration)
    elif BlueWhite.forceEnded:
        routineTimer.reset()
    else:
        routineTimer.addTime(-175.000000)
    thisExp.nextEntry()
    
    # --- Prepare to start Routine "RedGreen" ---
    # create an object to store info about Routine RedGreen
    RedGreen = data.Routine(
        name='RedGreen',
        components=[text_13, Base_4, text_14, text_15, textbox_4, text_16, a_Distractor_4, b_Distractor_4, c_Distractor_4, d_Distractor_4, e_Base, mouse_4],
    )
    RedGreen.status = NOT_STARTED
    continueRoutine = True
    # update component parameters for each repeat
    textbox_4.reset()
    # setup some python lists for storing info about the mouse_4
    mouse_4.x = []
    mouse_4.y = []
    mouse_4.leftButton = []
    mouse_4.midButton = []
    mouse_4.rightButton = []
    mouse_4.time = []
    mouse_4.clicked_name = []
    gotValidClick = False  # until a click is received
    # store start times for RedGreen
    RedGreen.tStartRefresh = win.getFutureFlipTime(clock=globalClock)
    RedGreen.tStart = globalClock.getTime(format='float')
    RedGreen.status = STARTED
    thisExp.addData('RedGreen.started', RedGreen.tStart)
    RedGreen.maxDuration = None
    # keep track of which components have finished
    RedGreenComponents = RedGreen.components
    for thisComponent in RedGreen.components:
        thisComponent.tStart = None
        thisComponent.tStop = None
        thisComponent.tStartRefresh = None
        thisComponent.tStopRefresh = None
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
    # reset timers
    t = 0
    _timeToFirstFrame = win.getFutureFlipTime(clock="now")
    frameN = -1
    
    # --- Run Routine "RedGreen" ---
    RedGreen.forceEnded = routineForceEnded = not continueRoutine
    while continueRoutine and routineTimer.getTime() < 175.0:
        # get current time
        t = routineTimer.getTime()
        tThisFlip = win.getFutureFlipTime(clock=routineTimer)
        tThisFlipGlobal = win.getFutureFlipTime(clock=None)
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        
        # *text_13* updates
        
        # if text_13 is starting this frame...
        if text_13.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            text_13.frameNStart = frameN  # exact frame index
            text_13.tStart = t  # local t and not account for scr refresh
            text_13.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text_13, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text_13.started')
            # update status
            text_13.status = STARTED
            text_13.setAutoDraw(True)
        
        # if text_13 is active this frame...
        if text_13.status == STARTED:
            # update params
            pass
        
        # if text_13 is stopping this frame...
        if text_13.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text_13.tStartRefresh + 5.0-frameTolerance:
                # keep track of stop time/frame for later
                text_13.tStop = t  # not accounting for scr refresh
                text_13.tStopRefresh = tThisFlipGlobal  # on global time
                text_13.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text_13.stopped')
                # update status
                text_13.status = FINISHED
                text_13.setAutoDraw(False)
        
        # *Base_4* updates
        
        # if Base_4 is starting this frame...
        if Base_4.status == NOT_STARTED and tThisFlip >= 5.0-frameTolerance:
            # keep track of start time/frame for later
            Base_4.frameNStart = frameN  # exact frame index
            Base_4.tStart = t  # local t and not account for scr refresh
            Base_4.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(Base_4, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'Base_4.started')
            # update status
            Base_4.status = STARTED
            Base_4.setAutoDraw(True)
        
        # if Base_4 is active this frame...
        if Base_4.status == STARTED:
            # update params
            pass
        
        # if Base_4 is stopping this frame...
        if Base_4.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > Base_4.tStartRefresh + 10.0-frameTolerance:
                # keep track of stop time/frame for later
                Base_4.tStop = t  # not accounting for scr refresh
                Base_4.tStopRefresh = tThisFlipGlobal  # on global time
                Base_4.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'Base_4.stopped')
                # update status
                Base_4.status = FINISHED
                Base_4.setAutoDraw(False)
        
        # *text_14* updates
        
        # if text_14 is starting this frame...
        if text_14.status == NOT_STARTED and tThisFlip >= 15.0-frameTolerance:
            # keep track of start time/frame for later
            text_14.frameNStart = frameN  # exact frame index
            text_14.tStart = t  # local t and not account for scr refresh
            text_14.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text_14, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text_14.started')
            # update status
            text_14.status = STARTED
            text_14.setAutoDraw(True)
        
        # if text_14 is active this frame...
        if text_14.status == STARTED:
            # update params
            pass
        
        # if text_14 is stopping this frame...
        if text_14.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text_14.tStartRefresh + 5.0-frameTolerance:
                # keep track of stop time/frame for later
                text_14.tStop = t  # not accounting for scr refresh
                text_14.tStopRefresh = tThisFlipGlobal  # on global time
                text_14.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text_14.stopped')
                # update status
                text_14.status = FINISHED
                text_14.setAutoDraw(False)
        
        # *text_15* updates
        
        # if text_15 is starting this frame...
        if text_15.status == NOT_STARTED and tThisFlip >= 20.0-frameTolerance:
            # keep track of start time/frame for later
            text_15.frameNStart = frameN  # exact frame index
            text_15.tStart = t  # local t and not account for scr refresh
            text_15.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text_15, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text_15.started')
            # update status
            text_15.status = STARTED
            text_15.setAutoDraw(True)
        
        # if text_15 is active this frame...
        if text_15.status == STARTED:
            # update params
            pass
        
        # if text_15 is stopping this frame...
        if text_15.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text_15.tStartRefresh + 30.0-frameTolerance:
                # keep track of stop time/frame for later
                text_15.tStop = t  # not accounting for scr refresh
                text_15.tStopRefresh = tThisFlipGlobal  # on global time
                text_15.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text_15.stopped')
                # update status
                text_15.status = FINISHED
                text_15.setAutoDraw(False)
        
        # *textbox_4* updates
        
        # if textbox_4 is starting this frame...
        if textbox_4.status == NOT_STARTED and tThisFlip >= 20.0-frameTolerance:
            # keep track of start time/frame for later
            textbox_4.frameNStart = frameN  # exact frame index
            textbox_4.tStart = t  # local t and not account for scr refresh
            textbox_4.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(textbox_4, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'textbox_4.started')
            # update status
            textbox_4.status = STARTED
            textbox_4.setAutoDraw(True)
        
        # if textbox_4 is active this frame...
        if textbox_4.status == STARTED:
            # update params
            pass
        
        # if textbox_4 is stopping this frame...
        if textbox_4.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > textbox_4.tStartRefresh + 30.0-frameTolerance:
                # keep track of stop time/frame for later
                textbox_4.tStop = t  # not accounting for scr refresh
                textbox_4.tStopRefresh = tThisFlipGlobal  # on global time
                textbox_4.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'textbox_4.stopped')
                # update status
                textbox_4.status = FINISHED
                textbox_4.setAutoDraw(False)
        
        # *text_16* updates
        
        # if text_16 is starting this frame...
        if text_16.status == NOT_STARTED and tThisFlip >= 50.0-frameTolerance:
            # keep track of start time/frame for later
            text_16.frameNStart = frameN  # exact frame index
            text_16.tStart = t  # local t and not account for scr refresh
            text_16.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text_16, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text_16.started')
            # update status
            text_16.status = STARTED
            text_16.setAutoDraw(True)
        
        # if text_16 is active this frame...
        if text_16.status == STARTED:
            # update params
            pass
        
        # if text_16 is stopping this frame...
        if text_16.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text_16.tStartRefresh + 5.0-frameTolerance:
                # keep track of stop time/frame for later
                text_16.tStop = t  # not accounting for scr refresh
                text_16.tStopRefresh = tThisFlipGlobal  # on global time
                text_16.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text_16.stopped')
                # update status
                text_16.status = FINISHED
                text_16.setAutoDraw(False)
        
        # *a_Distractor_4* updates
        
        # if a_Distractor_4 is starting this frame...
        if a_Distractor_4.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            a_Distractor_4.frameNStart = frameN  # exact frame index
            a_Distractor_4.tStart = t  # local t and not account for scr refresh
            a_Distractor_4.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(a_Distractor_4, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'a_Distractor_4.started')
            # update status
            a_Distractor_4.status = STARTED
            a_Distractor_4.setAutoDraw(True)
        
        # if a_Distractor_4 is active this frame...
        if a_Distractor_4.status == STARTED:
            # update params
            pass
        
        # if a_Distractor_4 is stopping this frame...
        if a_Distractor_4.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > a_Distractor_4.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                a_Distractor_4.tStop = t  # not accounting for scr refresh
                a_Distractor_4.tStopRefresh = tThisFlipGlobal  # on global time
                a_Distractor_4.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'a_Distractor_4.stopped')
                # update status
                a_Distractor_4.status = FINISHED
                a_Distractor_4.setAutoDraw(False)
        
        # *b_Distractor_4* updates
        
        # if b_Distractor_4 is starting this frame...
        if b_Distractor_4.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            b_Distractor_4.frameNStart = frameN  # exact frame index
            b_Distractor_4.tStart = t  # local t and not account for scr refresh
            b_Distractor_4.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(b_Distractor_4, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'b_Distractor_4.started')
            # update status
            b_Distractor_4.status = STARTED
            b_Distractor_4.setAutoDraw(True)
        
        # if b_Distractor_4 is active this frame...
        if b_Distractor_4.status == STARTED:
            # update params
            pass
        
        # if b_Distractor_4 is stopping this frame...
        if b_Distractor_4.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > b_Distractor_4.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                b_Distractor_4.tStop = t  # not accounting for scr refresh
                b_Distractor_4.tStopRefresh = tThisFlipGlobal  # on global time
                b_Distractor_4.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'b_Distractor_4.stopped')
                # update status
                b_Distractor_4.status = FINISHED
                b_Distractor_4.setAutoDraw(False)
        
        # *c_Distractor_4* updates
        
        # if c_Distractor_4 is starting this frame...
        if c_Distractor_4.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            c_Distractor_4.frameNStart = frameN  # exact frame index
            c_Distractor_4.tStart = t  # local t and not account for scr refresh
            c_Distractor_4.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(c_Distractor_4, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'c_Distractor_4.started')
            # update status
            c_Distractor_4.status = STARTED
            c_Distractor_4.setAutoDraw(True)
        
        # if c_Distractor_4 is active this frame...
        if c_Distractor_4.status == STARTED:
            # update params
            pass
        
        # if c_Distractor_4 is stopping this frame...
        if c_Distractor_4.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > c_Distractor_4.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                c_Distractor_4.tStop = t  # not accounting for scr refresh
                c_Distractor_4.tStopRefresh = tThisFlipGlobal  # on global time
                c_Distractor_4.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'c_Distractor_4.stopped')
                # update status
                c_Distractor_4.status = FINISHED
                c_Distractor_4.setAutoDraw(False)
        
        # *d_Distractor_4* updates
        
        # if d_Distractor_4 is starting this frame...
        if d_Distractor_4.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            d_Distractor_4.frameNStart = frameN  # exact frame index
            d_Distractor_4.tStart = t  # local t and not account for scr refresh
            d_Distractor_4.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(d_Distractor_4, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'd_Distractor_4.started')
            # update status
            d_Distractor_4.status = STARTED
            d_Distractor_4.setAutoDraw(True)
        
        # if d_Distractor_4 is active this frame...
        if d_Distractor_4.status == STARTED:
            # update params
            pass
        
        # if d_Distractor_4 is stopping this frame...
        if d_Distractor_4.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > d_Distractor_4.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                d_Distractor_4.tStop = t  # not accounting for scr refresh
                d_Distractor_4.tStopRefresh = tThisFlipGlobal  # on global time
                d_Distractor_4.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'd_Distractor_4.stopped')
                # update status
                d_Distractor_4.status = FINISHED
                d_Distractor_4.setAutoDraw(False)
        
        # *e_Base* updates
        
        # if e_Base is starting this frame...
        if e_Base.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            e_Base.frameNStart = frameN  # exact frame index
            e_Base.tStart = t  # local t and not account for scr refresh
            e_Base.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(e_Base, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'e_Base.started')
            # update status
            e_Base.status = STARTED
            e_Base.setAutoDraw(True)
        
        # if e_Base is active this frame...
        if e_Base.status == STARTED:
            # update params
            pass
        
        # if e_Base is stopping this frame...
        if e_Base.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > e_Base.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                e_Base.tStop = t  # not accounting for scr refresh
                e_Base.tStopRefresh = tThisFlipGlobal  # on global time
                e_Base.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'e_Base.stopped')
                # update status
                e_Base.status = FINISHED
                e_Base.setAutoDraw(False)
        # *mouse_4* updates
        
        # if mouse_4 is starting this frame...
        if mouse_4.status == NOT_STARTED and t >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            mouse_4.frameNStart = frameN  # exact frame index
            mouse_4.tStart = t  # local t and not account for scr refresh
            mouse_4.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(mouse_4, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.addData('mouse_4.started', t)
            # update status
            mouse_4.status = STARTED
            mouse_4.mouseClock.reset()
            prevButtonState = mouse_4.getPressed()  # if button is down already this ISN'T a new click
        
        # if mouse_4 is stopping this frame...
        if mouse_4.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > mouse_4.tStartRefresh + 175.0-frameTolerance:
                # keep track of stop time/frame for later
                mouse_4.tStop = t  # not accounting for scr refresh
                mouse_4.tStopRefresh = tThisFlipGlobal  # on global time
                mouse_4.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.addData('mouse_4.stopped', t)
                # update status
                mouse_4.status = FINISHED
        if mouse_4.status == STARTED:  # only update if started and not finished!
            buttons = mouse_4.getPressed()
            if buttons != prevButtonState:  # button state changed?
                prevButtonState = buttons
                if sum(buttons) > 0:  # state changed to a new click
                    # check if the mouse was inside our 'clickable' objects
                    gotValidClick = False
                    clickableList = environmenttools.getFromNames([a_Distractor_4, b_Distractor_4, c_Distractor_4, d_Distractor_4, e_Base], namespace=locals())
                    for obj in clickableList:
                        # is this object clicked on?
                        if obj.contains(mouse_4):
                            gotValidClick = True
                            mouse_4.clicked_name.append(obj.name)
                    if not gotValidClick:
                        mouse_4.clicked_name.append(None)
                    x, y = mouse_4.getPos()
                    mouse_4.x.append(x)
                    mouse_4.y.append(y)
                    buttons = mouse_4.getPressed()
                    mouse_4.leftButton.append(buttons[0])
                    mouse_4.midButton.append(buttons[1])
                    mouse_4.rightButton.append(buttons[2])
                    mouse_4.time.append(mouse_4.mouseClock.getTime())
                    if gotValidClick:
                        continueRoutine = False  # end routine on response
        
        # check for quit (typically the Esc key)
        if defaultKeyboard.getKeys(keyList=["escape"]):
            thisExp.status = FINISHED
        if thisExp.status == FINISHED or endExpNow:
            endExperiment(thisExp, win=win)
            return
        # pause experiment here if requested
        if thisExp.status == PAUSED:
            pauseExperiment(
                thisExp=thisExp, 
                win=win, 
                timers=[routineTimer], 
                playbackComponents=[]
            )
            # skip the frame we paused on
            continue
        
        # check if all components have finished
        if not continueRoutine:  # a component has requested a forced-end of Routine
            RedGreen.forceEnded = routineForceEnded = True
            break
        continueRoutine = False  # will revert to True if at least one component still running
        for thisComponent in RedGreen.components:
            if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
                continueRoutine = True
                break  # at least one component has not yet finished
        
        # refresh the screen
        if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
            win.flip()
    
    # --- Ending Routine "RedGreen" ---
    for thisComponent in RedGreen.components:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    # store stop times for RedGreen
    RedGreen.tStop = globalClock.getTime(format='float')
    RedGreen.tStopRefresh = tThisFlipGlobal
    thisExp.addData('RedGreen.stopped', RedGreen.tStop)
    thisExp.addData('textbox_4.text',textbox_4.text)
    # store data for thisExp (ExperimentHandler)
    thisExp.addData('mouse_4.x', mouse_4.x)
    thisExp.addData('mouse_4.y', mouse_4.y)
    thisExp.addData('mouse_4.leftButton', mouse_4.leftButton)
    thisExp.addData('mouse_4.midButton', mouse_4.midButton)
    thisExp.addData('mouse_4.rightButton', mouse_4.rightButton)
    thisExp.addData('mouse_4.time', mouse_4.time)
    thisExp.addData('mouse_4.clicked_name', mouse_4.clicked_name)
    # using non-slip timing so subtract the expected duration of this Routine (unless ended on request)
    if RedGreen.maxDurationReached:
        routineTimer.addTime(-RedGreen.maxDuration)
    elif RedGreen.forceEnded:
        routineTimer.reset()
    else:
        routineTimer.addTime(-175.000000)
    thisExp.nextEntry()
    
    # --- Prepare to start Routine "YellowBlack" ---
    # create an object to store info about Routine YellowBlack
    YellowBlack = data.Routine(
        name='YellowBlack',
        components=[text_17, Base_5, text_18, text_19, textbox_5, text_20, a_Base, b_Distractor_5, c_Distractor_5, d_Distractor_5, e_Distractor_5, mouse_5],
    )
    YellowBlack.status = NOT_STARTED
    continueRoutine = True
    # update component parameters for each repeat
    textbox_5.reset()
    # setup some python lists for storing info about the mouse_5
    mouse_5.x = []
    mouse_5.y = []
    mouse_5.leftButton = []
    mouse_5.midButton = []
    mouse_5.rightButton = []
    mouse_5.time = []
    mouse_5.clicked_name = []
    gotValidClick = False  # until a click is received
    # store start times for YellowBlack
    YellowBlack.tStartRefresh = win.getFutureFlipTime(clock=globalClock)
    YellowBlack.tStart = globalClock.getTime(format='float')
    YellowBlack.status = STARTED
    thisExp.addData('YellowBlack.started', YellowBlack.tStart)
    YellowBlack.maxDuration = None
    # keep track of which components have finished
    YellowBlackComponents = YellowBlack.components
    for thisComponent in YellowBlack.components:
        thisComponent.tStart = None
        thisComponent.tStop = None
        thisComponent.tStartRefresh = None
        thisComponent.tStopRefresh = None
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
    # reset timers
    t = 0
    _timeToFirstFrame = win.getFutureFlipTime(clock="now")
    frameN = -1
    
    # --- Run Routine "YellowBlack" ---
    YellowBlack.forceEnded = routineForceEnded = not continueRoutine
    while continueRoutine and routineTimer.getTime() < 175.0:
        # get current time
        t = routineTimer.getTime()
        tThisFlip = win.getFutureFlipTime(clock=routineTimer)
        tThisFlipGlobal = win.getFutureFlipTime(clock=None)
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        
        # *text_17* updates
        
        # if text_17 is starting this frame...
        if text_17.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            text_17.frameNStart = frameN  # exact frame index
            text_17.tStart = t  # local t and not account for scr refresh
            text_17.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text_17, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text_17.started')
            # update status
            text_17.status = STARTED
            text_17.setAutoDraw(True)
        
        # if text_17 is active this frame...
        if text_17.status == STARTED:
            # update params
            pass
        
        # if text_17 is stopping this frame...
        if text_17.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text_17.tStartRefresh + 5.0-frameTolerance:
                # keep track of stop time/frame for later
                text_17.tStop = t  # not accounting for scr refresh
                text_17.tStopRefresh = tThisFlipGlobal  # on global time
                text_17.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text_17.stopped')
                # update status
                text_17.status = FINISHED
                text_17.setAutoDraw(False)
        
        # *Base_5* updates
        
        # if Base_5 is starting this frame...
        if Base_5.status == NOT_STARTED and tThisFlip >= 5.0-frameTolerance:
            # keep track of start time/frame for later
            Base_5.frameNStart = frameN  # exact frame index
            Base_5.tStart = t  # local t and not account for scr refresh
            Base_5.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(Base_5, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'Base_5.started')
            # update status
            Base_5.status = STARTED
            Base_5.setAutoDraw(True)
        
        # if Base_5 is active this frame...
        if Base_5.status == STARTED:
            # update params
            pass
        
        # if Base_5 is stopping this frame...
        if Base_5.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > Base_5.tStartRefresh + 10.0-frameTolerance:
                # keep track of stop time/frame for later
                Base_5.tStop = t  # not accounting for scr refresh
                Base_5.tStopRefresh = tThisFlipGlobal  # on global time
                Base_5.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'Base_5.stopped')
                # update status
                Base_5.status = FINISHED
                Base_5.setAutoDraw(False)
        
        # *text_18* updates
        
        # if text_18 is starting this frame...
        if text_18.status == NOT_STARTED and tThisFlip >= 15.0-frameTolerance:
            # keep track of start time/frame for later
            text_18.frameNStart = frameN  # exact frame index
            text_18.tStart = t  # local t and not account for scr refresh
            text_18.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text_18, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text_18.started')
            # update status
            text_18.status = STARTED
            text_18.setAutoDraw(True)
        
        # if text_18 is active this frame...
        if text_18.status == STARTED:
            # update params
            pass
        
        # if text_18 is stopping this frame...
        if text_18.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text_18.tStartRefresh + 5.0-frameTolerance:
                # keep track of stop time/frame for later
                text_18.tStop = t  # not accounting for scr refresh
                text_18.tStopRefresh = tThisFlipGlobal  # on global time
                text_18.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text_18.stopped')
                # update status
                text_18.status = FINISHED
                text_18.setAutoDraw(False)
        
        # *text_19* updates
        
        # if text_19 is starting this frame...
        if text_19.status == NOT_STARTED and tThisFlip >= 20.0-frameTolerance:
            # keep track of start time/frame for later
            text_19.frameNStart = frameN  # exact frame index
            text_19.tStart = t  # local t and not account for scr refresh
            text_19.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text_19, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text_19.started')
            # update status
            text_19.status = STARTED
            text_19.setAutoDraw(True)
        
        # if text_19 is active this frame...
        if text_19.status == STARTED:
            # update params
            pass
        
        # if text_19 is stopping this frame...
        if text_19.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text_19.tStartRefresh + 30.0-frameTolerance:
                # keep track of stop time/frame for later
                text_19.tStop = t  # not accounting for scr refresh
                text_19.tStopRefresh = tThisFlipGlobal  # on global time
                text_19.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text_19.stopped')
                # update status
                text_19.status = FINISHED
                text_19.setAutoDraw(False)
        
        # *textbox_5* updates
        
        # if textbox_5 is starting this frame...
        if textbox_5.status == NOT_STARTED and tThisFlip >= 20.0-frameTolerance:
            # keep track of start time/frame for later
            textbox_5.frameNStart = frameN  # exact frame index
            textbox_5.tStart = t  # local t and not account for scr refresh
            textbox_5.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(textbox_5, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'textbox_5.started')
            # update status
            textbox_5.status = STARTED
            textbox_5.setAutoDraw(True)
        
        # if textbox_5 is active this frame...
        if textbox_5.status == STARTED:
            # update params
            pass
        
        # if textbox_5 is stopping this frame...
        if textbox_5.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > textbox_5.tStartRefresh + 30.0-frameTolerance:
                # keep track of stop time/frame for later
                textbox_5.tStop = t  # not accounting for scr refresh
                textbox_5.tStopRefresh = tThisFlipGlobal  # on global time
                textbox_5.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'textbox_5.stopped')
                # update status
                textbox_5.status = FINISHED
                textbox_5.setAutoDraw(False)
        
        # *text_20* updates
        
        # if text_20 is starting this frame...
        if text_20.status == NOT_STARTED and tThisFlip >= 50.0-frameTolerance:
            # keep track of start time/frame for later
            text_20.frameNStart = frameN  # exact frame index
            text_20.tStart = t  # local t and not account for scr refresh
            text_20.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(text_20, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'text_20.started')
            # update status
            text_20.status = STARTED
            text_20.setAutoDraw(True)
        
        # if text_20 is active this frame...
        if text_20.status == STARTED:
            # update params
            pass
        
        # if text_20 is stopping this frame...
        if text_20.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > text_20.tStartRefresh + 5.0-frameTolerance:
                # keep track of stop time/frame for later
                text_20.tStop = t  # not accounting for scr refresh
                text_20.tStopRefresh = tThisFlipGlobal  # on global time
                text_20.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'text_20.stopped')
                # update status
                text_20.status = FINISHED
                text_20.setAutoDraw(False)
        
        # *a_Base* updates
        
        # if a_Base is starting this frame...
        if a_Base.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            a_Base.frameNStart = frameN  # exact frame index
            a_Base.tStart = t  # local t and not account for scr refresh
            a_Base.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(a_Base, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'a_Base.started')
            # update status
            a_Base.status = STARTED
            a_Base.setAutoDraw(True)
        
        # if a_Base is active this frame...
        if a_Base.status == STARTED:
            # update params
            pass
        
        # if a_Base is stopping this frame...
        if a_Base.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > a_Base.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                a_Base.tStop = t  # not accounting for scr refresh
                a_Base.tStopRefresh = tThisFlipGlobal  # on global time
                a_Base.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'a_Base.stopped')
                # update status
                a_Base.status = FINISHED
                a_Base.setAutoDraw(False)
        
        # *b_Distractor_5* updates
        
        # if b_Distractor_5 is starting this frame...
        if b_Distractor_5.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            b_Distractor_5.frameNStart = frameN  # exact frame index
            b_Distractor_5.tStart = t  # local t and not account for scr refresh
            b_Distractor_5.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(b_Distractor_5, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'b_Distractor_5.started')
            # update status
            b_Distractor_5.status = STARTED
            b_Distractor_5.setAutoDraw(True)
        
        # if b_Distractor_5 is active this frame...
        if b_Distractor_5.status == STARTED:
            # update params
            pass
        
        # if b_Distractor_5 is stopping this frame...
        if b_Distractor_5.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > b_Distractor_5.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                b_Distractor_5.tStop = t  # not accounting for scr refresh
                b_Distractor_5.tStopRefresh = tThisFlipGlobal  # on global time
                b_Distractor_5.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'b_Distractor_5.stopped')
                # update status
                b_Distractor_5.status = FINISHED
                b_Distractor_5.setAutoDraw(False)
        
        # *c_Distractor_5* updates
        
        # if c_Distractor_5 is starting this frame...
        if c_Distractor_5.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            c_Distractor_5.frameNStart = frameN  # exact frame index
            c_Distractor_5.tStart = t  # local t and not account for scr refresh
            c_Distractor_5.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(c_Distractor_5, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'c_Distractor_5.started')
            # update status
            c_Distractor_5.status = STARTED
            c_Distractor_5.setAutoDraw(True)
        
        # if c_Distractor_5 is active this frame...
        if c_Distractor_5.status == STARTED:
            # update params
            pass
        
        # if c_Distractor_5 is stopping this frame...
        if c_Distractor_5.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > c_Distractor_5.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                c_Distractor_5.tStop = t  # not accounting for scr refresh
                c_Distractor_5.tStopRefresh = tThisFlipGlobal  # on global time
                c_Distractor_5.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'c_Distractor_5.stopped')
                # update status
                c_Distractor_5.status = FINISHED
                c_Distractor_5.setAutoDraw(False)
        
        # *d_Distractor_5* updates
        
        # if d_Distractor_5 is starting this frame...
        if d_Distractor_5.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            d_Distractor_5.frameNStart = frameN  # exact frame index
            d_Distractor_5.tStart = t  # local t and not account for scr refresh
            d_Distractor_5.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(d_Distractor_5, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'd_Distractor_5.started')
            # update status
            d_Distractor_5.status = STARTED
            d_Distractor_5.setAutoDraw(True)
        
        # if d_Distractor_5 is active this frame...
        if d_Distractor_5.status == STARTED:
            # update params
            pass
        
        # if d_Distractor_5 is stopping this frame...
        if d_Distractor_5.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > d_Distractor_5.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                d_Distractor_5.tStop = t  # not accounting for scr refresh
                d_Distractor_5.tStopRefresh = tThisFlipGlobal  # on global time
                d_Distractor_5.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'd_Distractor_5.stopped')
                # update status
                d_Distractor_5.status = FINISHED
                d_Distractor_5.setAutoDraw(False)
        
        # *e_Distractor_5* updates
        
        # if e_Distractor_5 is starting this frame...
        if e_Distractor_5.status == NOT_STARTED and tThisFlip >= 55.0-frameTolerance:
            # keep track of start time/frame for later
            e_Distractor_5.frameNStart = frameN  # exact frame index
            e_Distractor_5.tStart = t  # local t and not account for scr refresh
            e_Distractor_5.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(e_Distractor_5, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'e_Distractor_5.started')
            # update status
            e_Distractor_5.status = STARTED
            e_Distractor_5.setAutoDraw(True)
        
        # if e_Distractor_5 is active this frame...
        if e_Distractor_5.status == STARTED:
            # update params
            pass
        
        # if e_Distractor_5 is stopping this frame...
        if e_Distractor_5.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > e_Distractor_5.tStartRefresh + 120.0-frameTolerance:
                # keep track of stop time/frame for later
                e_Distractor_5.tStop = t  # not accounting for scr refresh
                e_Distractor_5.tStopRefresh = tThisFlipGlobal  # on global time
                e_Distractor_5.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.timestampOnFlip(win, 'e_Distractor_5.stopped')
                # update status
                e_Distractor_5.status = FINISHED
                e_Distractor_5.setAutoDraw(False)
        # *mouse_5* updates
        
        # if mouse_5 is starting this frame...
        if mouse_5.status == NOT_STARTED and t >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            mouse_5.frameNStart = frameN  # exact frame index
            mouse_5.tStart = t  # local t and not account for scr refresh
            mouse_5.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(mouse_5, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.addData('mouse_5.started', t)
            # update status
            mouse_5.status = STARTED
            mouse_5.mouseClock.reset()
            prevButtonState = mouse_5.getPressed()  # if button is down already this ISN'T a new click
        
        # if mouse_5 is stopping this frame...
        if mouse_5.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > mouse_5.tStartRefresh + 175.0-frameTolerance:
                # keep track of stop time/frame for later
                mouse_5.tStop = t  # not accounting for scr refresh
                mouse_5.tStopRefresh = tThisFlipGlobal  # on global time
                mouse_5.frameNStop = frameN  # exact frame index
                # add timestamp to datafile
                thisExp.addData('mouse_5.stopped', t)
                # update status
                mouse_5.status = FINISHED
        if mouse_5.status == STARTED:  # only update if started and not finished!
            buttons = mouse_5.getPressed()
            if buttons != prevButtonState:  # button state changed?
                prevButtonState = buttons
                if sum(buttons) > 0:  # state changed to a new click
                    # check if the mouse was inside our 'clickable' objects
                    gotValidClick = False
                    clickableList = environmenttools.getFromNames([a_Base, b_Distractor_5, c_Distractor_5, d_Distractor_5, e_Distractor_5], namespace=locals())
                    for obj in clickableList:
                        # is this object clicked on?
                        if obj.contains(mouse_5):
                            gotValidClick = True
                            mouse_5.clicked_name.append(obj.name)
                    if not gotValidClick:
                        mouse_5.clicked_name.append(None)
                    x, y = mouse_5.getPos()
                    mouse_5.x.append(x)
                    mouse_5.y.append(y)
                    buttons = mouse_5.getPressed()
                    mouse_5.leftButton.append(buttons[0])
                    mouse_5.midButton.append(buttons[1])
                    mouse_5.rightButton.append(buttons[2])
                    mouse_5.time.append(mouse_5.mouseClock.getTime())
                    if gotValidClick:
                        continueRoutine = False  # end routine on response
        
        # check for quit (typically the Esc key)
        if defaultKeyboard.getKeys(keyList=["escape"]):
            thisExp.status = FINISHED
        if thisExp.status == FINISHED or endExpNow:
            endExperiment(thisExp, win=win)
            return
        # pause experiment here if requested
        if thisExp.status == PAUSED:
            pauseExperiment(
                thisExp=thisExp, 
                win=win, 
                timers=[routineTimer], 
                playbackComponents=[]
            )
            # skip the frame we paused on
            continue
        
        # check if all components have finished
        if not continueRoutine:  # a component has requested a forced-end of Routine
            YellowBlack.forceEnded = routineForceEnded = True
            break
        continueRoutine = False  # will revert to True if at least one component still running
        for thisComponent in YellowBlack.components:
            if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
                continueRoutine = True
                break  # at least one component has not yet finished
        
        # refresh the screen
        if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
            win.flip()
    
    # --- Ending Routine "YellowBlack" ---
    for thisComponent in YellowBlack.components:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    # store stop times for YellowBlack
    YellowBlack.tStop = globalClock.getTime(format='float')
    YellowBlack.tStopRefresh = tThisFlipGlobal
    thisExp.addData('YellowBlack.stopped', YellowBlack.tStop)
    thisExp.addData('textbox_5.text',textbox_5.text)
    # store data for thisExp (ExperimentHandler)
    thisExp.addData('mouse_5.x', mouse_5.x)
    thisExp.addData('mouse_5.y', mouse_5.y)
    thisExp.addData('mouse_5.leftButton', mouse_5.leftButton)
    thisExp.addData('mouse_5.midButton', mouse_5.midButton)
    thisExp.addData('mouse_5.rightButton', mouse_5.rightButton)
    thisExp.addData('mouse_5.time', mouse_5.time)
    thisExp.addData('mouse_5.clicked_name', mouse_5.clicked_name)
    # using non-slip timing so subtract the expected duration of this Routine (unless ended on request)
    if YellowBlack.maxDurationReached:
        routineTimer.addTime(-YellowBlack.maxDuration)
    elif YellowBlack.forceEnded:
        routineTimer.reset()
    else:
        routineTimer.addTime(-175.000000)
    thisExp.nextEntry()
    
    # mark experiment as finished
    endExperiment(thisExp, win=win)


def saveData(thisExp):
    """
    Save data from this experiment
    
    Parameters
    ==========
    thisExp : psychopy.data.ExperimentHandler
        Handler object for this experiment, contains the data to save and information about 
        where to save it to.
    """
    filename = thisExp.dataFileName
    # these shouldn't be strictly necessary (should auto-save)
    thisExp.saveAsWideText(filename + '.csv', delim='auto')
    thisExp.saveAsPickle(filename)


def endExperiment(thisExp, win=None):
    """
    End this experiment, performing final shut down operations.
    
    This function does NOT close the window or end the Python process - use `quit` for this.
    
    Parameters
    ==========
    thisExp : psychopy.data.ExperimentHandler
        Handler object for this experiment, contains the data to save and information about 
        where to save it to.
    win : psychopy.visual.Window
        Window for this experiment.
    """
    if win is not None:
        # remove autodraw from all current components
        win.clearAutoDraw()
        # Flip one final time so any remaining win.callOnFlip() 
        # and win.timeOnFlip() tasks get executed
        win.flip()
    # return console logger level to WARNING
    logging.console.setLevel(logging.WARNING)
    # mark experiment handler as finished
    thisExp.status = FINISHED
    logging.flush()


def quit(thisExp, win=None, thisSession=None):
    """
    Fully quit, closing the window and ending the Python process.
    
    Parameters
    ==========
    win : psychopy.visual.Window
        Window to close.
    thisSession : psychopy.session.Session or None
        Handle of the Session object this experiment is being run from, if any.
    """
    thisExp.abort()  # or data files will save again on exit
    # make sure everything is closed down
    if win is not None:
        # Flip one final time so any remaining win.callOnFlip() 
        # and win.timeOnFlip() tasks get executed before quitting
        win.flip()
        win.close()
    logging.flush()
    if thisSession is not None:
        thisSession.stop()
    # terminate Python process
    core.quit()


# if running this experiment as a script...
if __name__ == '__main__':
    # call all functions in order
    expInfo = showExpInfoDlg(expInfo=expInfo)
    thisExp = setupData(expInfo=expInfo)
    logFile = setupLogging(filename=thisExp.dataFileName)
    win = setupWindow(expInfo=expInfo)
    setupDevices(expInfo=expInfo, thisExp=thisExp, win=win)
    run(
        expInfo=expInfo, 
        thisExp=thisExp, 
        win=win,
        globalClock='float'
    )
    saveData(thisExp=thisExp)
    quit(thisExp=thisExp, win=win)