Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GetClicks (Run phase)
- from openexp.mouse import mouse
- from math import sqrt
- # Create a mouse object
- my_mouse = mouse(exp, visible=True)
- # Define all valid target positions
- coords= [[+184, +130], [-100, +172], [+271, -222], [+287, +39], [-87, -39] ]
- Words= ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
- # The maximum distance in pixels that a click can be from a target position
- max_err = 10
- # The number of clicks to collect
- max_click = 4
- # Loop until we have collected all clicks
- n_click = 0
- #Centre coordinates
- xc= self.get('width')/2
- yc= self.get('height')/2
- while n_click < max_click:
- # Get a click and extract the position
- button, position, timestamp = my_mouse.get_click()
- cursor_x, cursor_y = position
- # Walk through all target positions to check if the click was on a target
- for xvar, yvar in coords:
- err = sqrt((xvar+xc-cursor_x)**2+(yvar+yc-cursor_y)**2)
- if err <= max_err:
- # If the click was on a target, set the click coordinates, find the word and
- # decrease the number of clicks that we still need to collect
- exp.set('click_%d_x' % n_click, xvar)
- exp.set('click_%d_y' % n_click, yvar)
- exp.set ('click_%d_word' % n_click, Wordvar)
- n_click += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement