Advertisement
Guest User

Untitled

a guest
Feb 20th, 2014
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. GetClicks (Run phase)
  2.  
  3. from openexp.mouse import mouse
  4. from math import sqrt
  5. # Create a mouse object
  6. my_mouse = mouse(exp, visible=True)
  7. # Define all valid target positions
  8. coords= [[+184, +130], [-100, +172], [+271, -222], [+287, +39], [-87, -39] ]
  9. Words= ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
  10. # The maximum distance in pixels that a click can be from a target position
  11. max_err = 10
  12. # The number of clicks to collect
  13. max_click = 4
  14. # Loop until we have collected all clicks
  15. n_click = 0
  16. #Centre coordinates
  17. xc= self.get('width')/2
  18. yc= self.get('height')/2
  19. while n_click < max_click:
  20. # Get a click and extract the position
  21. button, position, timestamp = my_mouse.get_click()
  22. cursor_x, cursor_y = position
  23. # Walk through all target positions to check if the click was on a target
  24. for xvar, yvar in coords:
  25. err = sqrt((xvar+xc-cursor_x)**2+(yvar+yc-cursor_y)**2)
  26. if err <= max_err:
  27. # If the click was on a target, set the click coordinates, find the word and
  28. # decrease the number of clicks that we still need to collect
  29. exp.set('click_%d_x' % n_click, xvar)
  30. exp.set('click_%d_y' % n_click, yvar)
  31. exp.set ('click_%d_word' % n_click, Wordvar)
  32. n_click += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement