Exemplo n.º 1
0
def PlotStimuli(pos):
    composition = stimuli.BlankScreen()
    picture.plot(composition)
    bar.plot(composition)
    barEndLeft.plot(composition)
    barEndRight.plot(composition)
    slider = stimuli.Rectangle((3, 30), position=pos, colour=(194, 24, 7))
    slider.plot(composition)
    composition.present()
 def make_surface(trial):
     sf = stimuli.BlankScreen()
     boundary = self.exp.config.gettuple('APPEARANCE', 'colour_window_boundary')
     if boundary:
         stimuli.Rectangle(self.exp.screen.window_size,
                           line_width=self.line_width,
                           colour=boundary).plot(sf)
     [s.plot(sf) for s in trial.stimuli]
     return sf
Exemplo n.º 3
0
 def stimulus(self, infotext=""):
     """Return the stimulus including infotext (obligatory)"""
     canvas = stimuli.BlankScreen()
     for elem in self.elements:
         elem.plot(canvas)
     if len(infotext) > 0:
         RecordingScreen._text_line(text=infotext, position=[0, 0],
                                   text_size=36).plot(canvas)
     return canvas
def hold_check(exp,
               holding_time,
               background_stimulus=None,
               n_sensors=2):  # FIXME not checked for sensor=1
    if background_stimulus is None:
        background_stimulus = stimuli.BlankScreen()

    background_stimulus.present()
    background_stimulus.present()
    udp.send("hold:test")

    fine = stimuli.Circle(radius=20,
                          colour=misc.constants.C_GREY,
                          line_width=0)
    too_low = stimuli.Circle(radius=20,
                             colour=misc.constants.C_GREEN,
                             line_width=0)
    too_strong = stimuli.Circle(radius=20,
                                colour=misc.constants.C_RED,
                                line_width=0)
    bkg = [
        stimuli.Circle(position=(-200, 0),
                       radius=24,
                       colour=misc.constants.C_BLACK,
                       line_width=0),
        stimuli.Circle(position=(200, 0),
                       radius=24,
                       colour=misc.constants.C_BLACK,
                       line_width=0)
    ]

    key = None
    stopwatch.reset_stopwatch()

    while key is None and stopwatch.stopwatch_time < holding_time:
        key = exp.keyboard.check()
        udp.clear_receive_buffer()
        lv = [
            rc.get_data(rc.Command.GET_THRESHOLD_LEVEL),
            rc.get_data(rc.Command.GET_THRESHOLD_LEVEL2)
        ]
        for i in range(n_sensors):
            bkg[i].clear_surface()
            if lv[i] == WEAK:
                too_low.plot(bkg[i])
                stopwatch.reset_stopwatch()
            elif lv[i] == STRONG:
                too_strong.plot(bkg[i])
                stopwatch.reset_stopwatch()
            elif lv[i] == FINE:
                fine.plot(bkg[i])
            bkg[i].present(clear=False, update=False)
            bkg[i].present(clear=False, update=False)
        exp.screen.update()

    background_stimulus.present()
Exemplo n.º 5
0
def _clickable_numeric_input(title, start_at):
    # copied from the 0.7.0 release of expyriment
    # https://github.com/expyriment/expyriment/blob/81acb8be1a2abcecdbbfe501e9c4f662c9ba6620/expyriment/control/_experiment_control.py#L96
    background_stimulus = stimuli.BlankScreen(colour=(0, 0, 0))
    fields = [
        stimuli.Circle(diameter=200, colour=(70, 70, 70), position=(0, 70)),
        stimuli.Circle(diameter=200, colour=(70, 70, 70), position=(0, -70)),
        stimuli.Rectangle(size=(50, 50),
                          colour=(70, 70, 70),
                          position=(120, 0))
    ]
    fields[0].scale((0.25, 0.25))
    fields[1].scale((0.25, 0.25))

    # stimuli.TextLine(text="-", text_size=36, position=(0, -70),
    #                  text_font="FreeMono",
    #                  text_colour=(0, 0, 0)),
    plusminus = [
        stimuli.TextLine(title,
                         text_size=24,
                         text_colour=misc.constants.C_EXPYRIMENT_PURPLE,
                         position=(-182, 0)),
        stimuli.FixCross(size=(15, 15),
                         position=(0, 70),
                         colour=(0, 0, 0),
                         line_width=2),
        stimuli.FixCross(size=(15, 2),
                         position=(0, -70),
                         colour=(0, 0, 0),
                         line_width=2),
        stimuli.TextLine(text="Go",
                         text_size=18,
                         position=(120, 0),
                         text_colour=(0, 0, 0))
    ]
    number = int(start_at)

    while True:
        text = stimuli.TextLine(text="{0}".format(number),
                                text_size=28,
                                text_colour=misc.constants.C_EXPYRIMENT_ORANGE)
        btn = io.TouchScreenButtonBox(button_fields=fields,
                                      stimuli=plusminus + [text],
                                      background_stimulus=background_stimulus)
        btn.show()
        key, rt = btn.wait()
        if key == fields[0]:
            number += 1
        elif key == fields[1]:
            number -= 1
            if number <= 0:
                number = 0
        elif key == fields[2]:
            break
    return (number)
Exemplo n.º 6
0
    def __init__(self, device_ID=0, error_screen=True):
        """Create a Cedrus Device Input.

        Notes
        -----
        If no Cedrus device is connected, an error text screen will be
        presented informing that the device could not be found and suggesting
        to check the connection and to switch on the device. After keypress the
        class tries to reconnect with the device. Use <q> to quit this
        procedure.

        Parameters
        ----------
        device_id : int, optional
            device ID (default=0). Only required if more than one
            Cedrus Devices are connected.
        error_screen : bool, optional
            set False to switch off the 'device not found' error screen.
            An exception will be raise instead (default=True)

        """

        Input.__init__(self)
        if not isinstance(_pyxid, ModuleType):
            message = """CedrusDevice can not be initialized, because the Python package
            'pyxid' is not installed. See Expyriment online documentation."""
            raise ImportError(message)

        while True:
            devices = _pyxid.get_xid_devices()
            if len(devices) < 1:
                message = "Could not find a Cedrus Device. Please check the connection and \n"\
                + " ensure that the device is switch on."
            else:
                if not devices[device_ID].is_response_device():
                    message = "Cedrus Device #{0} is not a response device.".format(
                        device_ID)
                else:
                    self._xid = devices[device_ID]
                    break
            if error_screen and _internals.active_exp.is_initialized:
                stimuli.TextScreen(
                    "Error", message +
                    " Press a key to reconnect to the device.").present()
                _internals.active_exp.keyboard.wait()
                stimuli.BlankScreen().present()
                _internals.active_exp.clock.wait(300)
            else:
                raise IOError(message)

        self._xid.reset_base_timer()
        self._xid.reset_rt_timer()
        self._device_ID = device_ID
        self._buffer = misc.Buffer(name="Cedrus Device {0}".format(device_ID))
Exemplo n.º 7
0
 def __init__(self, task, lsl_stream, fixationTime, instructions_path,
              exp=None, is_practice=False):
     self.task = task;
     self.show_cross_for_seconds = fixationTime;
     self.is_practice = is_practice
     self.canvas = stimuli.BlankScreen()
     self.exp = exp
     self.instructions_path = instructions_path
     self.file = file
     self.lsl_stream = lsl_stream
     self.task = task
Exemplo n.º 8
0
    def ask_for_order(self):
        canvas = stimuli.BlankScreen()
        order1_ = stimuli.Rectangle(size=(100, 80), position=(-200, 0))
        Order1 = stimuli.TextLine(text="Order1", position=order1_.position,
                                  text_colour=misc.constants.C_WHITE)
        order2_ = stimuli.Rectangle(size=(100, 80), position=(-70, 0))
        Order2 = stimuli.TextLine(text="Order2", position=order2_.position,
                                  text_colour=misc.constants.C_WHITE)

        order3_ = stimuli.Rectangle(size=(100, 80), position=(60, 0))
        Order3 = stimuli.TextLine(text="Order3", position=order3_.position,
                                  text_colour=misc.constants.C_WHITE)

        order4_ = stimuli.Rectangle(size=(100, 80), position=(200, 0))
        Order4 = stimuli.TextLine(text="Order4", position=order4_.position,
                                  text_colour=misc.constants.C_WHITE)

        order1_.plot(canvas)
        Order1.plot(canvas)

        order2_.plot(canvas)
        Order2.plot(canvas)

        order3_.plot(canvas)
        Order3.plot(canvas)

        order4_.plot(canvas)
        Order4.plot(canvas)

        self.experiment.exp.mouse.show_cursor()
        canvas.present()

        while True:
            id, pos, _rt = self.experiment.exp.mouse.wait_press()

            if order1_.overlapping_with_position(pos):
                self.experiment.exp.mouse.hide_cursor()
                self.current_block_order_number = '1'
                return

            elif order2_.overlapping_with_position(pos):
                self.experiment.exp.mouse.hide_cursor()
                self.current_block_order_number = '2'
                return

            elif order3_.overlapping_with_position(pos):
                self.experiment.exp.mouse.hide_cursor()
                self.current_block_order_number = '3'
                return

            elif order4_.overlapping_with_position(pos):
                self.experiment.exp.mouse.hide_cursor()
                self.current_block_order_number = '4'
                return
Exemplo n.º 9
0
    def paint_all_lines(self):
        self.canvas = stimuli.BlankScreen()

        index = 0
        for line_text in self.text_array:
            y_position = self.line_positions_y[index]
            self.write_text(line_text, self.edges_text[index], y_position,
                            self.canvas)
            self.paint_line(y_position, self.canvas,
                            self.new_marks_positions[index])
            index += 1
        self.canvas.present()
        self.old_marks_positions = copy.deepcopy(self.new_marks_positions)
Exemplo n.º 10
0
def blocks(nb_el_block, nb_probes, exp, block_name):
    """Run a block of trials with the inputed parameters
    Saves in the expyriment data file : subject_id, stimulus (digit), button pressed (always space), RT , error, block name
    Saves in the manually created data file : block name, trial number, reponse and rt to both Probes

    Is used once for the practice block and another number of time (chosen in the parameters) for the real blocks
    """
    #random size out of 5
    font_sizes_list = [48, 72, 94, 100, 120]

    #list far easier this way
    #numbers = list(range(0,10))
    repetitions = round(nb_el_block / 10)
    block = []
    for i in range(repetitions):
        for j in range(0, 10):
            block.append(j)

    probe_trials = probe_random(nb_el_block, nb_probes)
    trial_number = 0
    for digit in block:
        trial_number += 1
        f_size = randint(0, 4)
        target = stimuli.TextLine(text=str(digit),
                                  text_size=font_sizes_list[f_size])
        mask = stimuli.TextLine(text='X\u0336',
                                text_size=font_sizes_list[f_size])

        target.present()
        exp.clock.wait(250)
        mask.present()
        button, rt = exp.keyboard.wait(misc.constants.K_SPACE, 900)

        #to make sure the ITI stays at 1150ms
        if rt != None:
            time_left = 900 - rt
            exp.clock.wait(time_left - stimuli.BlankScreen().present())

        error = (button == misc.constants.K_SPACE
                 and digit == 3) or (button == [] and digit != 3)
        exp.data.add([digit, button, rt, int(error), block_name])

        #probe trials
        if trial_number in probe_trials:
            button_r, rt_r, button_c, rt_c = probes()

            globals()[''.join(data_probe_name)] = open(''.join(data_file_name),
                                                       "a")
            globals()[''.join(data_probe_name)].write(str(block_name)+','+str(trial_number)\
            +','+str(button_r)+','+str(rt_r)+','+str(button_c)+','+str(rt_c)+ '\n')
            globals()[''.join(data_probe_name)].close
Exemplo n.º 11
0
    def show_feedback_if_needed(self):
        currentTrialsNumber = self.test_trials_number;
        if self.is_practice:
            currentTrialsNumber = self.practice_trials_number;
        if self.is_practice == True:
            canvas = stimuli.BlankScreen()
            text_title = stimuli.TextLine("Success Rate", (0,0), text_size=(50))
            success_rate = str(float(self.correct_trials) / currentTrialsNumber * 100)
            text_number = stimuli.TextLine(success_rate + "%", position=(0, -100),\
                                           text_size=(50))

            text_title.plot(canvas)
            text_number.plot(canvas)
            canvas.present();
Exemplo n.º 12
0
    def prepare_grid_stimulus(self):
        side = self.num_boxes**(0.5)
        block_size = self.canvas_size / side
        center = self.canvas_size / 2
        grid = stimuli.BlankScreen()

        colour_grid = self.exp._colours(
            self.exp.config.get('APPEARANCE', 'colour_grid'))
        colour_fixation_cross = self.exp._colours(
            self.exp.config.get('APPEARANCE', 'colour_fixation_cross'))
        antialiasing = 10 if self.exp.config.getboolean(
            'APPEARANCE', 'antialiasing') else None

        if colour_grid:
            for a, b in [(i % side, i // side) for i in range(self.num_boxes)]:
                stimuli.Line(
                    (a * block_size - center, b * block_size - center),
                    ((a + 1) * block_size - center, b * block_size - center),
                    line_width=self.line_width,
                    colour=colour_grid,
                    anti_aliasing=antialiasing).plot(grid)
                stimuli.Line(
                    (a * block_size - center, b * block_size - center),
                    (a * block_size - center, (b + 1) * block_size - center),
                    line_width=self.line_width,
                    colour=(colour_grid),
                    anti_aliasing=antialiasing).plot(grid)

            stimuli.Line(
                (0 - center, side * block_size - center),
                (side * block_size - center, side * block_size - center),
                line_width=self.line_width,
                colour=colour_grid,
                anti_aliasing=antialiasing).plot(grid)
            stimuli.Line(
                (side * block_size - center, 0 - center),
                (side * block_size - center, side * block_size - center),
                line_width=self.line_width,
                colour=colour_grid,
                anti_aliasing=antialiasing).plot(grid)

        if colour_fixation_cross:
            stimuli.FixCross(colour=colour_fixation_cross).plot(grid)
        grid.preload()
        return (grid)
Exemplo n.º 13
0
def ask_for_task():

    canvas = stimuli.BlankScreen()
    develop_mode = use_develop_mode
    design.defaults.experiment_background_colour = misc.constants.C_GREY
    design.defaults.experiment_foreground_colour = misc.constants.C_BLACK

    N_back = stimuli.Rectangle(size=(100, 80), position=(200, 0))
    text_N_back = stimuli.TextLine(text="N back",
                                   position=N_back.position,
                                   text_colour=misc.constants.C_WHITE)

    Stroop = stimuli.Rectangle(size=(100, 80), position=(-200, 0))
    text_Stroop = stimuli.TextLine(text="Stroop",
                                   position=Stroop.position,
                                   text_colour=misc.constants.C_WHITE)

    exit = stimuli.Rectangle(size=(100, 80), position=(0, -200))
    text_exit = stimuli.TextLine(text="Exit",
                                 position=exit.position,
                                 text_colour=misc.constants.C_WHITE)
    N_back.plot(canvas)
    text_N_back.plot(canvas)

    Stroop.plot(canvas)
    text_Stroop.plot(canvas)

    exit.plot(canvas)
    text_exit.plot(canvas)

    exp.mouse.show_cursor()
    canvas.present()

    while True:
        id, pos, _rt = exp.mouse.wait_press()

        if N_back.overlapping_with_position(pos):
            exp.mouse.hide_cursor()
            return 'n_back', exp
        elif Stroop.overlapping_with_position(pos):
            exp.mouse.hide_cursor()
            return 'stroop', exp
        elif exit.overlapping_with_position(pos):
            exp.mouse.hide_cursor()
            return 'exit', exp
Exemplo n.º 14
0
 def show_feedback_if_needed(self):
     if self.is_practice == True:
         canvas = stimuli.BlankScreen()
         text_title = stimuli.TextLine("Success Rate", (0, 0),
                                       text_size=(50))
         success_rate = int(float(self.hit_trials) / self.targets_amount * 100) - \
                            int(float(self.FA_trials) / (self.trials_number - self.targets_amount) * 100)
         if success_rate < 0:
             success_rate = "0"
         if success_rate > 100:
             success_rate = "100"
         else:
             success_rate = str(success_rate)
         text_number = stimuli.TextLine(success_rate + "%", position=(0, -100),\
                                        text_size=(50))
         text_title.plot(canvas)
         text_number.plot(canvas)
         canvas.present()
Exemplo n.º 15
0
    def write_anticipation_text(self):
        self.canvas = stimuli.BlankScreen()

        self.plot_instructions()
        self.canvas.present()
        if self.is_practice:
            key, rt = self.exp.keyboard.wait([self.continue_key,\
                                              self.exit_key], self.show_instructions_for_seconds * 1000)
            if key is self.continue_key:
                return True
            elif key is self.exit_key:
                return False

        else:
            key, rt = self.exp.keyboard.wait([self.exit_key], self.show_instructions_for_seconds * 1000)
            if key is self.exit_key:
                return False
            return True
Exemplo n.º 16
0
    def ask_for_condition(self):
        canvas = stimuli.BlankScreen()
        Practice = stimuli.Rectangle(size=(100, 80), position=(200, 0))
        text_Practice = stimuli.TextLine(text="Practice",
                                         position=Practice.position,
                                         text_colour=misc.constants.C_WHITE)
        Basic = stimuli.Rectangle(size=(100, 80), position=(-200, 0))
        text_Basic = stimuli.TextLine(text="Test",
                                      position=Basic.position,
                                      text_colour=misc.constants.C_WHITE)

        exit = stimuli.Rectangle(size=(100, 80), position=(0, -200))
        text_exit = stimuli.TextLine(text="Exit",
                                     position=exit.position,
                                     text_colour=misc.constants.C_WHITE)

        Practice.plot(canvas)
        text_Practice.plot(canvas)

        Basic.plot(canvas)
        text_Basic.plot(canvas)

        exit.plot(canvas)
        text_exit.plot(canvas)

        self.experiment.exp.mouse.show_cursor()
        canvas.present()

        while True:
            id, pos, _rt = self.experiment.exp.mouse.wait_press()

            if Practice.overlapping_with_position(pos):
                self.experiment.exp.mouse.hide_cursor()
                return 'practice'
            elif Basic.overlapping_with_position(pos):
                self.experiment.exp.mouse.hide_cursor()
                return 'test'
            elif exit.overlapping_with_position(pos):
                self.experiment.exp.mouse.hide_cursor()
                return 'exit'
Exemplo n.º 17
0
    def ask_for_level(self):
        canvas = stimuli.BlankScreen()
        level1 = stimuli.Rectangle(size=(100, 80), position=(200, 0))
        text_level1 = stimuli.TextLine(text="1 back",
                                       position=level1.position,
                                       text_colour=misc.constants.C_WHITE)
        level2 = stimuli.Rectangle(size=(100, 80), position=(0, 0))
        text_level2 = stimuli.TextLine(text="2 back",
                                       position=level2.position,
                                       text_colour=misc.constants.C_WHITE)

        level3 = stimuli.Rectangle(size=(100, 80), position=(-200, 0))
        text_level3 = stimuli.TextLine(text="3 back",
                                       position=level3.position,
                                       text_colour=misc.constants.C_WHITE)

        level1.plot(canvas)
        text_level1.plot(canvas)

        level2.plot(canvas)
        text_level2.plot(canvas)

        level3.plot(canvas)
        text_level3.plot(canvas)

        self.experiment.exp.mouse.show_cursor()
        canvas.present()

        while True:
            id, pos, _rt = self.experiment.exp.mouse.wait_press()

            if level1.overlapping_with_position(pos):
                self.experiment.exp.mouse.hide_cursor()
                return "1"
            elif level2.overlapping_with_position(pos):
                self.experiment.exp.mouse.hide_cursor()
                return "2"
            elif level3.overlapping_with_position(pos):
                self.experiment.exp.mouse.hide_cursor()
                return "3"
Exemplo n.º 18
0
    def ask_for_practice_type(self):
        canvas = stimuli.BlankScreen()
        auditory = stimuli.Rectangle(size=(100, 80), position=(200, 0))
        text_auditory = stimuli.TextLine(text="auditory",
                                         position=auditory.position,
                                         text_colour=misc.constants.C_WHITE)
        spatial = stimuli.Rectangle(size=(100, 80), position=(-200, 0))
        text_spatial = stimuli.TextLine(text="spatial",
                                        position=spatial.position,
                                        text_colour=misc.constants.C_WHITE)

        both = stimuli.Rectangle(size=(100, 80), position=(0, 0))
        text_both = stimuli.TextLine(text="both",
                                     position=both.position,
                                     text_colour=misc.constants.C_WHITE)

        auditory.plot(canvas)
        text_auditory.plot(canvas)

        spatial.plot(canvas)
        text_spatial.plot(canvas)

        both.plot(canvas)
        text_both.plot(canvas)

        self.experiment.exp.mouse.show_cursor()
        canvas.present()

        while True:
            id, pos, _rt = self.experiment.exp.mouse.wait_press()

            if auditory.overlapping_with_position(pos):
                self.experiment.exp.mouse.hide_cursor()
                return "a"
            elif spatial.overlapping_with_position(pos):
                self.experiment.exp.mouse.hide_cursor()
                return "v"
            elif both.overlapping_with_position(pos):
                self.experiment.exp.mouse.hide_cursor()
                return "both"
def execute_trial(motion_coherence,
                  direction,
                  number_dots,
                  time_duration=MAX_RESPONSE_DELAY):
    dot_list = generate_n_dots(N_DOTS)
    stimuli.BlankScreen().present()
    arena = stimuli.Circle(radius=RADIUS_OF_ARENA + 2 * RADIUS_OF_DOTS,
                           colour=COLOR_OF_ARENA)
    cue = stimuli.FixCross(size=(SIZE_FIXATION_CROSS, SIZE_FIXATION_CROSS),
                           line_width=LINE_WIDTH_FIXATION_CROSS)

    cue.present()
    exp.clock.wait(1000)

    key = exp.keyboard.check()
    exp.clock.reset_stopwatch()

    while (exp.clock.stopwatch_time < time_duration) and (key is None):

        update_stimulus(dot_list, arena)
        key, time = check_keyboard_response_and_time()
        exp.clock.wait(1)

    return (key, time)
Exemplo n.º 20
0
##c.wait(2000)
##
##print "--> ", c.time, "quit"
##udp.send("quit")
##feedback = udp.poll()
##while feedback is None:
##    feedback = udp.poll()
##print "<-- ", c.time,  feedback

while True:
    key = exp.keyboard.check()
    if key == ord("q"):
        break
    elif key == misc.constants.K_SPACE:
        text = io.TextInput().get()
        stimuli.BlankScreen().present()
        print "--> ", c.time, text
        udp_connection.send(text)
    elif key == ord("t"):
        times = []
        for cnt in range(20):
            stimuli.TextLine("ping test " + str(cnt)).present()
            c.reset_stopwatch()
            ok, time = udp_connection.ping()
            print c.stopwatch_time
            times.append(time)
            c.wait(100)
        stimuli.BlankScreen().present()
        print times

    feedback = udp_connection.poll()
Exemplo n.º 21
0
WORD_DURATION = 400
PICTURE_DURATION = 1000
TEXT_DURATION = 3000
#TOTAL_EXPE_DURATION = 20000 # 10 sec

exp = expyriment.design.Experiment(name="HiRes Experiment")
#expyriment.control.defaults.open_gl=1
expyriment.control.defaults.window_size = (1280, 1028)
expyriment.control.set_develop_mode(True)

#%

expyriment.control.initialize(exp)

kb = expyriment.io.Keyboard()
bs = stimuli.BlankScreen()
wm = stimuli.TextLine('Waiting for scanner sync (or press \'t\')')
fs = stimuli.FixCross()

events = PriorityQueue()  # all stimuli will be queued here

# load stimuli

mapsounds = dict()
mapspeech = dict()
maptext = dict()
mappictures = dict()
mapvideos = dict()

for listfile in sys.argv[1:]:
    stimlist = csv.reader(io.open(listfile, 'r', encoding='utf-8'))
Exemplo n.º 22
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
A very short example experiment in 16 lines of pure code.
Participants have to indicate the parity of digits by pressing 
the left arrow key for odd and the right arrow key for even numbers.
"""

from expyriment import control, stimuli, design, misc

digit_list = [1, 2, 3, 4, 6, 7, 8, 9] * 12
design.randomize.shuffle_list(digit_list)

exp = control.initialize()
exp.data_variable_names = ["digit", "btn", "rt", "error"]

control.start(exp)

for digit in digit_list:
    target = stimuli.TextLine(text=str(digit), text_size=80)
    exp.clock.wait(500 - stimuli.FixCross().present() - target.preload())
    target.present()
    button, rt = exp.keyboard.wait(
        [misc.constants.K_LEFT, misc.constants.K_RIGHT])
    error = (button == misc.constants.K_LEFT) == digit % 2
    if error: stimuli.Tone(duration=200, frequency=2000).play()
    exp.data.add([digit, button, rt, int(error)])
    exp.clock.wait(1000 - stimuli.BlankScreen().present() - target.unload())

control.end(goodbye_text="Thank you very much...", goodbye_delay=2000)
Exemplo n.º 23
0
    for shape in ['diamond', 'square']:
        for number in [2, 3]:
            trial = design.Trial()
            trial.set_factor('block', 'mixed')
            trial.set_factor('task', task)
            trial.set_factor('shape', shape)
            trial.set_factor('number_of_circles', number)
            pngname = os.path.join(
                STIM_DIR, '{}_{}_{}_circles.png'.format(task, shape, number))
            trial.add_stimulus(stimuli.Picture(pngname))
            mixed_block.add_trial(trial)
mixed_block.shuffle_trials()

BLOCKS = [pure_shape_block, pure_filling_block, mixed_block]

blankscreen = stimuli.BlankScreen()
sex_question = stimuli.TextScreen(
    "One last question...",
    heading_size=40,
    text="What is your biological sex? Press M for male and F for female.")
training_instructions = stimuli.TextScreen("Instructions:",
                                           heading_size=40,
                                           text=TRAINING_INSTRUCTIONS)
reminder_if_incorrect_response = stimuli.TextScreen(
    "Your response was incorrect. Instructions reminder:",
    heading_size=40,
    text=REMINDER_INSTRUCTIONS)
experiment_instructions = stimuli.TextScreen(
    "So, you're all set for the experiment! Instructions:",
    heading_size=40,
    text=EXPERIMENT_INSTRUCTIONS)
Exemplo n.º 24
0
exp = design.Experiment(name="Recall")
control.initialize(exp)

StimList = pd.read_hdf(filename,
                       key='StimLists/StimListRec_Set%d' % run,
                       mode='r')

#   creating most elements on screen
fix = stimuli.Circle(3,
                     colour=None,
                     line_width=None,
                     position=None,
                     anti_aliasing=None)
pos = [(-300, 0), (300, 0), (0, 0)]
rect_b = stimuli.Rectangle((80, 80), colour=(255, 255, 255), position=pos[2])
blank = stimuli.BlankScreen()

c1 = stimuli.BlankScreen()
blank.plot(c1)
c1.preload()
c2 = stimuli.BlankScreen()
fix.plot(c2)
c2.preload()
c3 = stimuli.BlankScreen()
fix.plot(c3)
rect_b.plot(c3)
c3.preload()

txt_input = io.TextInput("")

# DESIGN
Exemplo n.º 25
0
def _font_viewer(exp):
    all_fonts = expyriment.misc.list_fonts().keys()

    def info_screen():
        stimuli.TextScreen(heading="Expyriment Font Viewer",
                           text="""
arrow keys left/right -- Switch font type
arrow keys up/down    -- Switch font size
                  i   -- Switch italic
                  b   -- Switch bold
                  c   -- Change text
                  h   -- Help
               return -- Quit


                 [Touch screen]
click left/right side --  Switch font type
click up/down side    --  Switch font size
click center          --  Quit
               """,
                           text_font="freemono",
                           text_bold=True,
                           text_justification=0).present()
        exp.keyboard.wait()

    default_text = u"""The quick brown fox jumps over the lazy dog.
ABCDEFGHIJKLMNOPQRSTUVWXYZ ÄÖÜ
abcdefghijklmnopqrstuvwxyz äöü
1234567890.:,;ßéèê(*!?')"""
    text = default_text
    size = 14
    font_id = 0
    italic = False
    bold = False
    quest = io.TextInput(
        message="Please enter text: (Keep empty for default text)", length=35)
    mouse = io.Mouse(show_cursor=True)

    bs = (exp.screen.size[0] / 3.5, exp.screen.size[1] / 3.5)

    # rects center, left, right, top, button]
    cl = (20, 20, 20)
    rects = [
        stimuli.Rectangle(size=bs, position=[0, 0], colour=cl),
        stimuli.Rectangle(size=bs,
                          position=[(bs[0] - exp.screen.size[0]) / 2.2, 0],
                          colour=cl),
        stimuli.Rectangle(size=bs,
                          position=[(exp.screen.size[0] - bs[0]) / 2.2, 0],
                          colour=cl),
        stimuli.Rectangle(size=bs,
                          position=[0, (bs[1] - exp.screen.size[1]) / 2.2],
                          colour=cl),
        stimuli.Rectangle(size=bs,
                          position=[0, (exp.screen.size[1] - bs[1]) / 2.2],
                          colour=cl)
    ]
    rect_key_mapping = [
        constants.K_RETURN, constants.K_LEFT, constants.K_RIGHT,
        constants.K_UP, constants.K_DOWN
    ]

    info_screen()
    while True:
        font_str = all_fonts[font_id]
        font_description = "font '{0}', size {1}".format(font_str, size)
        if italic:
            font_description += ", italic"
        if bold:
            font_description += ", bold"

        canvas = stimuli.BlankScreen()
        for r in rects:
            r.plot(canvas)
        try:
            stimuli.TextScreen(heading=font_description,
                               text=text,
                               text_font=font_str,
                               text_size=size,
                               text_justification=0,
                               text_italic=italic,
                               text_bold=bold,
                               text_colour=(255, 255, 255)).plot(canvas)
        except:
            stimuli.TextLine(
                text="Sorry, I can't display the text with " +
                "{0}".format(font_description),
                text_colour=constants.C_EXPYRIMENT_ORANGE).plot(canvas)
        canvas.present()
        mouse.clear()
        exp.keyboard.clear()
        while True:
            key = exp.keyboard.check()
            if mouse.get_last_button_down_event() is not None:
                for cnt, r in enumerate(rects):
                    if r.overlapping_with_position(mouse.position):
                        key = rect_key_mapping[cnt]
                        break
            if key is not None:
                break

        if (key == constants.K_RETURN):
            break
        elif key == constants.K_UP:
            size += 2
        elif key == constants.K_DOWN:
            size -= 2
        elif key == constants.K_LEFT:
            font_id -= 1
            if font_id < 0:
                font_id = len(all_fonts) - 1
        elif key == constants.K_RIGHT:
            font_id += 1
            if font_id >= len(all_fonts):
                font_id = 0
        elif key == constants.K_i:
            italic = not (italic)
        elif key == constants.K_b:
            bold = not (bold)
        elif key == constants.K_c:
            text = quest.get()
            if len(text) <= 0:
                text = default_text
        else:
            info_screen()
    mouse.hide_cursor()
Exemplo n.º 26
0
    def run_experiment(self):
        # define headers for expyriment log file output table (we currently don't use it,
        # but if we want - we can improve it and use it if we want
        self.exp.data_variable_names = ["time", "location", "direction", "trialType", "response", "rt"\
                                        ,"is success", "is practice", "blockType", "order"]

        currentTrailsNumber = self.test_trials_number;
        if self.is_practice:
            currentTrailsNumber = self.practice_trials_number;
        for trial_index in range(0, currentTrailsNumber):
            canvas = stimuli.BlankScreen()

            time_delay = 0

            # plot cross on canvas
            cross = stimuli.FixCross((50, 50), (0, 0), 5)
            time_delay += cross.plot(canvas)

            # plot arrow on canvas
            picture_arrow = stimuli.Picture(self.direction_file_converter[self.directions[trial_index]] \
                                            , position=self.locations_converter[self.locations[trial_index]])
            time_delay += picture_arrow.preload()
            time_delay += picture_arrow.plot(canvas)

            # show canvas
            time_delay += canvas.present();

            # send trigger to LSL with arrow details
            utils.push_sample_current_time(self.outlet, ["stimulus_task_stroop_type_arrow_location_" + ("u" if "up" in self.directions[trial_index] else "d") \
                                    + "_direction_"  + ("u" if "up" in self.locations[trial_index] else "d")])

            # wait for subject's response. Wait only for "duration" time
            key, rt = self.game_controller.wait_press(self.possible_joystick_buttons, self.duration,\
                                                      process_control_events=False)

            # we get here is subjects responded or of duration of stimulus ended
            if key != None: # subject responded and stimulus duration hasn't ended
                utils.push_sample_current_time(self.outlet, ["keyPressed_task_stroop_key_" + str(key)])
                self.exp.clock.wait(self.duration - rt) # wait the rest of the stimulus duration before going on

                # we get here when stimulus duration has ended (and subject responded)
                time_delay += self.paint_cross();
                self.exp.clock.wait(
                    self.isi - time_delay)  # wait for the ISI before going on

            else:
                # we get here if subject hasn't responded but stimulus duration ended - so we clean the screen
                time_delay += self.paint_cross();

                key = None;
                # we wait for subject to respond (but only for the ISI duration)
                key, rt = self.game_controller.wait_press(self.possible_joystick_buttons, self.isi - time_delay,
                                                          process_control_events=False)
                if key != None: # we get here if subject has responded - so we need to wait for the rest of
                                # the ISI
                    self.exp.clock.wait(
                        self.isi - rt - time_delay)  # wait the rest of the ISI before going on

                utils.push_sample_current_time(self.outlet, ["keyPressed_task_stroop_key_" + str(key)])
            self.save_trial_data(key, rt, trial_index)

        self.show_feedback_if_needed()
expyriment.design.defaults.experiment_background_colour = BACKGROUND_COLOR
exp = expyriment.design.Experiment(name="Localizer",
                                   background_colour=BACKGROUND_COLOR,
                                   foreground_colour=TEXT_COLOR,
                                   text_size=TEXT_SIZE,
                                   text_font=TEXT_FONT)
#expyriment.control.defaults.open_gl=1
expyriment.misc.add_fonts('fonts')
expyriment.control.initialize(exp)
#expyriment.control.defaults.quit_key = expyriment.misc.constants.K_q
#expyriment.control.defaults.fast_quit = True
#exp.background_colour = BACKGROUND_COLOR
exp._screen_colour = BACKGROUND_COLOR

kb = expyriment.io.Keyboard()
bs = stimuli.BlankScreen(colour=BACKGROUND_COLOR)
fs = stimuli.FixCross(size=(25, 25), line_width=3, colour=TEXT_COLOR)

##############################
# START PROTOCOL

#time to display the message of Preparing expyriment, otherwise it can be very short
#and we don't see what it is exactly
exp.clock.wait(800)

#CALIBRATION
if not (calibration is None):
    calibrage = "Nous allons faire un calibrage"
    calibration = stimuli.TextLine(calibrage,
                                   text_font=TEXT_FONT,
                                   text_size=TEXT_SIZE,
Exemplo n.º 28
0
control.initialize(exp)
control.start(exp, auto_create_subject_id=True, skip_ready_screen=True)

nPict = 0
for nCard in presentationOrder:
    m._matrix.item(nCard).setPicture(picturesExamplesFolder +
                                     picturesExamples[nPict])
    nPict += 1

mouse = io.Mouse()  # Create Mouse instance
mouse.set_logging(True)  # Log mouse
mouse.hide_cursor(True, True)  # Hide cursor

setCursor(arrow)

bs = stimuli.BlankScreen(bgColor)  # Create blank screen
m.plotDefault(bs, True)  # Draw default grid

exp.clock.wait(shortRest)

exp.add_experiment_info(['Block {} - Presentation'.format(0)
                         ])  # Add listPictures
exp.add_experiment_info(presentationOrder)  # Add listPictures

instructions = stimuli.TextLine(
    ' PRESENTATION ',
    position=(0, -windowSize[1] / float(2) +
              (2 * m.gap + cardSize[1]) / float(2)),
    text_font=None,
    text_size=textSize,
    text_bold=None,
Exemplo n.º 29
0
Start Training
'''
control.start(subject_id=45)

# Add variable header to data_file; can't be done before control.start
exp._data.add_variable_names(
    ["Trial", "clef", "key", "Expected", "Type_response", "RT"])

# iRun indexes the Notes array; when all notes are shown and nTrails remain, this index is set to 0 and runs again
iRun = 0
'''
Trial function
'''
for iTrial in range(0, setup.nTrials):

    stimuli.BlankScreen().present(clear=True, update=False)

    piano.Canvas.present(clear=False, update=False)

    # Present empty music sheet
    musicsheet[Notes[iRun].clef].Field.present(clear=False, update=True)

    # if Note needs extra help lines they need to be added first
    musicsheet[Notes[iRun].clef].add_helplines(Notes[iRun])

    # if Note has prefix, add it to screen
    musicsheet[Notes[iRun].clef].add_prefix(Notes[iRun])

    # Present note, prefix and lines
    Notes[iRun].stimuli.present(clear=False, update=True)
Exemplo n.º 30
0
from expyriment import stimuli, control, design, io, misc

from config import windowMode, windowSize, restBGColor, restCrossColor, restCrossSize, restCrossThickness

control.defaults.window_mode = windowMode
control.defaults.window_size = windowSize

exp = design.Experiment('Rest')  # Save experiment name
control.initialize(exp)
control.start(exp, auto_create_subject_id=True, skip_ready_screen=True)
bs = stimuli.BlankScreen(restBGColor)  # Create blank screen
cross = stimuli.FixCross(size=restCrossSize,
                         colour=restCrossColor,
                         line_width=restCrossThickness)  # Create cross
cross.plot(bs)
kb = io.Keyboard()
bs.present()

kb.wait(keys=misc.constants.K_q)