def line_bisection_task(line_length, position):
    # make button
    button = stimuli.Rectangle(size=(40, 20),
                               position=(exp.screen.size[0] / 2 - 25,
                                         15 - exp.screen.size[1] / 2))
    button_text = stimuli.TextLine(text="ok",
                                   position=button.position,
                                   text_colour=misc.constants.C_WHITE)
    mark_position = None
    while True:
        canvas = stimuli.BlankScreen()
        line = stimuli.Rectangle(size=(line_length, 3),
                                 position=position,
                                 colour=misc.constants.C_BLACK)
        line.plot(canvas)
        if mark_position is not None:
            # plot button and mark line on canvas
            button.plot(canvas)
            button_text.plot(canvas)
            markline = stimuli.Rectangle(size=(1, 25),
                                         position=(mark_position,
                                                   line.position[1]),
                                         colour=misc.constants.C_RED)
            markline.plot(canvas)
        # present stimulus
        canvas.present()
        # wait for mouse or touch screen response
        _id, pos, _rt = exp.mouse.wait_press()
        # process clicked position position
        if abs(pos[1]-line.position[1])<=50 and\
                    abs(pos[0]-line.position[0])<=line_length/2:
            mark_position = pos[0]
        else:
            if button.overlapping_with_position(pos):  # is button pressed
                return mark_position - line.position[0]
Пример #2
0
 def prepare_button_boxes(self, labels):
     buttons = []
     for i, lb in enumerate(labels):
         width, height = self.screen.window_size
         size = (width / len(labels),
                 self._unit(self.config.get('APPEARANCE', 'button_height')))
         pos = (int(size[0] * (i - len(labels) / 2.0 + 0.5)),
                -(height - size[1]) / 2)
         btn = stimuli.Rectangle(size=size,
                                 position=pos,
                                 colour=self._colours(
                                     self.config.get(
                                         'APPEARANCE',
                                         'button_background_colour')))
         stimuli.Rectangle(
             size=size,
             line_width=5,
             colour=self._colours(
                 self.config.get('APPEARANCE',
                                 'button_border_colour'))).plot(btn)
         text = stimuli.TextLine(text=lb,
                                 text_colour=self._colours(
                                     self.config.get(
                                         'APPEARANCE',
                                         'button_text_colour')))
         text.plot(btn)
         btn.label = lb
         btn.preload()
         buttons.append(btn)
     return (buttons)
Пример #3
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
Пример #4
0
    def paint_line(self, y_position, canvas, mark_position):

        line = stimuli.Rectangle(size=(self.line_length, 3),
                                 position=(self.position_x, y_position),
                                 colour=misc.constants.C_BLACK)
        line.plot(canvas)
        if mark_position is not None:

            markline = stimuli.Rectangle(
                size=(self.marker_width, self.marker_height),
                position=(mark_position,
                          line.position[1] + self.marker_distance_from_scale),
                colour=misc.constants.C_RED)
            markline.plot(canvas)
Пример #5
0
    def __init__(self, key_mapping):
        self.name = key_mapping['key']
        self.kid = key_mapping['kid']

        # key boarder rectangle parameters
        keys_to_c1 = key_mapping['keyboard_pos']

        x_rect = keys_to_c1 * 20

        self.white_key = key_mapping['white_key']

        if self.white_key:
            #size
            height_rect = 60
            width_rect = 20

            #position
            y_rect = 0
            position_rect = [x_rect, y_rect]

            #colour
            colour_rect = constants.C_WHITE

        else:
            height_rect = 40
            width_rect = 15

            #position
            y_rect = 10
            position_rect = [x_rect, y_rect]

            #colour
            colour_rect = constants.C_BLACK

        self.Border = stimuli.Rectangle([width_rect, height_rect],
                                        position=position_rect,
                                        colour=constants.C_BLACK)
        self.Key = stimuli.Rectangle([width_rect - 3, height_rect - 3],
                                     position=position_rect,
                                     colour=colour_rect)
        self.KeyGreen = stimuli.Rectangle([width_rect - 3, height_rect - 3],
                                          position=position_rect,
                                          colour=constants.C_GREEN)

        #text parameters
        self.text_title = ""
        y_text = 50
        self.text_position = [x_rect, y_text]
Пример #6
0
 def __init__(self, size, color=cardColor):
     self._size = size
     self._stimuli = (stimuli.Picture(templatePicture, position=None),
                      stimuli.Rectangle(size,
                                        colour=color,
                                        line_width=None,
                                        position=None))
Пример #7
0
    def rect(self, x, y, w, h, fill=False, color=None):
        """See openexp._canvas.legacy"""

        if fill:
            if color != None: color = self.color(color)
            else: color = self.fgcolor
            # The position of the stimulus is the center, not the top-left
            pos = c2p((x + w / 2, y + h / 2))
            #stim = stimuli.Rectangle(size=(w,h), position=pos, colour= \
            #	color, anti_aliasing=self.aa)
            # Anti-aliasing gone as of 0.6.1
            stim = stimuli.Rectangle(size=(w,h), position=pos, colour= \
             color)
            self.add_stim(stim)

        # Unfilled shapes are drawn using a polygon
        else:
            # For now, do not use a polygon, because it's really slow when
            # rendering, which is particularly problematic for forms.
            # self.polygon( [(x,y), (x+w,y), (x+w,y+w), (x,y+w), (x,y)], \
            # color=color)
            self.line(x, y, x + w, y, color=color)
            self.line(x + w, y, x + w, y + h, color=color)
            self.line(x, y + h, x + w, y + h, color=color)
            self.line(x, y, x, y + h, color=color)
Пример #8
0
 def setPicture(self, value, scale=True):
     self._stimuli = (stimuli.Picture(value, position=self.position),
                      stimuli.Rectangle(self.size,
                                        colour=constants.C_WHITE,
                                        line_width=None,
                                        position=self.position))
     if scale:
         self._stimuli[0].scale(self.size[0] / float(300))
Пример #9
0
 def update_line(self, y_position, mark_position):
     delay = 0
     markline = stimuli.Rectangle(
         size=(self.marker_width, self.marker_height),
         position=(mark_position,
                   y_position + self.marker_distance_from_scale),
         colour=misc.constants.C_RED)
     delay += markline.plot(self.canvas)
     cover = stimuli.Rectangle(
         size=(self.marker_width, self.marker_height),
         position=(self.old_marks_positions[self.line_index],
                   y_position + self.marker_distance_from_scale),
         colour=misc.constants.C_GREY)
     delay += cover.plot(self.canvas)
     delay += self.canvas.present()
     self.old_marks_positions[self.line_index] = mark_position
     return delay
Пример #10
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
Пример #11
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
Пример #13
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)
Пример #14
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"
Пример #15
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"
Пример #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'
Пример #17
0
def _clickable_numeric_input(title, start_at, scale=1.0):
    positions = [(100*scale, 0),
                 (-100*scale, 0),
                 (300*scale, -200*scale)]
    btn_colour = misc.constants.C_DARKGREY
    btn_size = (int(70*scale), int(70*scale))
    btn_text_colour = (0, 0, 0)
    pos_title = (0, 100*scale)
    title_text_colour = misc.constants.C_GREY
    number_text_colour = misc.constants.C_GREY

    buttons = [stimuli.Rectangle(size=btn_size, colour=btn_colour, position=pos)
               for pos in positions]

    plus_width = 2*scale if expyriment_version[0] == 7 else 3*scale
    minus_width = 3*scale

    labels = [
        stimuli.TextLine(text='OK', text_size=int(30*scale),
                         position=positions[2], text_colour=btn_text_colour),
        stimuli.FixCross(size=(40*scale, 40*scale),
                         position=positions[0], colour=btn_text_colour,
                         line_width=plus_width),
        stimuli.FixCross(size=(40*scale, 3*scale),
                         position=positions[1], colour=btn_text_colour,
                         line_width=minus_width),
        stimuli.TextLine(title, text_size=int(30*scale),
                         text_colour=title_text_colour, position=pos_title)
    ]

    number = int(start_at)

    while True:
        current_num = stimuli.TextLine(text=str(number),
                                       text_size=int(40*scale),
                                       text_colour=number_text_colour)
        button_box = io.TouchScreenButtonBox(buttons, labels+[current_num])
        button_box.show()
        key = button_box.wait()[0]
        if key == buttons[0]:
            number = number + 1
        elif key == buttons[1]:
            number = max(number - 1, 1)
        elif key == buttons[2]:
            return(number)
    return(number)
