Ejemplo n.º 1
0
def present_trial(imagepath):
	"""
	This is the main function used to run this demo. It is fed an imagepath and uses this to create a CommandableImageSprite offscreen. This Sprite is later moved onto the screen, where it hangs out until it is clicked.

	"""

	#create a tobii simulator
	tobii_sim = TobiiSimController(screen)

	#create a tobii sprite
	img = TobiiSprite( screen, spot.center, imagepath, tobii_sim, scale=IMAGE_SCALE)
	
	# this sets this sprite to follow eye gaze once it's first looked at
	img.enable_follow();
	
	# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
	# Set up the updates, etc. 
	
	# A queue of animation operations
	Q = DisplayQueue()
		
	# Draw a single animation in if you want!
	
	
	# What order do we draw sprites and things in?
	dos = OrderedUpdates(img) # Draw and update in this order
	
	## Note the start time...
	start_time = time()

	# start recording the "eye gaze" data
	tobii_sim.start_tracking()
	
	## The standard event loop in kelpy -- this loops infinitely to process interactions
	## and throws events depending on what the user does
	trial_time = 5.0
	for event in kelpy_standard_event_loop(screen, Q, dos, throw_null_events=True):
	
		#stay in the event loop until the trial time has passed
		if (time() - start_time > trial_time): 
			print "trial end"
			break

		#can check if the image is being looked at
		#img.is_following = img.is_looked_at()

		#have the sprite follow the "eye gaze"
		img.process_follow(event)
				
	#stop collecting "eye gaze" data
	tobii_sim.stop_tracking()
Ejemplo n.º 2
0
def present_trial(imagepath):
	"""
	The sprite in this trial will move around the screen based on eye gaze.

	"""
	## This is a TobiiSprite which has activated its Followable state (is_following = True)
	img = TobiiSprite( screen, spot.center, imagepath, tobii_controller, scale=IMAGE_SCALE)
	img.enable_follow();
		
	# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
	# Set up the updates, etc. 
	
	# A queue of animation operations
	Q = DisplayQueue()
	
	# Draw a single animation in if you want!		
	# Q.append(obj=img, action='darken', amount=0.5, duration=4.0)
	
	# What order do we draw sprites and things in?
	dos = OrderedUpdates(img) # Draw and update in this order
	
	#start tracking
	tobii_controller.start_tracking()
	
	start_time = time()
	
	## The standard event loop in kelpy -- this loops infinitely to process interactions
	## and throws events depending on what the user does
	for event in kelpy_standard_event_loop(screen, Q, dos, throw_null_events=True):
		
		#if (img.is_looked_at()):
		#		play_sound(sound_yup_path, wait=True, volume=7.0)
		#		break
		
		if( time() - start_time > MAX_DISPLAY_TIME): 
			break
		
		# If the event is a click:
		if is_click(event):
			break

		if event.type == QUIT:
			tobii_controller.close_data_file()
			tobii_controller.destroy()

		img.process_follow(event)
			
	tobii_controller.stop_tracking()	

	print img.get_look_time()
	duration = time() - start_time 
	print looking_proportions(dos, duration)
Ejemplo n.º 3
0
def present_trial(imagepath):
	"""
	This is the main function used to run this demo. It is fed an imagepath and uses this to create a CommandableImageSprite offscreen. This Sprite is later moved onto the screen, where it hangs out until it is clicked.

	"""
	## Images here are commandable sprites, so we can tell them what to do using Q below
	img = TobiiSprite( screen, spot.center, imagepath, tobii_controller, scale=IMAGE_SCALE)
	img.enable_follow()

	drum = DropSprite(screen, (609,407), kstimulus("common_objects/drum.png"), scale=IMAGE_SCALE)

	img.register_drag_zone(drum)

	images = [drum, img]

	# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
	# Set up the updates, etc. 
	
	# A queue of animation operations
	Q = DisplayQueue()
	
	# What order do we draw sprites and things in?
	dos = OrderedUpdates(images) # Draw and update in this order
	
	start_time = time()

	#start tracking
	tobii_controller.start_tracking()	
	
	## The standard event loop in kelpy -- this loops infinitely to process interactions
	## and throws events depending on what the user does
	for event in kelpy_standard_event_loop(screen, Q, dos, throw_null_events=True):

	# This also turns it off when the sprite it not looked at any longer.
		img.process_follow(event)   ## simple, right?

		if was_dragged_into_zone(event):  ## This is a function located in the EventHandler that watches for drag zone events.
			print "Nice Drumming!"
			play_sound(kstimulus("sounds/Button-Reverb.wav"))

		if event.type == QUIT:
			tobii_controller.close_data_file()
			tobii_controller.destroy()
				
		
	tobii_controller.stop_tracking()
Ejemplo n.º 4
0
def present_trial(objects, probabilities, trial,i, writer):
    start_time = time()
    in_right = False
    in_left = False
    left_box =  TobiiSprite( screen, spot.c1, kstimulus("misc/box.png"), tobii_controller, scale=BOX_SCALE)
    left_boxfront = TobiiSprite(screen, spot.c1, kstimulus("misc/boxfront.png"), tobii_controller,scale=BOX_SCALE)
    left_lid =  TobiiSprite( screen, LID_SPOT1, kstimulus("misc/lid.png"), tobii_controller,scale=BOX_SCALE)
    right_box = TobiiSprite(screen, spot.c4, kstimulus("misc/box.png"),tobii_controller, scale=BOX_SCALE)
    right_boxfront = TobiiSprite(screen, spot.c4, kstimulus("misc/boxfront.png"), tobii_controller,scale=BOX_SCALE)
    right_lid = TobiiSprite(screen, LID_SPOT2, kstimulus("misc/lid.png"),tobii_controller, scale=BOX_SCALE)
    left_object = TobiiSprite( screen, spot.c1, objects[0],tobii_controller, scale=IMAGE_SCALE)
    right_object = TobiiSprite(screen, spot.c4, objects[1],tobii_controller, scale=IMAGE_SCALE)


    #the boxes keep opening every when_open seconds, and object appearance is stochastic

    # A queue of animation operations
    Q = DisplayQueue()

    Q.append(obj=left_lid, action='wait', duration=1)
    Q.append(obj=right_lid, action='wait', duration=1)
    Q.append_simultaneous(obj=left_lid, action = 'move', pos=left_lid_MOVE, duration=0.25)
    Q.append_simultaneous(obj=right_lid, action='move', pos=right_lid_MOVE, duration=0.25)

    #with certain probability, reveal object:
    flip1 = random.random()
    if  flip1 < probabilities[0]:
        Q.append_simultaneous(obj=left_object, action='move', pos=spot.b1, duration=.5)
        in_left = True

    #with other probability, reveal object
    flip2 = random.random()
    
    if flip2 < probabilities[1]:
        Q.append_simultaneous(obj=right_object, action='move', pos=spot.b4, duration=.5)
        in_right = True

    Q.append(obj=left_object, action='wait', duration=.25)
    Q.append(obj=right_object, action='wait', duration=.25)

    Q.append(obj=left_lid, action='wait', duration=.25)
    Q.append(obj=right_lid, action='wait', duration=.25)

    Q.append_simultaneous(obj=left_object, action='move', pos=spot.c1, duration=.5)
    Q.append_simultaneous(obj=right_object, action='move', pos=spot.c4, duration=.5)
    Q.append_simultaneous(obj=left_lid, action='move', pos=LID_SPOT1,duration=.5)
    Q.append_simultaneous(obj=right_lid, action='move', pos=LID_SPOT2, duration=.5)

    Q.append(obj=left_object, action='move', pos=OFF_SOUTH, duration=0.0)
    Q.append(obj=right_object, action='move', pos=OFF_SOUTH, duration=0.0)

    # What order do we draw sprites and things in?
    dos = OrderedUpdates([left_box,left_object,left_boxfront, right_box,right_object,right_boxfront,left_lid,right_lid])  # Draw and update in this order

    #main ticker loop
    for event in kelpy_standard_event_loop(screen, Q, dos, throw_null_events=True):
    # output trial info to csv

        writer.writerow([subject, session, trial, i, start_time, time(), objects[0], probabilities[0], in_left, left_box.is_looked_at(), left_object.is_looked_at(), left_lid.is_looked_at(), objects[1],probabilities[1], in_right, right_box.is_looked_at(), right_object.is_looked_at(), right_lid.is_looked_at()])
        print file_header
        #print subject, session, trial, i, start_time, time(), objects[0], probabilities[0], in_left, left_box.is_looked_at(), left_object.is_looked_at(), left_lid.is_looked_at(), objects[1],probabilities[1], in_right, right_box.is_looked_at(), right_object.is_looked_at(), right_lid.is_looked_at()
        if (time() - start_time > MAX_DISPLAY_TIME):
            break

        # If the event is a click:
        #if is_click(event):
         #   break
		
    # need to do a check for exiting here
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                print("escaping now")
                quit()
                # make sure to close the data file when exiting, otherwise it'll hang
                if not use_tobii_sim:
                    tobii_controller.stop_tracking()
                    tobii_controller.close_data_file()
                    tobii_controller.destroy()
Ejemplo n.º 5
0
def open_box(object, box, probability, trial, writer, BGCOLOR, lookaway_start_time,TRIAL_START):
    print TRIAL_START
    pygame.display.set_mode((1400,900),pygame.FULLSCREEN)
    play_sound(kstimulus('music/hothothot.wav'))
    start_time = time()
    lookaway_time = 2.0

    started_looking_away = False
    screen.fill(BGCOLOR)
    box =  TobiiSprite( screen, spot.center, box, tobii_controller, scale=BOX_SCALE)
    object = TobiiSprite( screen, spot.south, object,tobii_controller, scale=IMAGE_SCALE)
    blankbox = TobiiSprite( screen, spot.center, '../../kelpy/stimuli/misc/blankbox.png', tobii_controller, scale=BOX_SCALE)

    Q = DisplayQueue()

    Q.append(obj=box, action='wait', duration=1)


    for i in range(1000):
        #with certain probability, reveal object:
        flip = random.random()
        #print flip
        if  flip < probability:
            Q.append_simultaneous(obj=object, action='move', pos=spot.center, duration=0)
            present = True
        Q.append(obj=box, action='move', pos=spot.north,duration=1)
        Q.append(obj=box, action='wait',duration=.25)
        Q.append(obj=box, action='move', pos=spot.center,duration=1)
        Q.append(obj=box, action='wait',duration=.25)
        Q.append_simultaneous(obj=object, action='move', pos=spot.north, duration=0)




    dos = OrderedUpdates([blankbox, object, box ])






    #main ticker loop
    for event in kelpy_standard_event_loop(screen, Q, dos, throw_null_events=True):
    # output trial info to csv
        pygame.draw.rect(screen,(0,0,0),((screen.get_width() /2 )-200, (screen.get_height() /2 )-200,400,400),4)
        pygame.draw.rect(screen,BGCOLOR,((screen.get_width() /2 )-200, (screen.get_height() /2 )-601,400,400),0)
        pygame.draw.rect(screen,BGCOLOR,((screen.get_width() /2 )-200, (screen.get_height() /2 )+201,400,400),0)
        pygame.display.update()
        #writer.writerow([subject, session, trial, i, start_time, time(), objects[0], probabilities[0], in_left, left_box.is_looked_at(), left_object.is_looked_at(), left_lid.is_looked_at(), objects[1],probabilities[1], in_right, right_box.is_looked_at(), right_object.is_looked_at(), right_lid.is_looked_at()])
        #print file_header
        #print subject, session, trial, i, start_time, time(), objects[0], probabilities[0], in_left, left_box.is_looked_at(), left_object.is_looked_at(), left_lid.is_looked_at(), objects[1],probabilities[1], in_right, right_box.is_looked_at(), right_object.is_looked_at(), right_lid.is_looked_at()
        if (time() - start_time > MAX_DISPLAY_TIME):
            break


        if not blankbox.is_looked_at():
            if not started_looking_away:
                lookaway_start_time = time()
                started_looking_away = True
                #check if they've looked away for long enough
            if (time() - lookaway_start_time > lookaway_time):
                final_time = time() - TRIAL_START
                print str(final_time) + "is final time!!!!!!!!!!!"
                break #or whatever else you need to do at the end of the trial

        elif blankbox.is_looked_at():
		    started_looking_away = False #resets timer
        # If the event is a click:
        #if is_click(event):
         #   break

    # need to do a check for exiting here
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                print("escaping now")
                quit()
                # make sure to close the data file when exiting, otherwise it'll hang
                if not use_tobii_sim:
                    tobii_controller.stop_tracking()
                    tobii_controller.close_data_file()
                    tobii_controller.destroy()
            if event.key == K_p:

                pygame.mixer.music.pause()
                sleep(3)
                pygame.mixer.music.unpause()