Esempio n. 1
0
 def make_stimuli(self):
     super(ManBar, self).make_stimuli()
     color = (self.parameters.brightness, self.parameters.brightness, self.parameters.brightness, 1.0)
     self.target = Target2D(anchor='center',
                            anti_aliasing=self.parameters.antialiase,
                            color=color,
                            on=False)
     self.tp = self.target.parameters # synonym
     self.tp.color = color
     self.tip = Target2D(size=(5, 1),
                         anchor='center',
                         anti_aliasing=self.parameters.antialiase,
                         color=(1.0, 0.0, 0.0, 1.0),
                         on=False)
     self.tipp = self.tip.parameters
     self.fixationspot = FixationSpot(anchor='center',
                                              color=(1.0, 0.0, 0.0, 0.0),
                                              size=(5, 5),
                                              on=False)
     self.fp = self.fixationspot.parameters
     self.centerspot = FixationSpot(anchor='center',
                                              color=(0.0, 1.0, 0.0, 0.0),
                                              size=(3, 3),
                                              on=False)
     self.cp = self.centerspot.parameters
     self.complete_stimuli = (self.background, self.target, self.tip, self.fixationspot, self.centerspot) + self.info
     self.essential_stimuli = (self.background, self.target)
Esempio n. 2
0
    def make_stimuli(self):
        size = self.viewport.get_size()
        self.background = Target2D(position=(size[0] / 2, size[1] / 2),
                                   anchor='center',
                                   size=size,
                                   on=True)

        self.bgp = self.background.parameters  # synonym
        #set background color before real sweep
        bgb = self.parameters.bgbrightness  # get it for sweep Seque index 0
        self.bgp.color = bgb, bgb, bgb, 1.0  # set bg colour, do this now so it's correct for the pre-exp delay

        position = (self.viewport.xorig+self.viewport.deg2pix(self.parameters.xorigDeg), \
                    self.viewport.yorig+self.viewport.deg2pix(self.parameters.yorigDeg))

        self.parameters.gridsize = self.parameters.rfsize * self.parameters.gridmag

        self.gridcell = (self.parameters.gridsize / self.parameters.griddim[0],
                         self.parameters.gridsize / self.parameters.griddim[1])

        self.barsize = (self.gridcell[0] * self.parameters.widthmag,
                        self.gridcell[1] * self.parameters.heightmag)

        self.targetstimulus = Target2D(
            position=position,
            color=(0.0, 0.0, 0.0, 1.0),
            orientation=self.parameters.ori,
            anchor='center',
            size=(self.viewport.deg2pix(self.barsize[0]),
                  self.viewport.deg2pix(self.barsize[1])),
            on=False)
        self.fixationspot = FixationSpot(position=(self.viewport.xorig,
                                                   self.viewport.yorig),
                                         anchor='center',
                                         color=(1.0, 0.0, 0.0, 1.0),
                                         size=(50, 50),
                                         on=False)

        self.checkboard = CheckBoard(position = position,
                                     orientation = 0.0,
                                     anchor='center',
                                     size = (self.viewport.deg2pix(self.parameters.gridsize), \
                                             self.viewport.deg2pix(self.parameters.gridsize)),
                                     grid = self.parameters.griddim,
                                     drawline = False,
                                     cellcolor = self.parameters.cbcolormap,
                                     on = self.parameters.checkbdon)

        self.tsp = self.targetstimulus.parameters  # synonym
        self.fsp = self.fixationspot.parameters
        self.cbp = self.checkboard.parameters
        # last entry will be topmost layer in viewport
        self.stimuli = (self.background, self.checkboard, self.targetstimulus,
                        self.fixationspot)
Esempio n. 3
0
    def make_stimuli(self):
        size = self.viewport.get_size()
        self.background = Target2D(position=(size[0]/2, size[1]/2),
                                   anchor='center',
                                   size=size,
                                   on=True)

        self.bgp = self.background.parameters
        #set background color before real sweep
        bgb = self.parameters.bgbrightness
        self.bgp.color = bgb, bgb, bgb, 1.0
        
        nsinsamples = 1024
        self.grating = SinGrating2D(anchor='center',
                                    pedestal=self.parameters.ml,
                                    contrast=self.parameters.contrast,
                                    ignore_time=True,
                                    num_samples=nsinsamples,
                                    max_alpha=1.0,
                                    on=False)
        self.gp = self.grating.parameters
        
        nmasksamples = 1024
        radius = self.viewport.deg2pix(self.parameters.maskDiameterDeg) / 2.0
        self.gp.size = [radius * 2] * 2
        samplesperpix = nmasksamples / self.gp.size[0]
        self.grating_mask = Mask2D(function=self.parameters.mask,
                                   radius_parameter=radius*samplesperpix,
                                   num_samples=(nmasksamples,nmasksamples))
        self.gp.mask = self.grating_mask
        self.gmp = self.grating_mask.parameters
        self.stimuli = (self.background, self.grating)
Esempio n. 4
0
 def make_stimuli(self):
     size = self.viewport.get_size()
     #set background color before real sweep
     bgb = self.parameters.bgbrightness
     self.background = Target2D(position=(size[0]/2, size[1]/2),
                                anchor='center',
                                size=size,
                                color=(bgb, bgb, bgb, 1.0),
                                on=True)
     width = self.viewport.deg2pix(self.parameters.dotSquareWidth)
     self.randomdots = TextureDots(on=True,
                                  size=(int(width), int(width)),
                                  bgcolor=(0.5,0.5,0.5),
                                  num_dots=self.parameters.dotsNumber,
                                  dot_color=self.parameters.dotColor,
                                  seed=self.parameters.randomSeed,
                                  dot_size=self.parameters.dotSize,
                                  mask_on=False)
     self.rp = self.randomdots.parameters
     self.fixationspot = FixationSpot(anchor='center',
                                      color=(1.0, 0.0, 0.0, 0.0),
                                      size=(10, 10),
                                      on=False)
     self.fp = self.fixationspot.parameters
     self.stimuli = (self.background, self.randomdots, self.fixationspot)
Esempio n. 5
0
    def make_stimuli(self):
        self.p = self.parameters
        size = self.viewport.get_size()
        self.background = Target2D(position=(size[0]/2, size[1]/2),
                                   anchor='center',
                                   size=size,
                                   on=True)

        self.bgp = self.background.parameters # synonym
        #set background color before real sweep
        bgb = self.p.bgbrightness # get it for sweep table index 0
        self.bgp.color = bgb, bgb, bgb, 1.0 # set bg colour, do this now so it's correct for the pre-exp delay
        
        self.screenstring = 'screen (w, h, d) = (%.1f, %.1f, %.1f) cm' % \
                            (self.viewport.width_cm, self.viewport.height_cm, self.viewport.distance_cm)
        self.screentext = BitmapText(text=self.screenstring, color=(0.0, 1.0, 1.0, 1.0), on=False)
        self.stp = self.screentext.parameters

        self.squarelocktext = BitmapText(text='SQUARELOCK', color=(0.0, 1.0, 1.0, 1.0), on=False) # leave it off for now
        self.sltp = self.squarelocktext.parameters
        self.upperbar = Target2D(anchor='upperleft', anti_aliasing=self.p.antialiase, \
                                 color=(self.p.bgbrightness, self.p.bgbrightness, self.p.bgbrightness, 1.0), \
                                 on=False)
        self.upbp = self.upperbar.parameters
        self.lowerbar = Target2D(anchor='lowerleft', anti_aliasing=self.p.antialiase, \
                                 color=(self.p.bgbrightness, self.p.bgbrightness, self.p.bgbrightness, 1.0), \
                                 on=False)
        self.lwbp = self.lowerbar.parameters
        
        self.stimulusparamtext = BitmapText(color=(0.0, 1.0, 0.0, 1.0), on=False)
        self.sptp = self.stimulusparamtext.parameters

        self.viewportinfotext = BitmapText(text='Viewports in control: ', color=(0.0, 1.0, 1.0, 1.0), on=False)
        self.vitp = self.viewportinfotext.parameters

        self.lvpindicatortext = BitmapText(text='left', on=False)

        self.rvpindicatortext = BitmapText(text='right', on=False)
        
        self.viewport_indicators = (self.lvpindicatortext.parameters,self.rvpindicatortext.parameters)

        self.info = (self.upperbar, self.squarelocktext, self.viewportinfotext, self.screentext,
                     self.lvpindicatortext, self.rvpindicatortext,
                     self.lowerbar, self.stimulusparamtext)
 def define_stimuli(self):
     """
     Creates standard and deviant stimuli.          
     """
     # The stimului. This can be anything compatible with VisionEgg
     dev = FilledCircle(
         color=(0, 1.0, 0),
         position=[self.geometry[2] / 2, self.geometry[3] / 2],
         radius=100)
     std1 = Target2D(color=(0, 0, 1.0),
                     position=[self.geometry[2] / 2, self.geometry[3] / 2],
                     size=(200, 200))
     std2 = Target2D(color=(1.0, 0, 0),
                     position=[self.geometry[2] / 2, self.geometry[3] / 2],
                     size=(200, 200))
     #dev = Text(text='Deviant', font_size=72, position=(300, 200), anchor='center')
     #std1 = Text(text='Standard I', font_size=72, position=(300, 200), anchor='center')
     #std2 = Text(text='Standard II', font_size=72, position=(300, 200), anchor='center')
     return [std1, std2], [dev]
Esempio n. 7
0
    def make_stimuli(self):
        width = self.viewport.deg2pix(self.parameters.width)
        thickness = self.viewport.deg2pix(self.parameters.thickness)
        nonius_h_position = self.viewport.deg2pix(self.parameters.xorigDeg) + self.viewport.xorig ,\
                            self.viewport.deg2pix(self.parameters.yorigDeg) + self.viewport.yorig
        if self.parameters.direction == "up":
            v_position = -width / 2
        elif self.parameters.direction == "down":
            v_position = width / 2
        nonius_v_position = self.viewport.deg2pix(self.parameters.xorigDeg) + self.viewport.xorig ,\
                            self.viewport.deg2pix(self.parameters.yorigDeg) + self.viewport.yorig + v_position

        self.nonius_h = Target2D(position=nonius_h_position,
                                 anchor='center',
                                 size=(width, thickness),
                                 on=True)
        self.nonius_h.parameters.bgbrightness = (1.0, 1.0, 1.0, 1.0)
        self.nonius_v = Target2D(position=nonius_v_position,
                                 anchor='center',
                                 size=(thickness, width),
                                 on=True)
        self.nonius_v.parameters.bgbrightness = (1.0, 1.0, 1.0, 1.0)
        self.stimuli = [self.nonius_h, self.nonius_v]
Esempio n. 8
0
import Pyro
Pyro.config.PYRO_MOBILE_CODE = True
Pyro.config.PYRO_TRACELEVEL = 3
Pyro.config.PYRO_PICKLE_FORMAT = 1

from VisionEgg.PyroClient import PyroClient

from VisionEgg.Gratings import SinGrating2D
from VisionEgg.MoreStimuli import Target2D
from StimControl.LightStim.Core import DefaultScreen

dummy_screen = DefaultScreen(['control'])

grating = SinGrating2D()
target = Target2D()

client = PyroClient(server_hostname='localhost')
#quit_controller = client.get('quit_controller')
#time.sleep(5.0) # show for 5 seconds
#
#quit_controller.set_between_go_value(1)
#quit_controller.evaluate_now()
stimulus_pool = client.get('stimulus_pool')
stimulus_pool.add_stimulus(target)
stimulus_pool.add_stimulus(grating)
Esempio n. 9
0
    def __init_screen(self):
        ## create screen:
        if not self.fullscreen:
            os.environ['SDL_VIDEO_WINDOW_POS'] = '%d, %d' % (self.geometry[0],
                                                             self.geometry[1])
        self._screen = Screen(size=(self.geometry[2], self.geometry[3]),
                              fullscreen=self.fullscreen,
                              bgcolor=self.bg_color,
                              sync_swap=True)

        ## create letter box on top:
        self._ve_letterbox = Target2D(position=(self._centerPos[0],
                                                self.geometry[3] * (1 - 0.01) -
                                                self.letterbox_size[1] / 2.),
                                      size=(self.letterbox_size[0],
                                            self.letterbox_size[1]),
                                      color=self.phrase_color)
        self._ve_innerbox = Target2D(position=(self._centerPos[0],
                                               self.geometry[3] * (1 - 0.01) -
                                               self.letterbox_size[1] / 2.),
                                     size=(self.letterbox_size[0] - 6,
                                           self.letterbox_size[1] - 6),
                                     color=self.bg_color)

        self._current_letter_position = (self._centerPos[0],
                                         self.geometry[3] * (1 - 0.015) -
                                         self.letterbox_size[1] / 2.)
        self._ve_current_letter = Text(
            position=self._current_letter_position,
            text=(len(self._desired_letters[:1]) == 0 and " "
                  or self._desired_letters[:1]),
            font_size=self.font_size_current_letter,
            color=self.current_letter_color,
            anchor='center')

        self._ve_desired_letters = Text(
            position=(self._centerPos[0] + 5 + self.letterbox_size[0] / 2.,
                      self._current_letter_position[1]),
            text=(len(self._desired_letters[1:]) == 0 and " "
                  or self._desired_letters[1:]),
            font_size=self.font_size_phrase,
            color=self.phrase_color,
            anchor='left')

        self._ve_spelled_phrase = Text(
            position=(self._centerPos[0] - 5 - self.letterbox_size[0] / 2.,
                      self._current_letter_position[1]),
            text=(len(self._spelled_phrase) == 0 and " "
                  or self._spelled_phrase),
            font_size=self.font_size_phrase,
            color=self.phrase_color,
            anchor='right')

        # if we're in free spelling mode, we hide all text fields but
        # the _ve_spelled_phrase. we also need a multiline
        # _ve_spelled_phrase instead of the single lined one
        if self.offline == self.copy_spelling == False:
            self._spelled_phrase = "   "
            self._ve_spelled_phrase = WrappedText(
                position=(0, self._current_letter_position[1]),
                text=(len(self._spelled_phrase) == 0 and " "
                      or self._spelled_phrase),
                font_size=self.font_size_phrase,
                color=self.phrase_color,
                size=(float(self.geometry[2]), float(self.geometry[3])))
            for i in self._ve_letterbox, self._ve_innerbox, self._ve_current_letter, self._ve_desired_letters:
                i.set(on=False)

        ## add word box to elementlist:
        self._ve_elements.extend([
            self._ve_letterbox, self._ve_innerbox, self._ve_current_letter,
            self._ve_desired_letters, self._ve_spelled_phrase
        ])

        ## create countdown:
        self._ve_countdown = Text(position=self._centerPos,
                                  text=" ",
                                  font_size=self.font_size_countdown,
                                  color=self.countdown_color,
                                  anchor='center',
                                  on=False)

        ## create countdown shapes
        self._ve_countdown_shape = self.countdown_shapes[
            self.countdown_shape_select](radius=90,
                                         position=self._centerPos,
                                         color=self.countdown_shape_color,
                                         on=False)

        ## create oscillator circle:
        self._ve_oscillator = FilledCircle(position=(self.osc_size / 2 + 10,
                                                     self.osc_size / 2 + 10),
                                           radius=self.osc_size / 2,
                                           color=self.osc_color,
                                           on=False)

        ## create shapes and letters:
        self.init_screen_elements()

        ## add remaining elements to element list:
        self._ve_elements.extend([
            self._ve_countdown_shape, self._ve_countdown, self._ve_oscillator
        ])

        ## add elements to viewport:
        self._viewport = Viewport(screen=self._screen,
                                  stimuli=self._ve_elements)
        self._presentation = Presentation(viewports=[self._viewport],
                                          handle_event_callbacks=[
                                              (pygame.KEYDOWN,
                                               self.keyboard_input),
                                              (pygame.QUIT, self.__stop)
                                          ])
Esempio n. 10
0
    def __init__(self, expparadigm, config, phrases, args):
        # TODO: add a 'question' argument
        debug("__init__")
        Trial.__init__(self,
                       config,
                       args['experiment'],
                       args['item'],
                       args['condition'],
                       args['mode'],
                       phrases,
                       len(phrases) + 1,
                       question=None)
        if expparadigm == "MR-SAT":
            self.paradigm = "MR"
        elif expparadigm == "SAT":
            self.paradigm = "SR"
        else:
            raise ("Invalid experiment paradigm.")

        mode = args['mode']

        if not args.has_key('speededAcceptability'):
            args['speededAcceptability'] = False
        #if not args.has_key('lastFeedbackOffset'):
        #	args['lastFeedbackOffset'] = 0

        self.args = args

        self.displayPhrase = None
        self.lastPhraseRead = None
        self.lastResponseCorrect = None

        # create phrase chunks
        masked_phrases = []
        text_phrases = []
        space = Text(text=" ",
                     color=(0.0, 0.0, 0.0),
                     position=(0, 0),
                     font_size=self.config.sprStimulusSize,
                     anchor='left',
                     on=0,
                     font_name=self.config.font)
        space_size = space.parameters.size[0]

        # set initial word coordinates
        phrase_positions = []
        if mode == CPresentationMode.MovingWindow:
            x_pos = self.config.xPositionStart
            y_pos = globalScreen.size[1] / 2
            anchor = "left"

        elif mode == CPresentationMode.Centered:
            x_pos = globalScreen.size[0] / 2
            y_pos = globalScreen.size[1] / 2
            anchor = "center"

        # create phrases
        self.sentence = ""
        for i in range(0, len(phrases)):
            if phrases[i] == "$":
                self.phraseSignalReference = i
                continue

            self.sentence = self.sentence + " " + phrases[i]
            text = Text(text=phrases[i],
                        color=(0.0, 0.0, 0.0),
                        position=(x_pos, y_pos),
                        font_size=self.config.sprStimulusSize,
                        anchor=anchor,
                        on=0,
                        font_name=self.config.font)

            if mode == CPresentationMode.MovingWindow:
                phrase_positions.append((x_pos, y_pos))
                x_pos = x_pos + text.parameters.size[0] + space_size

            text_phrases.append(text)
            # TODO: Fix y coordinates too. Necessary once the stimulus
            #       becomes longer than one line.
        assert (hasattr(self, "phraseSignalReference"))
        self.sentence.strip()

        # create masks if the mode is moving window
        if mode == CPresentationMode.MovingWindow:
            for i in range(0, len(phrases)):
                text_size = text_phrases[i].parameters.size
                mask_size = (text_size[0], config.sprMaskHeight)
                mask_position = [
                    phrase_positions[i][0], phrase_positions[i][1]
                ]
                mask_position[1] = mask_position[1] - (text_size[1] / 2 -
                                                       mask_size[1] / 2)

                phrase_mask = Target2D(color=(0.0, 0.0, 0.0),
                                       position=mask_position,
                                       anchor='left',
                                       on=1,
                                       size=mask_size)

                masked_phrases.append(phrase_mask)

        self.screen = TrialScreenSAT(config, text_phrases, masked_phrases,
                                     mode, self.args['signalsCnt'],
                                     self.args['feedbackIndicators'],
                                     self.args['mappingIndicators'])

        if not self.args['speededAcceptability']:
            self.responses = [False] * self.args['signalsCnt']
        else:
            self.responses = [False]

        self._directionBeforeSignal = None
        self._directionAfterSignal = None
 def init_screen_elements(self):
     '''
     Initializing screen elements
     '''
     self._letter_positions = []        
     ## create and place the circles and letters:
     circle_layout = CircularLayout(nr_elements=self._nr_elements,
                                    radius=self.speller_radius,
                                    start=NP.pi/6.*5)
     circle_layout.positions.reverse()
     self._letter_layout = CircularLayout(nr_elements=self._nr_elements,
                                    radius=self.circle_radius*0.65,
                                    start=NP.pi/6.*5)
     self._letter_layout.positions.reverse()
     self._shape_positions = [(x+self.geometry[2]/2, y+self._spellerHeight/2) for (x,y) in circle_layout.positions]
     # add the standard elements:
     for i in xrange(self._nr_elements):
         self._ve_edges.append(FilledCircle(radius=self._edge_radius,
                                             position=self._shape_positions[i],
                                             color=self.edge_color))
         self._ve_shapes.append(FilledCircle(radius=self._circle_radius,
                                             position=self._shape_positions[i],
                                             color=self.shape_color))
         # add the letters of level 1:
         for j in xrange(len(self.letter_set[i])): # warning: self.letter_set must be at least of length self._nr_elements!!!
             self._letter_positions.append((self._letter_layout.positions[j][0]+self._shape_positions[i][0],
                                            self._letter_layout.positions[j][1]+self._shape_positions[i][1]))
             self._ve_letters.append(Text(position=self._letter_positions[-1],
                                          text=self.letter_set[i][j],
                                          font_size=self.font_size_level1,
                                          color=self.letter_color,
                                          anchor='center'))
     
     # add the stimuli letters of level 1:
     letter_layout2 = CircularLayout(nr_elements=self._nr_elements,
                                    radius=self.circle_radius*0.65*self.flash_size_factor,
                                    start=NP.pi/6.*5)
     letter_layout2.positions.reverse()
     for i in xrange(self._nr_elements):
         for j in xrange(len(self.letter_set[i])): # warning: self.letter_set must be at least of length self._nr_elements!!!
             self._letter_positions.append((letter_layout2.positions[j][0]+self._shape_positions[i][0],
                                            letter_layout2.positions[j][1]+self._shape_positions[i][1]))
             self._ve_letters.append(Text(position=self._letter_positions[-1],
                                          text=self.letter_set[i][j],
                                          font_size=int(NP.floor(self.font_size_level1*self.flash_size_factor)),
                                          color=self.letter_stimulus_color,
                                          anchor='center',
                                          on=False))
     
     # add letters of level 2:
     for i in xrange(self._nr_elements):
         self._ve_letters.append(Text(position=self._shape_positions[i],
                                      text=" ",
                                      font_size=self.font_size_level2,
                                      color=self.letter_color,
                                      anchor='center',
                                      on=False))
         
     # add stimuli letters of level 2:
     for i in xrange(self._nr_elements):
         self._ve_letters.append(Text(position=self._shape_positions[i],
                                      text=" ",
                                      font_size=int(NP.floor(self.font_size_level2*self.flash_size_factor)),
                                      color=self.letter_stimulus_color,
                                      anchor='center',
                                      on=False))
         
     ## add fixation point:
     self._ve_fixationpoint = FilledCircle(radius=self.fixationpoint_size,
                                           position=self._centerPos,
                                           color=self.fixationpoint_color)
             
     
     ## create feedback box:
     self._ve_feedback_box = Target2D(position=self._centerPos,
                                      size=(self.feedbackbox_size, self.feedbackbox_size),
                                      color=self.feedback_color,
                                      on=False)
     
     ## add feedback letters:
     self._ve_feedback_letters = []
     for i in xrange(self._nr_elements-1):
         self._ve_feedback_letters.append(Text(position=(self._letter_layout.positions[i][0]+self._centerPos[0],
                                                         self._letter_layout.positions[i][1]+self._centerPos[1]),
                                               color=self.letter_color,
                                               font_size=self.font_size_level1,
                                               text=" ",
                                               on=False,
                                               anchor="center"))
     self._ve_feedback_letters.append(Text(position=self._centerPos,
                                           color=self.letter_color,
                                           font_size=self.font_size_level2,
                                           text=" ",
                                           anchor='center',
                                           on=False))
     
     ## put all in elements container:
     self._ve_elements.extend(self._ve_edges)
     self._ve_elements.extend(self._ve_shapes)
     self._ve_elements.extend(self._ve_letters)
     self._ve_elements.extend([self._ve_feedback_box])
     self._ve_elements.extend(self._ve_feedback_letters)
     self._ve_elements.append(self._ve_fixationpoint)
Esempio n. 12
0
    eye = (0.0, sin(t * 0.3) + 2.0, -2.0)
    camera_look_at = (0.0, 0.0, 0.0)
    camera_up = (0.0, 1.0, 0.0)
    cam_matrix.look_at(eye, camera_look_at, camera_up)
    return cam_matrix.get_matrix()


drum_camera_matrix = ModelView()

##########
#  Gabor #
##########

gray_rect = Target2D(
    position=(x2, y1),
    anchor='center',
    size=(width, height),
    color=(0.5, 0.5, 0.5, 1.0),
)

try:
    gaussian_mask = Mask2D(function='gaussian',
                           radius_parameter=25,
                           num_samples=(256, 256))
except Exception, x:
    gaussian_mask = None
    warning_stimuli.append(
        Text(
            text="Texture Mask",
            position=(x2, y1),
            anchor='center',
            color=warning_color,
    def init_screen_elements(self):
        '''
        Initializing screen elements
        '''

        ## create shapes:
        if self.do_animation:
            for i in xrange(self._nr_elements):
                self._ve_shapes.append(
                    self.registered_shapes[self.shapes[i][0]](
                        position=self._centerPos,
                        color=self.shape_color[i],
                        on=False,
                        **self.shapes[i][1]))

            ## add letters of level 1:
            circle_layout = CircularLayout(nr_elements=self._nr_elements,
                                           radius=self.speller_radius,
                                           start=NP.pi / 6. * 5)
            circle_layout.positions.reverse()
            self._letter_layout = CircularLayout(nr_elements=self._nr_elements,
                                                 radius=self.letter_radius,
                                                 start=NP.pi / 6. * 5)
            self._letter_layout.positions.reverse()
            for i in xrange(self._nr_elements):
                # store countdown position:
                self._countdown_shape_positions.append(
                    (self._centerPos[0] + circle_layout.positions[i][0],
                     self._centerPos[1] + circle_layout.positions[i][1]))

                # put shape in container:
                self._ve_elements.append(self._ve_shapes[i])

                for j in xrange(
                        len(self.letter_set[i])
                ):  # warning: self.letter_set must be at least of length self._nr_elements!!!
                    # store position:
                    self._letter_positions.append(
                        (self._letter_layout.positions[j][0] +
                         self._centerPos[0],
                         self._letter_layout.positions[j][1] +
                         self._centerPos[1]))

                    # store countdown position:
                    self._countdown_letter_positions.append(
                        (self._letter_layout.positions[j][0] +
                         self._countdown_shape_positions[-1][0],
                         self._letter_layout.positions[j][1] +
                         self._countdown_shape_positions[-1][1]))

                    # add letter:
                    self._ve_letters.append(
                        Text(position=self._letter_positions[-1],
                             text=self.letter_set[i][j],
                             font_size=self.font_size_level1,
                             color=self.letter_color,
                             anchor='center',
                             on=False))

            # add letters of level 2:
            for i in xrange(self._nr_elements):
                self._letter_positions.append(self._centerPos)
                self._countdown_letter_positions.append(
                    self._countdown_shape_positions[i])
                self._ve_letters.append(
                    Text(position=self._centerPos,
                         text=" ",
                         font_size=self.font_size_level2,
                         color=(self.level_2_letter_colors
                                and self.stimuli_colors[i]
                                or self.letter_color),
                         anchor='center',
                         on=False))

                # put letters in container:
            self._ve_elements.extend(self._ve_letters)

            ## create feedback box:
            self._ve_feedback_box = Target2D(position=self._centerPos,
                                             size=(self.feedbackbox_size,
                                                   self.feedbackbox_size),
                                             color=self.feedback_color,
                                             on=False)

            ## add feedback letters:
            self._ve_feedback_letters = []
            for i in xrange(self._nr_elements):
                self._ve_feedback_letters.append(
                    Text(position=(self._letter_layout.positions[i][0] +
                                   self._centerPos[0],
                                   self._letter_layout.positions[i][1] +
                                   self._centerPos[1]),
                         color=self.letter_color,
                         font_size=self.font_size_level1,
                         text=" ",
                         on=False,
                         anchor="center"))
                self._ve_feedback_letters.append(
                    Text(position=self._centerPos,
                         color=self.letter_color,
                         font_size=self.font_size_level2,
                         text=" ",
                         anchor='center',
                         on=False))

            ## add feedback note (whether or not there was an ErrP detected):
            self._ve_feedback_ErrP = Text(
                position=self._centerPos,
                color=self.feedback_ErrP_color,
                text="X",
                font_size=self.font_size_feedback_ErrP,
                anchor='center',
                on=False)

            ## add fixation point:
            self._ve_fixationpoint = FilledCircle(
                radius=self.fixationpoint_size,
                position=self._centerPos,
                color=self.fixationpoint_color,
                on=False)

            ##################### IF NOT DO ANIMATION #########################
        else:
            ## add letters of level 1:
            circle_layout = CircularLayout(nr_elements=self._nr_elements,
                                           radius=self.speller_radius,
                                           start=NP.pi / 6. * 5)
            self._letter_layout = CircularLayout(nr_elements=self._nr_elements,
                                                 radius=self.letter_radius,
                                                 start=NP.pi / 6. * 5)
            circle_layout.positions.reverse()
            self._letter_layout.positions.reverse()

            for i in xrange(self._nr_elements):
                self._ve_shapes.append(
                    self.registered_shapes[self.shapes[i][0]](
                        position=(self._centerPos[0] +
                                  circle_layout.positions[i][0],
                                  self._centerPos[1] +
                                  circle_layout.positions[i][1]),
                        color=self.shape_color[i],
                        on=False,
                        **self.shapes[i][1]))

            for i in xrange(self._nr_elements):
                # store countdown position:
                self._countdown_shape_positions.append(
                    (self._centerPos[0] + circle_layout.positions[i][0],
                     self._centerPos[1] + circle_layout.positions[i][1]))
                # put shape in container:
                self._ve_elements.append(self._ve_shapes[i])

                for j in xrange(
                        len(self.letter_set[i])
                ):  # warning: self.letter_set must be at least of length self._nr_elements!!!
                    # store position:
                    self._letter_positions.append(
                        (self._letter_layout.positions[j][0] +
                         self._centerPos[0],
                         self._letter_layout.positions[j][1] +
                         self._centerPos[1]))

                    # store countdown position:
                    self._countdown_letter_positions.append(
                        (self._letter_layout.positions[j][0] +
                         self._countdown_shape_positions[-1][0],
                         self._letter_layout.positions[j][1] +
                         self._countdown_shape_positions[-1][1]))

                    # add letter:
                    self._ve_letters.append(
                        Text(position=(self._letter_layout.positions[j][0] +
                                       self._centerPos[0] +
                                       circle_layout.positions[i][0],
                                       self._letter_layout.positions[j][1] +
                                       self._centerPos[1] +
                                       circle_layout.positions[i][1]),
                             text=self.letter_set[i][j],
                             font_size=self.font_size_level1,
                             color=self.letter_color,
                             anchor='center',
                             on=False))

            # add letters of level 2:
            for i in xrange(self._nr_elements):
                self._letter_positions.append(
                    (self._letter_layout.positions[i][0] + self._centerPos[0],
                     self._letter_layout.positions[i][1] + self._centerPos[1]))
                self._countdown_letter_positions.append(
                    (self._letter_layout.positions[i][0] +
                     self._countdown_shape_positions[-1][0],
                     self._letter_layout.positions[i][1] +
                     self._countdown_shape_positions[-1][1]))
                self._ve_letters.append(
                    Text(position=(self._letter_layout.positions[i][0] +
                                   self._centerPos[0] +
                                   circle_layout.positions[i][0],
                                   self._letter_layout.positions[i][1] +
                                   self._centerPos[1] +
                                   circle_layout.positions[i][1]),
                         text=" ",
                         font_size=self.font_size_level2,
                         color=(self.level_2_letter_colors
                                and self.stimuli_colors[i]
                                or self.letter_color),
                         anchor='center',
                         on=False))

            # put letters in container:
            self._ve_elements.extend(self._ve_letters)

            ## create feedback box:
            self._ve_feedback_box = Target2D(position=self._centerPos,
                                             size=(self.feedbackbox_size,
                                                   self.feedbackbox_size),
                                             color=self.feedback_color,
                                             on=False)

            ## add feedback letters:
            self._ve_feedback_letters = []
            for i in xrange(self._nr_elements):
                self._ve_feedback_letters.append(
                    Text(position=(self._letter_layout.positions[i][0] +
                                   self._centerPos[0],
                                   self._letter_layout.positions[i][1] +
                                   self._centerPos[1]),
                         color=self.letter_color,
                         font_size=self.font_size_level1,
                         text=" ",
                         on=False,
                         anchor="center"))
                self._ve_feedback_letters.append(
                    Text(position=self._centerPos,
                         color=self.letter_color,
                         font_size=self.font_size_level2,
                         text=" ",
                         anchor='center',
                         on=False))

            ## add feedback note (whether or not there was an ErrP detected):
            self._ve_feedback_ErrP = Text(
                position=self._centerPos,
                color=self.feedback_ErrP_color,
                text="X",
                font_size=self.font_size_feedback_ErrP,
                anchor='center',
                on=False)

            ## add fixation point:
            self._ve_fixationpoint = FilledCircle(
                radius=self.fixationpoint_size,
                position=self._centerPos,
                color=self.fixationpoint_color,
                on=False)

        # put letters in container:
        self._ve_elements.append(self._ve_feedback_box)
        self._ve_elements.extend(self._ve_feedback_letters)
        self._ve_elements.append(self._ve_feedback_ErrP)
        self._ve_elements.append(self._ve_fixationpoint)
Esempio n. 14
0
    def init_screen_elements(self):
        '''
        Initialize screen elements
        '''
        self._letter_positions = []
        ## create triangles:
        self._letter_layout = CircularLayout(nr_elements=self._nr_elements,
                                             radius=self.letter_radius,
                                             start=NP.pi / 6. * 5)
        self._letter_layout.positions.reverse()
        a = self.speller_radius / 2.
        b = a * NP.sqrt(3) / 3.
        self._shape_positions = [
            (self._centerPos[0], self._centerPos[1] + 2 * b),
            (self._centerPos[0] + a, self._centerPos[1] + b),
            (self._centerPos[0] + a, self._centerPos[1] - b),
            (self._centerPos[0], self._centerPos[1] - 2 * b),
            (self._centerPos[0] - a, self._centerPos[1] - b),
            (self._centerPos[0] - a, self._centerPos[1] + b)
        ]
        orientaion = [180., 0., 180., 0., 180., 0.]
        for i in xrange(self._nr_elements):
            self._ve_edges.append(
                FilledTriangle(size=self.speller_radius,
                               position=self._shape_positions[i],
                               orientation=orientaion[i],
                               color=self.edge_color))
            self._ve_shapes.append(
                FilledTriangle(size=self.speller_radius - self.edge_size,
                               position=self._shape_positions[i],
                               orientation=orientaion[i],
                               color=self.shape_color))

            ## add the letters of level 1:
            for j in xrange(
                    len(self.letter_set[i])
            ):  # warning: self.letter_set must be at least of length self._nr_elements!!!
                self._letter_positions.append(
                    (self._letter_layout.positions[j][0] +
                     self._shape_positions[i][0],
                     self._letter_layout.positions[j][1] +
                     self._shape_positions[i][1]))
                self._ve_letters.append(
                    Text(position=self._letter_positions[-1],
                         text=self.letter_set[i][j],
                         font_size=self.font_size_level1,
                         color=self.letter_color,
                         anchor='center'))

        ## add letters of level 2:
        for i in xrange(self._nr_elements):
            self._ve_letters.append(
                Text(position=self._shape_positions[i],
                     text=" ",
                     font_size=self.font_size_level2,
                     color=self.letter_color,
                     anchor='center',
                     on=False))

        ## add fixation point:
        self._ve_fixationpoint = FilledCircle(radius=self.fixationpoint_size,
                                              position=self._centerPos,
                                              color=self.fixationpoint_color)

        ## create feedback box:
        self._ve_feedback_box = Target2D(position=self._centerPos,
                                         size=(self.feedbackbox_size,
                                               self.feedbackbox_size),
                                         color=self.feedback_color,
                                         on=False)

        ## add feedback letters:
        self._ve_feedback_letters = []
        for i in xrange(self._nr_elements - 1):
            self._ve_feedback_letters.append(
                Text(position=(self._letter_layout.positions[i][0] +
                               self._centerPos[0],
                               self._letter_layout.positions[i][1] +
                               self._centerPos[1]),
                     color=self.letter_color,
                     font_size=self.font_size_level1,
                     text=" ",
                     on=False,
                     anchor="center"))
        self._ve_feedback_letters.append(
            Text(position=self._centerPos,
                 color=self.letter_color,
                 font_size=self.font_size_level2,
                 text=" ",
                 anchor='center',
                 on=False))

        ## put all in elements container:
        self._ve_elements.extend(self._ve_edges)
        self._ve_elements.extend(self._ve_shapes)
        self._ve_elements.extend(self._ve_letters)
        self._ve_elements.append(self._ve_feedback_box)
        self._ve_elements.extend(self._ve_feedback_letters)
        self._ve_elements.append(self._ve_fixationpoint)
    def __init__(self,
                 config,
                 experiment,
                 item,
                 condition,
                 mode,
                 phrases,
                 question=None):
        debug("__init__")
        Trial.__init__(self, config, experiment, item, condition, mode,
                       phrases,
                       len(phrases) + 1, question)
        self.displayPhrase = None
        self.lastPhraseRead = None

        # create phrase chunks
        masked_phrases = []
        text_phrases = []
        i = 0
        signalReference = -1
        space = Text(text=" ",
                     color=(0.0, 0.0, 0.0),
                     position=(0, 0),
                     font_size=self.config.sprStimulusSize,
                     anchor='left',
                     on=0,
                     font_name=self.config.font)
        space_size = space.parameters.size[0]

        # set initial word coordinates
        phrase_positions = []
        if mode == CPresentationMode.MovingWindow:
            x_pos = self.config.xPositionStart
            y_pos = globalScreen.size[1] / 2
            anchor = "left"

        elif mode == CPresentationMode.Centered:
            x_pos = globalScreen.size[0] / 2
            y_pos = globalScreen.size[1] / 2
            anchor = "center"

        # create phrases
        for i in range(0, len(phrases)):
            if phrases[i] == "$":
                raise "There should not be a '$' in an SPR stimulus."

            text = Text(text=phrases[i],
                        color=(0.0, 0.0, 0.0),
                        position=(x_pos, y_pos),
                        font_size=self.config.sprStimulusSize,
                        anchor=anchor,
                        on=0,
                        font_name=self.config.font)

            if mode == CPresentationMode.MovingWindow:
                phrase_positions.append((x_pos, y_pos))
                x_pos = x_pos + text.parameters.size[0] + space_size

            text_phrases.append(text)

            # TODO: Fix y coordinates too. Necessary once the stimulus becomes longer than one line.

        # create masks if the mode is moving window
        if mode == CPresentationMode.MovingWindow:
            for i in range(0, len(phrases)):
                text_size = text_phrases[i].parameters.size
                mask_size = (text_size[0], config.sprMaskHeight)
                mask_position = [
                    phrase_positions[i][0], phrase_positions[i][1]
                ]
                mask_position[1] = mask_position[1] - (text_size[1] / 2 -
                                                       mask_size[1] / 2)

                phrase_mask = Target2D(color=(0.0, 0.0, 0.0),
                                       position=mask_position,
                                       anchor='left',
                                       on=1,
                                       size=mask_size)

                masked_phrases.append(phrase_mask)

        self.screen = TrialScreen(config, text_phrases, masked_phrases, mode)