Пример #18
0
	def rect(self, x, y, w, h):

		if self.fill:
			# The position of the stimulus is the center, not the top-left
			pos = self.to_xy((x+w/2,y+h/2))
			stim = stimuli.Rectangle(size=(w,h), position=pos,
				colour=self.color.backend_color)
			self.add_stim(stim)
		# Unfilled shapes are drawn using a polygon
		else:
			# For now, do not use a polygon, because it's really slow when
			# rendering, which is particularly problematic for forms.
			# self.polygon( [(x,y), (x+w,y), (x+w,y+w), (x,y+w), (x,y)], \
			# color=color)
			self.line(x, y, x+w, y)
			self.line(x+w, y, x+w, y+h)
			self.line(x, y+h, x+w, y+h)
			self.line(x, y, x, y+h)
Пример #19
0
def createBlock(COLORS, blockname,
                exp):  # i/p list 'COLORS' and RETURNS a stimuli block 'b'
    #for level in ["LEVEL 1"]:#,"LEVEL 2"]:
    #print(level)
    b = design.Block(name=blockname)
    b.set_factor("level", blockname)  #blockname as level
    for color in COLORS:
        t = design.Trial()
        t.set_factor("COLOR", color[0])
        #print(type(color[1]))
        #print(color[0])
        s = stimuli.Rectangle([200, 200], position=[0, 0], colour=color[1])
        t.add_stimulus(s)
        b.add_trial(t, copies=1)
    #b.shuffle_trials() #never use this line
    #print(b.trials)
    exp.add_block(b)
    return b  # b IS AN EXPERIMENT TRIAL <INPUT LIST 'COLORS' is coverted to Experiment object>
Пример #20
0
	def rect(self, x, y, w, h, fill=False, color=None, penwidth=None):

		if fill:
			if color != None: color = self.color(color)
			else: color = self.fgcolor
			# The position of the stimulus is the center, not the top-left
			pos = c2p((x+w/2,y+h/2))
			stim = stimuli.Rectangle(size=(w,h), position=pos,
				colour=color)
			self.add_stim(stim)
		# Unfilled shapes are drawn using a polygon
		else:
			# For now, do not use a polygon, because it's really slow when
			# rendering, which is particularly problematic for forms.
			# self.polygon( [(x,y), (x+w,y), (x+w,y+w), (x,y+w), (x,y)], \
			# color=color)
			self.line(x, y, x+w, y, color=color, penwidth=penwidth)
			self.line(x+w, y, x+w, y+h, color=color, penwidth=penwidth)
			self.line(x, y+h, x+w, y+h, color=color, penwidth=penwidth)
			self.line(x, y, x, y+h, color=color, penwidth=penwidth)
