Created
May 16, 2012 09:33
-
-
Save smathot/2709074 to your computer and use it in GitHub Desktop.
OpenSesame script to draw mouse cursor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from openexp.mouse import mouse | |
from openexp.canvas import canvas | |
# Uncomment for 0.25 and earlier | |
# exp = self.experiment | |
# The name of the sketchpad item to draw the cursor on | |
src_sketchpad = 'my_sketchpad' | |
# The size of the cursor crosshair | |
cross_size = 8 | |
# Create a mouse and canvas object | |
my_mouse = mouse(exp) | |
my_canvas = canvas(exp) | |
# Use the onset of the source sketchpad as the start of the response | |
# interval | |
start_time = self.get('time_%s' % src_sketchpad) | |
# Wait for a response | |
while True: | |
button, position, timestamp = my_mouse.get_click(timeout=20) | |
if button != None: | |
break | |
pos, time = my_mouse.get_pos() | |
my_canvas.copy(exp.items[src_sketchpad].canvas) | |
my_canvas.line(pos[0], pos[1]-cross_size, pos[0], pos[1]+cross_size) | |
my_canvas.line(pos[0]-cross_size, pos[1], pos[0]+cross_size, pos[1]) | |
my_canvas.show() | |
# Determine response, rt, and correct | |
response = button | |
response_time = timestamp-start_time | |
correct = 1 | |
# Maintain feedback variables. This ensures that | |
# you can use the feedback item as usual | |
exp.set('response_time', response_time) | |
exp.set('response', response) | |
exp.set('correct', correct) | |
exp.set('cursor_x', pos[0]) | |
exp.set('cursor_y', pos[1]) | |
exp.total_responses += 1 | |
exp.total_correct += correct | |
exp.total_response_time += response_time | |
exp.acc = 100. * exp.total_correct / exp.total_responses | |
exp.avg_rt = exp.total_response_time / exp.total_responses | |
exp.accuracy = exp.acc | |
exp.average_response_time = exp.avg_rt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment