Last active
August 29, 2015 14:02
-
-
Save lindemann09/5bed85d002bcbd6641a5 to your computer and use it in GitHub Desktop.
Tracking mouse trajectory
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
"""Drag and drop | |
Example how to track mouse trajectories under Expyriment by Florian Krause | |
""" | |
from expyriment import control, stimuli | |
control.set_develop_mode(True) | |
exp = control.initialize() | |
exp.mouse.show_cursor() | |
rect = stimuli.Rectangle(size=(100, 100), colour=(255, 0, 0)) | |
rect.preload() | |
rect.present() | |
erase = stimuli.Rectangle(size=(100, 100), colour=(0, 0, 0)) | |
erase.preload() | |
trajectories = [] | |
last_x, last_y = 0, 0 | |
while True: | |
exp.keyboard.check() | |
event, pos, rt = exp.mouse.wait_press() | |
if rect.overlapping_with_position(pos): | |
trajectories.append([]) | |
while exp.mouse.pressed_buttons[0]: | |
x, y = exp.mouse.position | |
trajectories[-1].append((x, y)) | |
if x != last_x or y != last_y: | |
erase.position = rect.position | |
rect.position = (x, y) | |
erase.present(clear=False, update=False) | |
rect.present(clear=False, update=False) | |
exp.screen.update_stimuli([erase, rect]) | |
print trajectories[-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment