def set_standard_screen(self):
        '''
        set screen elements to standard state.
        '''

        self._countdown_screen = False

        # move all elements with their letters to standard position:

        def update(t):
            dt = t / self.animation_time
            for i in xrange(self._nr_elements):
                pos = animate_sigmoid(self._countdown_shape_positions[i],
                                      self._centerPos, dt)
                self._ve_shapes[i].set(position=pos)  # shapes
                self._ve_letters[self._nr_letters + i].set(
                    position=pos)  # level 2 letters
            for i in xrange(self._nr_letters):
                pos = animate_sigmoid(self._countdown_letter_positions[i],
                                      self._letter_positions[i], dt)
                self._ve_letters[i].set(position=pos)  # level 1 letters

        if self.do_animation:
            self._presentation.set(go_duration=(self.animation_time,
                                                'seconds'))
            self._presentation.add_controller(
                None, None, FunctionController(during_go_func=update))
        else:
            self._presentation.set(go_duration=(0, 'seconds'))

        # send to screen:
        self._presentation.go()
        self._presentation.remove_controller(None, None, None)

        for i in xrange(self._nr_elements):
            self._ve_shapes[i].set(position=self._centerPos, on=False)
            self._ve_letters[self._nr_letters + i].set(
                position=self._centerPos, on=False)
        for i in xrange(self._nr_letters):
            self._ve_letters[i].set(position=self._letter_positions[i],
                                    on=False)

        self._ve_countdown.set(on=False, text=" ")
示例#2
0
    draw = ImageDraw.Draw(image)
    line_x = image_size[0] / float(num_images) * i
    draw.line((line_x, 0, line_x, image_size[1]), fill=(255, 255, 255))
    image_list.append(image)

texture_list = map(Texture,
                   image_list)  # create instances of Texture from images

screen = get_default_screen()

stimulus = TextureStimulus(texture=texture_list[0],
                           position=(screen.size[0] / 2.0,
                                     screen.size[1] / 2.0),
                           anchor='center',
                           size=image_size)

viewport = Viewport(screen=screen, stimuli=[stimulus])

p = Presentation(go_duration=(num_images * duration_per_image, 'seconds'),
                 viewports=[viewport])


def put_image(t):
    i = int(t / duration_per_image)  # choose image
    stimulus.parameters.texture = texture_list[i]


p.add_controller(None, None, FunctionController(during_go_func=put_image))

p.go()
示例#3
0
    print "PROBLEM: %s" % problem
    print "SOLUTION: %s " % solution
    print "----------------------"

    ns = [n1, n2]

    #default values for misfiring voice key
    misfire = 0
    ACC = 1

    #BLOCK 1 - Problem & RESPONSE

    p = Presentation(go_duration=('forever', ), viewports=[expPort])
    p.add_controller(
        None, None,
        FunctionController(during_go_func=problem_controller,
                           temporal_variables=FRAMES_ABSOLUTE))
    p.go()

    #BLOCK 2 - STRATEGY SELECTION & GRADING
    p2 = Presentation(go_duration=(1.5, 'seconds'), viewports=[fixCross])
    p2.parameters.handle_event_callbacks = [(pygame.locals.KEYDOWN,
                                             key_handler)]
    p2.go()

    if ACC == 0:
        problemQ = [n1, n2, stim]
        error = Presentation(go_duration=(1, 'seconds'), viewports=[errorPort])
        error.go()
    else:
        problemQ = []
示例#4
0
def showRSVP(viewport):
 global imageCounter
 global previous_t
 global numImsPerBlock
 global texture_object
 global curImList
 global numTargets
 global numNontargets
 global presentationFreq
 global doingTraining
 global ctrl_key

 doingTraining = 0

 #
 # Load the parameters for the presentation
 #

 presentationParams = getPracticeSessionParams()

 SDL_Maximize()

 presentationFreq = int(presentationParams[0])


 block_idx = 0
 ctrl_key = 0 
 while (1):
   internalState = 0  # here we are the block state
   
   if (doingTraining==1):
      presentationParams = getPracticeSessionParams()
      presentationFreq = int(presentationParams[0])
      SDL_Maximize()

      doingTraining = 0
   elif (doingTraining==2):
      break     
       

   imageCounter = 0
   internalState = 1  # About to enter the presentation mode.

   previous_t = 0;
      
   # Load training block
   
   if (input_from == 1):
     curList = sampleTrainImages(trainPath,numTargets,numNontargets,alreadySampled,withreplacement)
   elif (input_from == 2):
     print "loading XML"
     curList = sampleTrainImagesXML(inputXMLfile,numTargets,numNontargets)
   else:
     msgbox('The input type specified is invalid, check the value of input_from parameter in configuration.ini file.\n Terminating RSVP session.')  
     my_logger.error('The input type specified is invalid, check the value of input_from parameter in configuration.ini file.')
     break;
   curImList = map(operator.itemgetter(0),curList)
   curTargList = map(operator.itemgetter(1),curList)
   curImPath = map(operator.itemgetter(2),curList)
   curImName = map(operator.itemgetter(3),curList)
   numImsPerBlock = len(curImList)

   # fixation cross
   p.parameters.go_duration = (1,'seconds')
   viewport.parameters.stimuli=[fixPt]

   p.go()

   imageStim = TextureStimulus(texture=imageTex,
                               position = (screen.size[0]/2.0,screen.size[1]/2.0),
                               anchor='center', size=(width*scale,height*scale),
                               mipmaps_enabled = 0, texture_min_filter=gl.GL_LINEAR)

   texture_object = imageStim.parameters.texture.get_texture_object()
   texture_object.put_sub_image( curImList[0] )
   p.add_controller(None, None, FunctionController(during_go_func=every_frame_func) )
   #p.parameters.go_duration = ((numImsPerBlock+1)/float(presentationFreq),'seconds')
   p.parameters.go_duration = (2*(numImsPerBlock+1)/float(presentationFreq),'seconds')
   viewport.parameters.stimuli=[imageStim]
   p.go();
   block_idx = block_idx + 1

   internalState = 0  # here we are the block state


   # fixation cross
   p.parameters.go_duration = (1,'seconds')
   p.controllers = []
   viewport.parameters.stimuli=[fixPt]
   p.go()

   # please wait (while we get results)
   p.parameters.go_duration = (1,'frames')
   p.controllers = []
   viewport.parameters.stimuli=[pleaseWait]
   p.go()

 

   totElements = len(curImName)
   curImNamePrefixed = [('_' + str(eventList[curTargList[i]]) + '_' + curImName[i]) for i in range(totElements)]

   # get the data strucute to be able to show potential feedback during evaluation methodology.

   dataStruct = simulateCBCIoutput(block_idx,curTargList,curImPath,curImName)
   
      
   # Call to the external feedback screen
   status = show_feedback(screen,viewport,dataStruct,curTargList)

   if (status == 1):
     #
     # Show custom feedback screen
     #
     p.parameters.go_duration = ('forever',)
     p.go()
   else:
     
     #
     # Show default feedback.
     #

     #print reslist
     sttext = "Blocks shown: " + str(block_idx)
     statisticsText = Text( text = sttext, position = (screen.size[0]/2.0,screen.size[1]/2), font_name=fname,font_size = fsize,
                        anchor = 'center', color = (0.0,0.0,0.0,1.0))

     p.parameters.go_duration = ('forever',)
     viewport.parameters.stimuli=[statisticsText]
     p.go()
    def doSim(self, trial, road, duration, tau, doEyetrack):

        # Measure sample rate in order to calculate delay buffer
        sample_rate = self.screen.measure_refresh_rate(2.0)
        print "Sample rate: " + str(sample_rate)
        #sample_rate = 60

        self.doEyetrack = doEyetrack

        self.pos_ring = RingBuffer(self.center,
                                   int(math.floor(tau * sample_rate)) + 1)
        print("Ring Buffer:: size: " + str(self.pos_ring.size))

        if doEyetrack:
            import pylink
            from EyeLinkCoreGraphicsVE import EyeLinkCoreGraphicsVE

            self.tracker = pylink.EyeLink()
            if self.tracker == None:
                print "Error: Eyelink is not connected"
                sys.exit()

            genv = EyeLinkCoreGraphicsVE(self.screen, self.tracker)
            pylink.openGraphicsEx(genv)

            #Opens the EDF file.
            edfFileName = "TRIAL" + str(trial) + ".EDF"
            self.tracker.openDataFile(edfFileName)

            pylink.flushGetkeyQueue()

            self.tracker.sendCommand("screen_pixel_coords =	0 0 %d %d" %
                                     (VisionEgg.config.VISIONEGG_SCREEN_W,
                                      VisionEgg.config.VISIONEGG_SCREEN_H))

            tracker_software_ver = 0
            eyelink_ver = self.tracker.getTrackerVersion()
            if eyelink_ver == 3:
                tvstr = self.tracker.getTrackerVersionString()
                vindex = tvstr.find("EYELINK CL")
                tracker_software_ver = int(
                    float(tvstr[(vindex + len("EYELINK CL")):].strip()))

            if eyelink_ver >= 2:
                self.tracker.sendCommand("select_parser_configuration 0")
                if eyelink_ver == 2:  #turn off scenelink camera stuff
                    self.tracker.sendCommand("scene_camera_gazemap = NO")
            else:
                self.tracker.sendCommand("saccade_velocity_threshold = 35")
                self.tracker.sendCommand(
                    "saccade_acceleration_threshold = 9500")

            # set EDF file contents
            self.tracker.sendCommand(
                "file_event_filter = LEFT,RIGHT,FIXATION,SACCADE,BLINK,MESSAGE,BUTTON"
            )
            if tracker_software_ver >= 4:
                self.tracker.sendCommand(
                    "file_sample_data	= LEFT,RIGHT,GAZE,AREA,GAZERES,STATUS,HTARGET"
                )
            else:
                self.tracker.sendCommand(
                    "file_sample_data	= LEFT,RIGHT,GAZE,AREA,GAZERES,STATUS")

            # set link data (used for gaze cursor)
            self.tracker.sendCommand(
                "link_event_filter = LEFT,RIGHT,FIXATION,SACCADE,BLINK,BUTTON")
            if tracker_software_ver >= 4:
                self.tracker.sendCommand(
                    "link_sample_data	= LEFT,RIGHT,GAZE,GAZERES,AREA,STATUS,HTARGET"
                )
            else:
                self.tracker.sendCommand(
                    "link_sample_data	= LEFT,RIGHT,GAZE,GAZERES,AREA,STATUS")

            if not self.doneSetup:
                self.tracker.doTrackerSetup()
                self.doneSetup = True
            else:
                while 1:
                    try:
                        error = self.tracker.doDriftCorrect(
                            self.screen.size[0] / 2, self.screen.size[1] / 2,
                            1, 1)
                        if error != 27:  # ?? from example
                            break
                        else:
                            self.tracker.doTrackerSetup()
                    except:
                        break

        self.screen.parameters.bgcolor = 106.0 / 255.0, 147.0 / 255.0, 0.0
        # Load road data from file and create an image
        roadArray = numpy.loadtxt('road' + str(road) + '.txt')

        # Convert to a Path
        roadPath = ImagePath.Path(
            map(lambda xy: (xy[0], xy[1]), roadArray.tolist()))

        # Use Path to create a plot of the road
        im = Image.new("RGB", (2000, 100), (50, 50, 50))
        draw = ImageDraw.Draw(im)

        # draw each side of the road separately
        draw.line(roadPath[:4000], fill=(200, 200, 200))
        draw.line(roadPath[4000:], fill=(200, 200, 200))

        del draw

        # Lay out a road texture in the x-z plane
        roadTexture = Texture(im)

        del im

        eye_height = 2.5

        vertices = [(-10, -eye_height, 0), (-10, -eye_height, -1000),
                    (10, -eye_height, 0), (10, -eye_height, -1000)]

        rect = TextureStimulus3D(texture=roadTexture,
                                 lowerleft=vertices[0],
                                 lowerright=vertices[1],
                                 upperleft=vertices[2],
                                 upperright=vertices[3])

        # We will use these later for our camera transforms
        self.camera_matrix = ModelView()
        self.frame_timer = FrameTimer()

        self.outf = open(
            'steersim-' + str(trial) + '-' + str(road) + '-out.txt', 'wb')

        # Vewport for the road
        viewport3D = Viewport(
            screen=self.screen,
            projection=SimplePerspectiveProjection(fov_x=75.2),
            camera_matrix=self.camera_matrix,
            stimuli=[rect])

        # Construct a sky
        sky_l = 0
        sky_r = self.screen.size[0]
        sky_t = self.screen.size[1]
        sky_b = self.screen.size[1] / 2

        sky_vertices = [(sky_l, sky_t, 0), (sky_r, sky_t, 0),
                        (sky_r, sky_b, 0), (sky_l, sky_b, 0)]

        sky = Rectangle3D(color=(144.0 / 255.0, 190.0 / 255.0, 1.0),
                          vertex1=sky_vertices[0],
                          vertex2=sky_vertices[1],
                          vertex3=sky_vertices[2],
                          vertex4=sky_vertices[3])

        wheelTexture = Texture('wheel.png')
        self.wheel = TextureStimulus(texture=wheelTexture,
                                     internal_format=gl.GL_RGBA,
                                     position=(self.center, -75),
                                     anchor='center')

        # display the sky in its own viewport
        viewport2D = Viewport(screen=self.screen)
        viewport2D.parameters.stimuli = [sky, self.wheel]

        self.init_state()

        askText = Text(text='Press a key to start',
                       anchor='center',
                       position=(self.center, self.screen.size[1] / 2))
        splash = Viewport(screen=self.screen)
        splash.parameters.stimuli = [askText]
        self.askForNext = Presentation(go_duration=(0.5, 'seconds'),
                                       viewports=[splash])
        self.askForNext.add_controller(
            None, None, FunctionController(during_go_func=self.wait_for_key))
        self.askForNext.parameters.enter_go_loop = True
        self.askForNext.run_forever()

        self.simPres = Presentation(go_duration=(duration, 'seconds'),
                                    viewports=[viewport3D, viewport2D],
                                    handle_event_callbacks=[
                                        (pygame.KEYDOWN, self.check_keypress)
                                    ])
        self.simPres.add_controller(
            None, None, FunctionController(during_go_func=self.update))

        if doEyetrack:
            startTime = pylink.currentTime()
            self.tracker.sendMessage("SYNCTIME %d" %
                                     (pylink.currentTime() - startTime))
            error = self.tracker.startRecording(1, 1, 1, 1)
            self.tracker.sendMessage("PRES %d START" % (trial))

        self.simPres.go()

        if doEyetrack:
            self.tracker.sendMessage("PRES %d END" % (trial))
            self.tracker.stopRecording()

            # File transfer and cleanup!
            self.tracker.setOfflineMode()
            pylink.msecDelay(500)
            #Close the file and transfer it to Display PC
            self.tracker.closeDataFile()
            self.tracker.receiveDataFile(edfFileName, edfFileName)

        self.outf.close()

        if self.quit:
            raise SystemExit
# calculate a few variables we need
mid_x = screen.size[0] / 2.0
mid_y = screen.size[1] / 2.0
max_vel = min(screen.size[0], screen.size[1]) * 0.4


# define position as a function of time
def get_target_position(t):
    global mid_x, mid_y, max_vel
    #return ( max_vel*sin(0.1*2.0*pi*t) + mid_x , # x
    #         max_vel*sin(0.1*2.0*pi*t) + mid_y ) # y
    return (10, 10)


# Create an instance of the Controller class
target_position_controller = FunctionController(
    during_go_func=get_target_position)

#############################################################
#  Connect the controllers with the variables they control  #
#############################################################

#p.add_controller(target,'position', target_position_controller )

#######################
#  Run the stimulus!  #
#######################

p.go()
示例#7
0
	ns = [n1, n2]

	#default values for misfiring voice key
	misfire = 0
	ACC = 1

	#generate texts
	strat2 = "\n\nPlease describe your strategy"

	stratText, stratPort = printText(screen, strat2, 60, (255, 255, 255))
	expText, expPort = printText(screen, problem, 60, (255, 255, 255))

	#BLOCK 1 - Problem & RESPONSE

	p = Presentation(go_duration=('forever', ), viewports=[expPort])
	p.add_controller(None, None, FunctionController(during_go_func=problem_controller, temporal_variables = FRAMES_ABSOLUTE))
	p.go()

	#BLOCK 2 - STRATEGY SELECTION & GRADING
	p2 = Presentation(go_duration=('forever', ), viewports=[expPort, stratPort])
	p2.add_controller(None, None, FunctionController(during_go_func=strategy_controller, temporal_variables = FRAMES_ABSOLUTE))
	p2.parameters.handle_event_callbacks=[(pygame.locals.KEYDOWN, key_handler)]        
	p2.go()


	subject.inputData(trial, "misfire", misfire)
	subject.inputData(trial, "ACC", ACC)
	subject.inputData(trial, "strategy", strategy)

	#blank screen
	p3 = Presentation(go_duration=(1.5, 'seconds'), viewports=[fixCross])
示例#8
0
    p3 = Presentation(go_duration=(blankTime, 'seconds'), viewports=[fixCross])
    p3.go()

    p = Presentation(go_duration=('forever', ), viewports=[vr])
    p.parameters.handle_event_callbacks = [(pygame.locals.KEYDOWN, key_handler)
                                           ]
    p.go()

    subject.inputData(trial, "RT", RT)
    subject.inputData(trial, "ACC", ACC)

    #BLOCK 2 - STRATEGY SELECTION
    p2 = Presentation(go_duration=('forever', ), viewports=[stratPort])
    p2.add_controller(
        None, None,
        FunctionController(during_go_func=strategy_controller,
                           temporal_variables=FRAMES_ABSOLUTE))
    p2.parameters.handle_event_callbacks = [(pygame.locals.KEYDOWN,
                                             key_handler)]
    p2.go()

    #BLOCK 3 - BLANK SCREEN
    p3 = Presentation(go_duration=(0.5, 'seconds'), viewports=[fixCross])
    p3.go()

    subject.inputData(trial, "ACC", ACC)
    subject.inputData(trial, "strategy", strategy)

    ns.sort()
    lastns = copy.deepcopy(ns)
    lastlastns = copy.deepcopy(lastns)
def aplicacion():
    global p, inten, coord
    pos = [0.4, 0.5, 0.6, 0.7, 0.8]
    pos2 = [1.3, 1.4, 1.5, 1.6, 1.7, 1.8]
    rellenar()
    shuffle(coord)
    i = len(coord) - 1
    target.parameters.position = coord[i][:2]
    (xpos, ypos) = target.parameters.position
    x = xpos - screen.size[0] / 2
    y = ypos - screen.size[1] / 2
    anrad = math.atan2(y, x)
    angrad = math.degrees(anrad)

    if angrad >= 0:
        if angrad <= 90:
            orientacion = -45
            xx = 2.0
            yy = 2.0
        else:
            orientacion = -135
            xx = -2.0
            yy = 2.0
    else:
        aux = angrad * (-1)
        if aux <= 90:
            orientacion = 45
            xx = 2.0
            yy = -2.0
        else:
            orientacion = 135
            xx = -2.0
            yy = -2.0

    fixpoint.parameters.position = ((screen.size[0] / 2.0) + xx,
                                    (screen.size[1] / 2.0) + yy)
    fixpoint.parameters.orientation = orientacion

    viewport = Viewport(screen=screen, stimuli=[fixpoint, fixcirc])
    p = Presentation(go_duration=(1.0, 'seconds'), viewports=[viewport])
    p.parameters.handle_event_callbacks = [(pygame.locals.KEYDOWN, keydown),
                                           (pygame.locals.KEYUP, keyup),
                                           (pygame.locals.QUIT, quit_app)]
    p.add_controller(None, None, FunctionController(during_go_func=settings))
    #winsound.PlaySound('instruccion',winsound.SND_FILENAME)
    p.go()

    while len(coord) != 0:
        if end:
            break
        i = len(coord) - 1
        target.parameters.position = coord[i][:2]
        dur = pos[random.randrange(0, 4, 1)]
        (xpos, ypos) = target.parameters.position
        x = xpos - screen.size[0] / 2
        y = ypos - screen.size[1] / 2
        anrad = math.atan2(y, x)
        angrad = math.degrees(anrad)
        #fixpoint.parameters.orientation=(-angrad)
        if angrad >= 0:
            if angrad <= 90:
                orientacion = -45
                xx = 2.0
                yy = 2.0
            else:
                orientacion = -135
                xx = -2.0
                yy = 2.0
        else:
            aux = angrad * (-1)
            if aux <= 90:
                orientacion = 45
                xx = 2.0
                yy = -2.0
            else:
                orientacion = 135
                xx = -2.0
                yy = -2.0

        fixpoint.parameters.position = ((screen.size[0] / 2.0) + xx,
                                        (screen.size[1] / 2.0) + yy)
        fixpoint.parameters.orientation = orientacion

        viewport = Viewport(screen=screen, stimuli=[fixpoint, fixcirc])
        p = Presentation(go_duration=(dur, 'seconds'), viewports=[viewport])
        p.parameters.handle_event_callbacks = [(pygame.locals.QUIT, quit_app)]

        p.add_controller(None, None,
                         FunctionController(during_go_func=settings))
        p.go()

        inten = coord[i][-1]
        target.parameters.color = (
            1.0, 1.0, 1.0, inten
        )  #Se muestra el estimulo Duracion 0.3 segundos
        viewport = Viewport(screen=screen, stimuli=[target, fixpoint, fixcirc])
        p = Presentation(go_duration=(0.3, 'seconds'), viewports=[viewport])
        p.parameters.handle_event_callbacks = [(pygame.locals.QUIT, quit_app)]

        p.add_controller(None, None,
                         FunctionController(during_go_func=settings))
        p.go()
        target.parameters.color = (
            0.0, 0.0, 0.0, 1.0)  #Desaparece el estimulo tiempo para registrar
        viewport = Viewport(screen=screen, stimuli=[target, fixpoint, fixcirc])
        dur2 = pos[random.randrange(0, 4, 1)]
        p = Presentation(go_duration=(dur2, 'seconds'), viewports=[viewport])
        p.parameters.handle_event_callbacks = [(pygame.locals.KEYDOWN,
                                                keydown),
                                               (pygame.locals.KEYUP, keyup),
                                               (pygame.locals.QUIT, quit_app)]
        p.add_controller(None, None,
                         FunctionController(during_go_func=settings))
        p.go()
        coord.pop()
示例#10
0
                        color2           = (1.0, 0.5,  0.1), # RGB (alpha ignored if given)
                        contrast         = 0.2,
                        pedestal         = 0.1,
                        mask             = mask, # optional
                        position         = ( screen.size[0]/2.0, screen.size[1]/2.0 ),
                        anchor           = 'center',
                        size             = ( 300.0 , 300.0 ),
                        spatial_freq     = 20.0 / screen.size[0], # units of cycles/pixel
                        temporal_freq_hz = 1.0,
                        orientation      = 270.0 )

def pedestal_func(t):
    # Calculate pedestal over time. (Pedestal range [0.1,0.9] and
    # contrast = 0.2 limits total range to [0.0,1.0])
    temporal_freq_hz = 0.2
    return 0.4 * sin(t*2*pi * temporal_freq_hz) + 0.5

###############################################################
#  Create viewport - intermediary between stimuli and screen  #
###############################################################

viewport = Viewport( screen=screen, stimuli=[stimulus] )

########################################
#  Create presentation object and go!  #
########################################

p = Presentation(go_duration=(10.0,'seconds'),viewports=[viewport])
p.add_controller(stimulus,'pedestal',FunctionController(during_go_func=pedestal_func))
p.go()
    def feedback(self):
        # turn on feedback box and turn off fixationpoint:
        self._ve_feedback_box.set(on=True)
        self._ve_fixationpoint.set(on=False)
        
        if self._current_level == 1:
            
            '''level 1: present classified letter group in center and move letters to circles '''
            
            ## display letter group:
            for i in xrange(self._nr_elements-1):
                self._ve_feedback_letters[i].set(on=True,
                                                 text=self.letter_set[self._classified_element][i])
            ## turn on current element:
            self.stimulus(self._classified_element, True)
            
            ## turn off other letters:
            idx_start = self._classified_element*(self._nr_elements-1)
            idx_end = idx_start + self._nr_elements-1
            for i in xrange(idx_start):
                self._ve_letters[i].set(on=False)
            for i in xrange(idx_end, self._nr_letters):
                self._ve_letters[i].set(on=False)
            
            ## present:
            self._presentation.set(go_duration=(1, 'seconds'))
            self._presentation.go()
            
            ## turn off current element:
            self.stimulus(self._classified_element, False)
            for i in xrange(idx_start, idx_end):
                self._ve_letters[i].set(on=False)
            for i in xrange(self._nr_elements-1):
                self._ve_feedback_letters[i].set(on=False)
            
            ## animate letters:
            self._presentation.set(go_duration=(self.animation_time, 'seconds'))
            self._viewport.parameters.stimuli.extend([None]*(self._nr_elements-1))
            def update(t):
                dt = t/self.animation_time
                self._viewport.parameters.stimuli = self._viewport.parameters.stimuli[:-(self._nr_elements-1)]
                feedback_letters = []
                for i in xrange(self._nr_elements-1):
                    pos = animate_sigmoid(NP.add(self._letter_layout.positions[i], self._centerPos), self._shape_positions[i], dt)
                    font_size = int(round(animate(self.font_size_level1, self.font_size_level2, dt)))
                    feedback_letters.append(Text(position=pos,
                                                 color=self.letter_color,
                                                 font_size=font_size,
                                                 text=self.letter_set[self._classified_element][i],
                                                 anchor="center"))
                self._viewport.parameters.stimuli.extend(feedback_letters)
            self._presentation.add_controller(None,None,FunctionController(during_go_func=update))
            
            # send to screen:
            self._presentation.go()
            self._presentation.remove_controller(None,None,None)
            self._viewport.parameters.stimuli = self._viewport.parameters.stimuli[:-(self._nr_elements-1)]
                
            ## turn on level 2 letters:
            for i in xrange(len(self.letter_set[self._classified_element])):
                self._ve_letters[self._nr_letters*2 + i].set(on=True, text=self.letter_set[self._classified_element][i])
                self._ve_letters[self._nr_letters*2 + self._nr_elements + i].set(text=self.letter_set[self._classified_element][i])
                    
        else: 
            ''' level 2: present classified letter and move it to wordbox '''
            
            ## check if backdoor classified:
            if self._classified_letter >= len(self.letter_set[self._classified_element]):
                text = ' '
            else:
                text = self.letter_set[self._classified_element][self._classified_letter]
                
            ## display letter:
            self._ve_feedback_letters[-1].set(on=True, text=text)
            
            ## turn on current element stimulusw:
            if not self.offline:
                self.stimulus(self._classified_letter, True)
            
            ## turn off other letters:
            for i in xrange(self._classified_letter):
                self._ve_letters[self._nr_letters*2 + i].set(on=False)
            for i in xrange(self._classified_letter+1, self._nr_elements):
                self._ve_letters[self._nr_letters*2 + i].set(on=False)
            
            ## present:
            self._presentation.set(go_duration=(self.feedback_duration, 'seconds'))
            self._presentation.go()
            
            ## turn off current element stimulus:
            if not self.offline:
                self.stimulus(self._classified_letter, False)
                self._ve_letters[self._nr_letters*2 + self._classified_letter].set(on=False)
            self._ve_feedback_letters[-1].set(on=False)
            
            ## animate letter, but not if backdoor classified:
            if self._classified_letter < len(self.letter_set[self._classified_element]):
                self._presentation.set(go_duration=(self.animation_time, 'seconds'))
                self._viewport.parameters.stimuli.append(None)
                def update(t):
                    # Add one screen refresh (otherwise animation lags by 1 frame)
                    dt = t/self.animation_time
                    self._viewport.parameters.stimuli = self._viewport.parameters.stimuli[:-1]
                    pos = animate_sigmoid(self._centerPos, self._current_letter_position, dt)
                    color = animate_sigmoid(self.letter_color, self.current_letter_color, dt)
                    font_size = int(round(animate(self.font_size_level2, self.font_size_current_letter, dt)))
                    self._viewport.parameters.stimuli.append(Text(position=pos,
                                                                  color=color,
                                                                  font_size=font_size,
                                                                  text=text,
                                                                  anchor='center'))
                self._presentation.add_controller(None,None,FunctionController(during_go_func=update))
                
                # send to screen:
                self._presentation.go()
                self._presentation.remove_controller(None,None,None)

                self._viewport.parameters.stimuli = self._viewport.parameters.stimuli[:-1]
            else:
                self._presentation.set(go_duration=(self.animation_time, 'seconds'))
                self._presentation.go()
                
                    
            ## turn on level 1 letters:
            for i in xrange(self._nr_letters):
                self._ve_letters[i].set(on=True)
        
        ## turn off feedback box and turn on fixationpoint:
        self._ve_feedback_box.set(on=False)
        self._ve_fixationpoint.set(on=True)
示例#12
0
viewport = Viewport(
    screen=screen,
    stimuli=[static_checkerboard, dynamic_checkerboard, fixation_spot])

p = Presentation(go_duration=(dynamic_time + static_time, 'seconds'),
                 viewports=[viewport])

# Use a controller to hook into go loop, but control texture buffer
# through direct manipulation.
dynamic_texture_object = dynamic_checkerboard.parameters.texture.get_texture_object(
)
width, height = dynamic_checkerboard_size
# (Note: numpy arrays have indices flipped from images, thus the re-ordering)
flipped_shape = (height, width)


def control_dynamic(t):
    if t <= dynamic_time:
        random_data = numpy.random.randint(
            0,
            2,
            size=(dynamic_checkerboard_size[1],
                  dynamic_checkerboard_size[0])) * 255
        dynamic_texture_object.put_sub_image(random_data)


p.add_controller(None, None,
                 FunctionController(during_go_func=control_dynamic))

p.go()
示例#13
0
fixation_spot = FixationSpot(position=(screen.size[0] / 2, screen.size[1] / 2),
                             anchor='center')

perspective = SimplePerspectiveProjection(fov_x=90.0)
perspective_viewport = Viewport(screen=screen,
                                projection=perspective,
                                stimuli=[drum])

flat_viewport = Viewport(screen=screen, stimuli=[fixation_spot])

p = Presentation(viewports=[perspective_viewport, flat_viewport])
gui_window = DrumGui(idle_func=p.between_presentations)

p.add_controller(
    fixation_spot, 'on',
    FunctionController(during_go_func=lambda t: gui_window.fixation_spot.get(),
                       eval_frequency=Controller.TRANSITIONS))
p.add_controller(
    p, 'go_duration',
    FunctionController(during_go_func=lambda t:
                       (gui_window.duration.get(), 'seconds'),
                       eval_frequency=Controller.TRANSITIONS))
p.add_controller(
    drum, 'angular_position',
    FunctionController(during_go_func=gui_window.positionFunction))
p.add_controller(
    drum, 'contrast',
    FunctionController(during_go_func=gui_window.contrastFunction))

gui_window.mainloop()
    def switch_level(self):

        if self.use_ErrP_detection and self._ErrP_classifier:
            self._ve_feedback_ErrP.set(on=True)
            self._show_feedback(True)
            self._presentation.set(go_duration=(self.feedback_ErrP_duration,
                                                'seconds'))
            self._presentation.go()
            self._ve_feedback_ErrP.set(on=False)
            self._show_feedback(False)
            return

        if self._current_level == 1:
            '''level 1: move classified letters to circles '''

            if self.level_2_animation:
                ## turn on all elements:
                for i in xrange(self._nr_elements):
                    self._ve_shapes[i].set(
                        on=self.level_2_shapes,
                        position=self._countdown_shape_positions[i])

                ## animate letters:
                def update(t):
                    dt = t / self.animation_time
                    self._viewport.parameters.stimuli = self._viewport.parameters.stimuli[:-(
                        self._nr_elements)]
                    feedback_letters = []
                    for i in xrange(self._nr_elements):
                        pos = (animate_sigmoid(
                            NP.add(self._letter_layout.positions[i],
                                   self._centerPos),
                            self._countdown_shape_positions[i], dt))
                        font_size = int(
                            round(
                                animate(self.font_size_level1,
                                        self.font_size_level2, dt)))
                        color = (self.level_2_letter_colors and list(
                            animate(self.letter_color, self.stimuli_colors[i],
                                    dt)) or self.letter_color)
                        text = (
                            i == self._nr_elements - 1 and self.backdoor_symbol
                            or self.letter_set[self._classified_element][i])
                        feedback_letters.append(
                            Text(position=pos,
                                 color=color,
                                 font_size=font_size,
                                 text=text,
                                 anchor="center"))
                        self._viewport.parameters.stimuli.extend(
                            feedback_letters)
                    if self.feedback_show_shape_at_center:
                        pos = animate_sigmoid(
                            self._centerPos, self._countdown_shape_positions[
                                self._classified_element], dt)
                        self._ve_shapes[self._classified_element].set(
                            position=pos)

                # send to screen:
                self._viewport.parameters.stimuli.extend([None] *
                                                         (self._nr_elements))
                self._presentation.set(go_duration=(self.animation_time,
                                                    'seconds'))
                self._presentation.add_controller(
                    None, None, FunctionController(during_go_func=update))
                self._presentation.go()
                self._presentation.remove_controller(None, None, None)
                self._viewport.parameters.stimuli = self._viewport.parameters.stimuli[:-(
                    self._nr_elements)]

                ## turn on level 2 letters:
                for i in xrange(self._nr_elements):
                    text = (i == self._nr_elements - 1 and self.backdoor_symbol
                            or self.letter_set[self._classified_element][i])
                    self._ve_letters[self._nr_letters + i].set(
                        on=True,
                        text=text,
                        position=self._countdown_letter_positions[
                            self._nr_letters + i])
            else:
                ## turn on all elements:
                self.set_standard_screen()

        else:
            ''' level 2: move classified letter to wordbox '''

            ## check if backdoor classified:
            if self._classified_letter >= len(
                    self.letter_set[self._classified_element]):
                text = self.backdoor_symbol
            else:
                text = self.letter_set[self._classified_element][
                    self._classified_letter]

            ## animate letter, but not if backdoor classified:
            if self._classified_letter < len(
                    self.letter_set[self._classified_element]):

                def update(t):
                    dt = t / self.animation_time
                    self._viewport.parameters.stimuli = self._viewport.parameters.stimuli[:
                                                                                          -1]
                    pos = animate_sigmoid(self._centerPos,
                                          self._current_letter_position, dt)
                    color = (self.level_2_letter_colors and list(
                        animate_sigmoid(
                            self.stimuli_colors[self._classified_letter],
                            self.current_letter_color, dt)) or list(
                                animate_sigmoid(self.letter_color,
                                                self.current_letter_color,
                                                dt)))
                    font_size = int(
                        round(
                            animate(self.font_size_level2,
                                    self.font_size_current_letter, dt)))
                    self._viewport.parameters.stimuli.append(
                        Text(position=pos,
                             color=color,
                             font_size=font_size,
                             text=text,
                             anchor='center'))

                # send to screen:
                self._viewport.parameters.stimuli.append(None)
                self._presentation.set(go_duration=(self.animation_time,
                                                    'seconds'))
                self._presentation.add_controller(
                    None, None, FunctionController(during_go_func=update))
                self._presentation.go()
                self._presentation.remove_controller(None, None, None)
                self._viewport.parameters.stimuli = self._viewport.parameters.stimuli[:
                                                                                      -1]
            else:
                self._presentation.set(go_duration=(self.animation_time,
                                                    'seconds'))
                self._presentation.go()

        ## turn off feedback box:
        self._ve_feedback_box.set(on=False)
示例#15
0
        print color

        if block == "overlapping":
            phase = ""
            fname = "%s_%s_%s_%s_%s_OL.bmp" % (ratio, n1, color, size,
                                               exemplar)

            t = Texture(Image.open(os.path.join(stimLib, fname)))
            s = TextureStimulus(texture=t, position=(x, y), anchor='center')
            texture_object = s.parameters.texture.get_texture_object()
            v = Viewport(screen=screen, stimuli=[s])
            p = Presentation(go_duration=('forever', ), viewports=[v])
            p.add_controller(
                None, None,
                FunctionController(during_go_func=put_image_overlapping,
                                   temporal_variables=TIME_SEC_ABSOLUTE))
            p.parameters.handle_event_callbacks = [(pygame.locals.KEYDOWN,
                                                    keyFunc)]
            p.go()

        else:
            if side == "large":
                fname1 = "%s_%s_%s_%s_%s_S2.bmp" % (ratio, n1, color, size,
                                                    exemplar)
                fname2 = "%s_%s_%s_%s_%s_S1.bmp" % (ratio, n1, color, size,
                                                    exemplar)
            else:
                fname1 = "%s_%s_%s_%s_%s_S1.bmp" % (ratio, n1, color, size,
                                                    exemplar)
                fname2 = "%s_%s_%s_%s_%s_S2.bmp" % (ratio, n1, color, size,
                                                    exemplar)
示例#16
0
    ))

other_text = []
other_text.append(
    Text(
        text='Pixel positions (x,y) calculated from 3D coordinates',
        position=(screen.size[0] / 2, screen.size[1]),
        anchor='top',
    ))

other_text.append(Text(
    text='----> x',
    position=(10, 10),
    anchor='left',
))

other_text.append(
    Text(
        text='----> y',
        angle=90.0,
        position=(10, 10),
        anchor='left',
    ))

viewport2D.parameters.stimuli = vertex_labels + other_text

p = Presentation(go_duration=(10.0, 'seconds'),
                 viewports=[viewport3D, viewport2D])
p.add_controller(None, None, FunctionController(during_go_func=update))
p.go()
示例#17
0
文件: exp.py 项目: jeffzemla/oft_exp
                                                  & pygame.locals.KMOD_LCTRL):
        p.parameters.go_duration = (
            0, 'frames')  # Quit presentation 'p' with LEFT CTRL + ESC


#######################
#  Define controllers #
#######################
###### Create an instance of the Controller class
trigger_in_controller = KeyboardTriggerInController(pygame.locals.K_5)

stimulus_on_controller = ConstantController(during_go_value=1,
                                            between_go_value=0)
stimulus_off_controller = ConstantController(during_go_value=0,
                                             between_go_value=1)
fixation_controller = FunctionController(during_go_func=setFixation)
dot_controller = FunctionController(during_go_func=setDots)
coherence_controller = FunctionController(during_go_func=setCoherence)
direction_controller = FunctionController(during_go_func=setDirection)
inst_controller = FunctionController(during_go_func=changeInstructions)
inst_on_controller = FunctionController(during_go_func=setInstructions)
inst3_on_controller = FunctionController(during_go_func=setTimeOn)
inst3_position_controller = FunctionController(during_go_func=setTimePos)
fixation_texture_controller = FunctionController(
    during_go_func=setFixationTexture)
samplefix_controller = FunctionController(during_go_func=setSampleFix)

state_controller = FunctionController(during_go_func=getState)

#######################################################
#  Connect the controllers with objects they control  #
示例#18
0
projection2 = SimplePerspectiveProjection(fov_x=55.0,
                                          aspect_ratio=(float(mid_x)/screen.size[1]))

camera_matrix = ModelView() # Parameters set in realtime, so no need to specify here

# Get a texture
filename = os.path.join(config.VISIONEGG_SYSTEM_DIR,"data","panorama.jpg")
texture = Texture(filename)

stimulus = SpinningDrum(texture=texture,shrink_texture_ok=1)
viewport1 = Viewport(screen=screen,
                     position=(0,0),
                     anchor='lowerleft',
                     size=(mid_x,screen.size[1]),
                     projection=projection1,
                     stimuli=[stimulus])
viewport2 = Viewport(screen=screen,
                     position=(mid_x,0),
                     anchor='lowerleft',
                     size=(mid_x,screen.size[1]),
                     projection=projection2,
                     camera_matrix=camera_matrix,
                     stimuli=[stimulus])

p = Presentation(go_duration=(10.0,'seconds'),viewports=[viewport1,viewport2])

p.add_controller(stimulus,'angular_position', FunctionController(during_go_func=angle_as_function_of_time))
p.add_controller(camera_matrix,'matrix', FunctionController(during_go_func=cam_matrix_f))

p.go()
示例#19
0
texture_object = stimulus.parameters.texture.get_texture_object()


def update_movie():
    # While movie.play() decompresses the movie to pygame surface
    # in a separate thread, this sends the data to OpenGL.
    texture_object.put_sub_image(pygame_surface)


viewport = Viewport(screen=screen, stimuli=[stimulus, text])

p = Presentation(
    go_duration=('forever', ),
    viewports=[viewport],
    handle_event_callbacks=[(pygame.locals.QUIT, quit),
                            (pygame.locals.KEYDOWN, keydown)],
)

p.add_controller(
    None, None,
    FunctionController(during_go_func=update_movie,
                       temporal_variables=TIME_INDEPENDENT))

movie.play()
#p.go()
import cProfile, pstats
cProfile.run('p.go()', 'mpeg_profile')
p = pstats.Stats('mpeg_profile')
p.sort_stats('cumulative')
p.print_stats()
示例#20
0
import math, os

max_speed = 100.0  # degrees per second


def angle_as_function_of_time(t):
    return max_speed * math.cos(t)


def contrast_as_function_of_time(t):
    return abs(math.cos(2 * math.pi * t * 0.2))


filename = os.path.join(config.VISIONEGG_SYSTEM_DIR, "data", "panorama.jpg")
texture = Texture(filename)

screen = get_default_screen()
projection = SimplePerspectiveProjection(fov_x=90.0)
stimulus = SpinningDrum(texture=texture, shrink_texture_ok=1)
viewport = Viewport(screen=screen,
                    size=screen.size,
                    projection=projection,
                    stimuli=[stimulus])
p = Presentation(go_duration=(10.0, 'seconds'), viewports=[viewport])
p.add_controller(stimulus, 'angular_position',
                 FunctionController(during_go_func=angle_as_function_of_time))
p.add_controller(
    stimulus, 'contrast',
    FunctionController(during_go_func=contrast_as_function_of_time))
p.go()
示例#21
0
def showTargets(viewport):
 global imageCounter
 global previous_t
 global numImsPerBlock
 global texture_object
 global curImList
 global presentationFreq    # use/update the global value for presetnation frequency
 global doingTraining
 global ctrl_key

 ctrl_key = 0
 doingTraining = 0

 Pfreq_default = presentationFreq

 
 SDL_Maximize()
                
 #
 # Show instructures
 #

 sttext = "You will be shown examples of target images... press space bar"
 statisticsText = Text( text = sttext, position = (screen.size[0]/2.0,screen.size[1]/2), font_name=fname,font_size = fsize,
                      anchor = 'center', color = (0.0,0.0,0.0,1.0))
      
   
 p.parameters.go_duration = ('forever',)
 viewport.parameters.stimuli=[statisticsText]
 p.go()

 
 while (1):
   imageCounter = 0
   previous_t = 0;
   block_idx = 0
   numTargets = 20
   numNontargets = 0
   presentationFreq = 5   # show 1 target every second to familiarize the user with the target set.
   
   
   # Load training block
#   curList = sampleTrainImages(trainPath,numTargets,numNontargets,alreadySampled,withreplacement)

   if (input_from == 1):
     curList = sampleTrainImages(trainPath,numTargets,numNontargets,alreadySampled,withreplacement)
   elif (input_from == 2):
     curList = sampleTrainImagesXML(inputXMLfile,numTargets,numNontargets)
   else:
     msgbox('The input type specified is invalid, check the value of input_from parameter in configuration.ini file.\n Terminating RSVP session.')  
     my_logger.error('The input type specified is invalid, check the value of input_from parameter in configuration.ini file.')
     break;

   curImList = map(operator.itemgetter(0),curList)
   curTargList = map(operator.itemgetter(1),curList)
   curImPath = map(operator.itemgetter(2),curList)
   curImName = map(operator.itemgetter(3),curList)
   numImsPerBlock = len(curImList)
   
   # fixation cross
   p.parameters.go_duration = (1,'seconds')
   viewport.parameters.stimuli=[fixPt]

   p.go()

   imageStim = TextureStimulus(texture=imageTex,
                               position = (screen.size[0]/2.0,screen.size[1]/2.0),
                               anchor='center', size=(width*scale,height*scale),
                               mipmaps_enabled = 0, texture_min_filter=gl.GL_LINEAR)

   texture_object = imageStim.parameters.texture.get_texture_object()
   texture_object.put_sub_image( curImList[0] )
   p.add_controller(None, None, FunctionController(during_go_func=every_frame_func) )
   p.parameters.go_duration = (2*(numImsPerBlock+1)/float(presentationFreq),'seconds')
   viewport.parameters.stimuli=[imageStim]
   p.go();
   block_idx = block_idx + 1



   # fixation cross
   p.parameters.go_duration = (2,'seconds')
   p.controllers = []
   viewport.parameters.stimuli=[fixPt]
   p.go()

   #
   # Show instructures
   #
   
   response = ynbox(msg='Would you like to see these targets again?', title=' ', choices=('No', 'Yes'), image=None) # default No
   
   SDL_Maximize()
   
   if (response == 1):
     presentationFreq = Pfreq_default 
     break
示例#22
0
文件: samar.py 项目: unshur/OpenPsyc
		fname2 = "%s_%s_%s_%s_%s_S2.bmp" % (ratio, n1, color, size, exemplar)
		
	####
	t1 = Texture(Image.open(os.path.join(stimLib,fname1)))
	t2 = Texture(Image.open(os.path.join(stimLib,fname2)))
	
	phase = ""
	s1 = TextureStimulus(texture = t1, position = (x, y), anchor = 'center')
	s2 = TextureStimulus(texture = t2, position = (x * 3, y), anchor = 'center')	

	texture_object1 = s1.parameters.texture.get_texture_object()
	texture_object2 = s2.parameters.texture.get_texture_object()

	v = Viewport(screen=screen, stimuli=[s1,s2])
	p = Presentation(go_duration=('forever', ), viewports=[v])
	p.add_controller(None, None, FunctionController(during_go_func=put_image_dual, temporal_variables = TIME_SEC_ABSOLUTE))

	if response == "voice":
		p.parameters.handle_event_callbacks=[(pygame.locals.MOUSEBUTTONDOWN, mouseGrade), (pygame.locals.KEYDOWN, quitHandler)]
	else:
		p.parameters.handle_event_callbacks=[(pygame.locals.MOUSEBUTTONDOWN, mouseFunc), (pygame.locals.KEYDOWN, quitHandler)]

	p.go()
	
	if response == "voice":
		sub.inputData(trial, "misfire", misfire)


	if trial % break_trial == 0 and trial != trials:
		print trial, "BREAK TIME"
		experiments.showImage(screen, os.path.join(basePath, "break.BMP"), 0)
示例#23
0
        s = s[:-3]
    return s + ','.join(reversed(groups))


def func(xvalues, k):
    return 1 / (1 + (xvalues * k))


### CONTROLLERS

trigger_in_controller = KeyboardTriggerInController(pygame.locals.K_5)
stimulus_on_controller = ConstantController(during_go_value=1,
                                            between_go_value=0)
stimulus_off_controller = ConstantController(during_go_value=0,
                                             between_go_value=1)
left_choice_controller = FunctionController(during_go_func=replaceLeftText)
right_choice_controller = FunctionController(during_go_func=replaceRightText)
left_choice2_controller = FunctionController(during_go_func=replaceLeftText2)
right_choice2_controller = FunctionController(during_go_func=replaceRightText2)
state_controller = FunctionController(during_go_func=getState)
fixation_controller = FunctionController(during_go_func=controlFix,
                                         between_go_func=hideStim)
newset_controller = FunctionController(during_go_func=showNewSet,
                                       between_go_func=hideStim)
taskend_controller = FunctionController(during_go_func=showTaskEnd)

p.add_controller(p, 'trigger_go_if_armed', trigger_in_controller)
p.add_controller(title, 'on', stimulus_off_controller)
p.add_controller(title2, 'on', stimulus_off_controller)
p.add_controller(left_choice, 'on', stimulus_on_controller)
p.add_controller(right_choice, 'on', stimulus_on_controller)
示例#24
0

# define target position as a function of time
def get_target_position(t):
    global mid_x, mid_y, max_vel
    return (
        max_vel * sin(0.1 * 2.0 * pi * t) + mid_x,  # x
        max_vel * sin(0.1 * 2.0 * pi * t) + mid_y)  # y


def get_drum_angle(t):
    return 50.0 * math.cos(0.2 * 2 * math.pi * t)


# Create instances of the Controller class
target_position_controller = FunctionController(
    during_go_func=get_target_position)
drum_angle_controller = FunctionController(during_go_func=get_drum_angle)

#############################################################
#  Connect the controllers with the variables they control  #
#############################################################

p.add_controller(target, 'position', target_position_controller)
p.add_controller(drum, 'angular_position', drum_angle_controller)

#######################
#  Run the stimulus!  #
#######################

p.go()
示例#25
0
        right = 0
    elif event.key == pygame.locals.K_LEFT:
        left = 0


# Create an instance of the Presentation class.  This contains the
# the Vision Egg's runtime control abilities.
p = Presentation(go_duration=('forever', ), viewports=[viewport])


def quit(event):
    p.parameters.go_duration = (0, 'frames')


p.parameters.handle_event_callbacks = [(pygame.locals.QUIT, quit),
                                       (pygame.locals.KEYDOWN, keydown),
                                       (pygame.locals.KEYUP, keyup)]

#############################################################
#  Connect the controllers with the variables they control  #
#############################################################

p.add_controller(None, None,
                 FunctionController(during_go_func=every_frame_func))

#######################
#  Run the stimulus!  #
#######################

p.go()
示例#26
0
    lumina_dev.poll_for_response()
    while lumina_dev.response_queue_size() > 0:
        response = lumina_dev.get_next_response()
        if response['key'] == 4:
            lumina_dev.clear_response_queue()
            print "TRIGGER RECEIVED!"
            return 1
    return 0


#######################
#  Define controllers #
#######################
###### Create an instance of the Controller class
if LUMINA == 1:
    trigger_in_controller = FunctionController(during_go_func=return_one, \
        between_go_func=lumina_trigger)
else:
    trigger_in_controller = KeyboardTriggerInController(pygame.locals.K_5)

stimulus_on_controller = ConstantController(during_go_value=1, \
                           between_go_value=0)
stimulus_off_controller = ConstantController(during_go_value=0, \
                           between_go_value=1)
state_controller = FunctionController(during_go_func=getState)
target_location_controller = FunctionController( \
                           during_go_func=get_line_location)
right_label_controller = FunctionController(during_go_func=myRightLabel)
left_label_controller = FunctionController(during_go_func=myLeftLabel)
task_controller = FunctionController(during_go_func=myFixation)
arrow_direction_controller = FunctionController( \
                           during_go_func=get_arrow_direction)
   # indicate begining of a block
   sendCommand(beginBlock,0)
   p.go()

   #par.setData(fixationOnOffTrig)
   #time.sleep(.001)

   imageStim = TextureStimulus(texture=imageTex,
                               position = (screen.size[0]/2.0,screen.size[1]/2.0),
                               anchor='center', size=(width*scale,height*scale),
                               mipmaps_enabled = 0, texture_min_filter=gl.GL_LINEAR)

   texture_object = imageStim.parameters.texture.get_texture_object()
              
   texture_object.put_sub_image( curImList[0] )
   p.add_controller(None, None, FunctionController(during_go_func=every_frame_func) )
#   p.parameters.go_duration = ((numImsPerBlock + 1)/float(presentationFreq),'seconds')
   p.parameters.go_duration = (3*(numImsPerBlock + 1)/float(presentationFreq),'seconds') # DJ: Why *3?
   viewport.parameters.stimuli=[imageStim]
   p.go();
   if (run_as_standalone == 0):
      par.setData(0)

   # indicate the results
   sendCommand(endBlock,0)
   internalState = 0

   # fixation cross
   p.parameters.go_duration = (1,'seconds')
   p.controllers = []
   viewport.parameters.stimuli=[fixPt]
    def set_countdown_screen(self):
        '''
        set screen how it should look during countdown.
        '''
        if self._countdown_screen:
            return

        self._countdown_screen = True
        is_level1 = self._current_level == 1

        ## turn on visible elements:
        for i in xrange(self._nr_elements):  # shapes
            self._ve_shapes[i].set(on=is_level1 or self.level_2_shapes)

        for i in xrange(self._nr_letters):  # level 1 letters
            self._ve_letters[i].set(on=is_level1)

        for i in xrange(len(
                self.letter_set[self._classified_element])):  # level 2 letters
            self._ve_letters[self._nr_letters + i].set(
                on=not is_level1,
                text=(is_level1 and " "
                      or self.letter_set[self._classified_element][i]))

        self._ve_letters[self._nr_letters + self._nr_elements - 1].set(
            on=not is_level1, text=(is_level1 and " " or self.backdoor_symbol))

        ## move all elements with their letters to countdown position:
        def update(t):
            dt = t / self.animation_time
            for i in xrange(self._nr_elements):
                pos = animate_sigmoid(self._centerPos,
                                      self._countdown_shape_positions[i], dt)
                self._ve_shapes[i].set(position=pos)  # shapes
                self._ve_letters[self._nr_letters + i].set(
                    position=pos)  # level 2 letters
            for i in xrange(self._nr_letters):
                pos = animate_sigmoid(self._letter_positions[i],
                                      self._countdown_letter_positions[i], dt)
                self._ve_letters[i].set(position=pos)  # level 1 letters

        def update2(t):  # if not do animation
            for i in xrange(self._nr_elements):
                self._ve_shapes[i].set(
                    position=self._countdown_shape_positions[i])  # shapes
                self._ve_letters[self._nr_letters + i].set(
                    position=self._countdown_shape_positions[i]
                )  # level 2 letters
            for i in xrange(self._nr_letters):
                self._ve_letters[i].set(
                    position=self._countdown_letter_positions[i]
                )  # level 1 letters

        if self.do_animation:
            self._presentation.set(go_duration=(self.animation_time,
                                                'seconds'))
            self._presentation.add_controller(
                None, None, FunctionController(during_go_func=update))
        else:
            self._presentation.set(go_duration=(0, 'seconds'))
            self._presentation.add_controller(
                None, None, FunctionController(during_go_func=update2))

        # send to screen:
        self._presentation.go()
        self._presentation.remove_controller(None, None, None)

        for i in xrange(self._nr_elements):
            self._ve_shapes[i].set(position=self._countdown_shape_positions[i])
            self._ve_letters[self._nr_letters + i].set(
                position=self._countdown_shape_positions[i])
        for i in xrange(self._nr_letters):
            self._ve_letters[i].set(
                position=self._countdown_letter_positions[i])