Пример #21
0
    def prepare_trial(self, block, item, id):
        trial = design.Trial()
        if id:
            trial._id = id
        bx = block.get_factor('num_boxes')**(0.5)
        sz = self.canvas_size / bx
        ctr = self.canvas_size / 2

        for k in item:
            if k == 'C':
                trial.set_factor(k, self.exp._invert_colour(item[k]))
            else:
                trial.set_factor(k, item[k])

        s = stimuli.Rectangle([sz, sz],
                              position=[(item['P'] % bx + 0.5) * sz - ctr,
                                        (item['P'] // bx + 0.5) * sz - ctr],
                              colour=item['C'])
        trial.add_stimulus(s)

        return (trial)
Пример #22
0
def design_experiment(exp, positions, colors, pairings):
    """Designs a Simon Task experiment."""

    for pair_name, pairing in pairings.items():

        b = design.Block()
        b.set_factor("pairing", pair_name)

        for pos_name, position in positions.items():
            for color_name, color in colors.items():

                t = design.Trial()
                t.set_factor("position", pos_name)
                t.set_factor("color", color_name)
                s = stimuli.Rectangle((50, 50),
                                      position=position,
                                      colour=color)
                t.add_stimulus(s)
                b.add_trial(t, copies=2)

        b.shuffle_trials()
        exp.add_block(b)

    return exp
        # wait for mouse or touch screen response
        _id, pos, _rt = exp.mouse.wait_press()
        # process clicked position position
        if abs(pos[1]-line.position[1])<=50 and\
                    abs(pos[0]-line.position[0])<=line_length/2:
            mark_position = pos[0]
        else:
            if button.overlapping_with_position(pos):  # is button pressed
                return mark_position - line.position[0]


### init ###
exp = control.initialize()

# create touch button box
buttonA = stimuli.Rectangle(size=(80, 40), position=(-60, 0))
buttonB = stimuli.Rectangle(size=(80, 40), position=(60, 0))
textA = stimuli.TextLine(text="quit",
                         position=buttonA.position,
                         text_colour=misc.constants.C_WHITE)
textB = stimuli.TextLine(text="next",
                         position=buttonB.position,
                         text_colour=misc.constants.C_WHITE)
touchButtonBox = io.TouchScreenButtonBox(button_fields=[buttonA, buttonB],
                                         stimuli=[textA, textB])
### start ###
control.start(exp)
exp.mouse.show_cursor()

# trial loop
while True:
Пример #24
0
#   initialize the experiment
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("")
Пример #25
0
    def _test1():
        info = """This will test the visual stimulus presentation timing specifics of your system.
During the test, you will see two squares on the screen.
After the test, you will be asked to indicate which (if any) of those two squares were flickering.

[Press RETURN to continue]"""
        # TODO test very slow quit
        text = stimuli.TextScreen("Visual stimulus presentation test", info)
        #y = []
        #for x in [16, 32, 48, 64]:
        #    y.extend([x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, ])
        #graph1 = _make_graph(range(60), y, [0, 255, 0])
        #y = range(80)
        #graph2 = _make_graph(range(60), y, [255, 0, 0])
        #graph1.position = (-200, -100)
        #graph2.position = (200, -100)
        text.present()
        #graph1.present(clear=False, update=False)
        #graph2.present(clear=False)
        exp.keyboard.wait([constants.K_RETURN])

        message = stimuli.TextScreen("Running", "Please wait...")
        message.present()
        message.present()
        message.present()
        c1 = stimuli.Canvas((400, 400))
        c2 = stimuli.Canvas((400, 400))
        c3 = stimuli.Canvas((400, 400))
        frame1 = stimuli.Rectangle((100, 100), position=(-100, 0))
        frame2 = stimuli.Rectangle((100, 100), position=(100, 0))
        bg = stimuli.Rectangle((90, 90), colour=exp.background_colour)
        bg.plot(frame1)
        bg.plot(frame2)
        frame1.plot(c1)
        frame2.plot(c2)
        frame1.plot(c3)
        frame2.plot(c3)
        c1.preload()
        c2.preload()
        c3.preload()
        c1.present(clear=False)
        c2.present(clear=False)
        c3.present(clear=False)

        s1 = stimuli.Circle(1, colour=exp.background_colour)
        s2 = stimuli.Circle(1, colour=exp.background_colour)
        s1.preload()
        s2.preload()
        todo_time = range(0, 60) * 3
        randomize.shuffle_list(todo_time)
        actual_time = []
        for x in todo_time:
            s1.present(clear=False)
            start = get_time()
            exp.clock.wait(x)
            s2.present(clear=False)
            actual_time.append((get_time() - start) * 1000)
            exp.clock.wait(expyriment.design.randomize.rand_int(30, 60))

        # determine refresh_rate
        tmp = []
        for _x in range(100):
            start = get_time()
            s1.present(clear=False)
            tmp.append(get_time() - start)
            start = get_time()
            s2.present(clear=False)
            tmp.append(get_time() - start)
        refresh_rate = 1000 / (statistics.mean(tmp) * 1000)

        #text = stimuli.TextScreen("Results", "[Press RETURN to continue]")
        #graph = _make_graph(todo_time, actual_time, [150, 150, 150])
        #graph.position = (0, -100)
        #text.present(update=False)
        #graph.present(clear=False)
        #exp.keyboard.wait([constants.K_RETURN])
        #text = stimuli.TextScreen(
        #    "Which picture looks most similar to the results?",
        #    "[Press LEFT or RIGHT arrow key]")
        #y = []
        #for x in [16, 32, 48, 64]:
        #    y.extend([x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, ])
        #graph1 = _make_graph(range(60), y, [0, 255, 0])
        #y = range(80)
        #graph2 = _make_graph(range(60), y, [255, 0, 0])
        #graph1.position = (-200, -100)
        #graph2.position = (200, -100)
        #text.present(update=False)
        #graph1.present(clear=False, update=False)
        #graph2.present(clear=False)
        #key, _rt = exp.keyboard.wait([constants.K_LEFT,
        #                             constants.K_RIGHT])
        #if key == constants.K_LEFT:
        #    response1 = "Steps"
        #elif key == constants.K_RIGHT:
        #    response1 = "Line"
        #else:
        #    response1 = None

        # show histogram of presentation delays
        def expected_delay(presentation_time, refresh_rate):
            refresh_time = 1000.0 / refresh_rate
            return refresh_time - (presentation_time % refresh_time)

        # delay = map(lambda x: x[1]- x[0], zip(todo_time, actual_time))
        unexplained_delay = map(
            lambda x: x[1] - x[0] - expected_delay(x[0], refresh_rate),
            zip(todo_time, actual_time))
        hist, hist_str = _histogram(unexplained_delay)
        inaccuracies = []
        delayed_presentations = 0
        for key in hist.keys():
            inaccuracies.extend([key % (1000 / refresh_rate)] * hist[key])
            if key != 0:
                delayed_presentations += hist[key]
        inaccuracy = int(round(sum(inaccuracies) / float(len(inaccuracies))))
        delayed = round(100 * delayed_presentations / 180.0, 2)

        text = stimuli.TextScreen(
            "How many of the two squares were flickering?",
            "[Press 0, 1 or 2]")
        text.present()
        key, _rt = exp.keyboard.wait(
            [constants.K_0, constants.K_1, constants.K_2])
        if key == constants.K_0:
            response = 0
        elif key == constants.K_1:
            response = 1
        elif key == constants.K_2:
            response = 2

        info = stimuli.TextScreen("Results", "")
        results1 = stimuli.TextScreen(
            "",
            "Estimated Screen Refresh Rate:     {0} Hz (~ every {1} ms)\n\n".
            format(int(round(refresh_rate)), int(1000.0 / refresh_rate)),
            text_font="freemono",
            text_size=16,
            text_bold=True,
            text_justification=0,
            position=(0, 40))
        results2 = stimuli.TextScreen(
            "",
            "Detected Framebuffer Pages:        {0}\n\n".format(response + 1),
            text_font="freemono",
            text_size=16,
            text_bold=True,
            text_justification=0,
            position=(0, 20))
        if inaccuracy != 0:
            results3_colour = [255, 0, 0]
        else:
            results3_colour = [0, 255, 0]
        results3 = stimuli.TextScreen(
            "",
            "Average Reporting Inaccuracy:      {0} ms\n\n".format(inaccuracy),
            text_font="freemono",
            text_size=16,
            text_bold=True,
            text_justification=0,
            text_colour=results3_colour,
            position=(0, -20))
        if delayed > 10:
            results4_colour = [255, 0, 0]
        elif 10 > delayed > 1:
            results4_colour = [255, 255, 0]
        else:
            results4_colour = [0, 255, 0]
        results4 = stimuli.TextScreen(
            "",
            "Unexplained Presentation Delays:   {0} %\n\n\n".format(delayed),
            text_font="freemono",
            text_size=16,
            text_bold=True,
            text_justification=0,
            text_colour=results4_colour,
            position=(0, -40))
        results5 = stimuli.TextScreen("",
                                      hist_str,
                                      text_font="freemono",
                                      text_size=16,
                                      text_bold=True,
                                      text_justification=0,
                                      position=(0, -100))
        results1.plot(info)
        results2.plot(info)
        results3.plot(info)
        results4.plot(info)
        results5.plot(info)
        info2 = stimuli.TextLine("[Press RETURN to continue]",
                                 position=(0, -160))
        info2.plot(info)
        info.present()
        exp.keyboard.wait([constants.K_RETURN])

        return todo_time, actual_time, refresh_rate, inaccuracy, delayed, response
Пример #26
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()
Пример #27
0
PERIOD = 500
TONE_DURATION = 100
SQUARE_DURATION = 100  # should be 6 frames with a video refresh rate at 60Hz

exp = design.Experiment(name="Cross-modal-timing-test")
#control.set_develop_mode(True)  # commented because we need fullscreen

control.defaults.open_gl = 2
control.defaults.audiosystem_buffer_size = 256
control.initialize(exp)

##

bs = stimuli.BlankScreen()
square_top = stimuli.Rectangle((400, 400), position=(0, 300))
tone = stimuli.Tone(TONE_DURATION, 440)

bs.preload()
square_top.preload()
tone.preload()

##
control.start(skip_ready_screen=True)
clock = misc.Clock()

exp.screen.clear()
bs.present(update=True)
nframe = 0
t1 = clock.time
while clock.time - t1 <= 1000:
Пример #28
0
control.defaults.open_gl = False  # switch off opengl to avoid screen refesh sync

exp = control.initialize()
control.start()

radius = 20
movement = [4, 8]
arena = (exp.screen.size[0] / 2 - radius, exp.screen.size[1] / 2 - radius)
dot = stimuli.Circle(radius=radius, colour=misc.constants.C_YELLOW)

stimuli.BlankScreen().present()

exp.clock.reset_stopwatch()
while exp.clock.stopwatch_time < 10000:
    erase = stimuli.Rectangle(size=dot.surface_size,
                              position=dot.position,
                              colour=exp.background_colour)
    dot.move(movement)
    if dot.position[0] > arena[0] or dot.position[0] < -1 * arena[0]:
        movement[0] = -1 * movement[0]
    if dot.position[1] > arena[1] or dot.position[1] < -1 * arena[1]:
        movement[1] = -1 * movement[1]

    erase.present(clear=False,
                  update=False)  # present but do not refesh screen
    dot.present(clear=False, update=True)  # present but do not refesh screen
    exp.screen.update_stimuli([dot, erase])  # refesh screen
    exp.keyboard.check()  # ensure that keyboard input is proccesed
    # to quit experiment with ESC
    exp.clock.wait(1)
Пример #29
0
experimentName = arguments[0]
subjectName = arguments[1]

exp = design.Experiment(experimentName)  # Save experiment name
exp.add_experiment_info(['Subject: '])  # Save Subject Code
exp.add_experiment_info([subjectName])  # Save Subject Code

# Save time, nblocks, position, correctAnswer, RT
exp.add_data_variable_names(['Time', 'NBlock', 'Picture', 'Answers', 'RT'])

m = LdMatrix(matrixSize, windowSize)  # Create Matrix

instructionRectangle = stimuli.Rectangle(
    size=(windowSize[0], m.gap * 2 + cardSize[1]),
    position=(0, -windowSize[1] / float(2) +
              (2 * m.gap + cardSize[1]) / float(2)),
    colour=constants.C_DARKGREY)

picturesExamples = np.random.permutation(picturesExamples)

presentationOrder = newRandomPresentation()
presentationOrder = presentationOrder[0:3]

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])
Пример #30
0
##################### INITIALISATION DES PARAMETRES #####################

key_m = 59
key_q = 97
response_keys = [key_m, key_q]

nb_trial = 100
fixcross = stimuli.FixCross(size=(20, 20), line_width=3)
fixcross.preload()
Blankscreen = stimuli.BlankScreen()

# Paramètres d'affichage du stimulus:
square_dist = 200
square_size = [20, 20]
left_square = stimuli.Rectangle(square_size, position=[-square_dist, 0])
left_square.preload()
right_square = stimuli.Rectangle(square_size, position=[square_dist, 0])
right_square.preload()
square_displaytime = 100

# Définition des stimuli et paramètres de réponse utilisateur
trial_left = ["left", key_q, left_square, 0]
trial_right = ["right", key_m, right_square, 0]

wait_duration = 1000

##################### INSTRUCTIONS #####################

instructions = """Dans l'expérience suivante, un carré gris va apparaître dans la partie droite ou gauche de votre champ visuel, \n\
de part ou d'autre d'une croix centrale. \n\