Hi Michael,
Sure! Here is the code:
Thank you very much for your help!
Best,
Jason
from __future__ import absolute_import, division, print_function
from psychopy import locale_setup
from psychopy import sound, gui, visual, core, data, event, logging, clock
import numpy as np # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle
import os # handy system and path functions
import sys # to get file system encoding
from psychopy.hardware import keyboard
from psychopy.iohub import launchHubServer
_thisDir = os.path.dirname(os.path.abspath(__file__))
os.chdir(_thisDir)
# Store info about the experiment session
psychopyVersion = '3.2.4'
expName = 'Mouse-tracking-study' # from the Builder filename that created this script
expInfo = {'participant': '', 'session': '001'}
dlg = gui.DlgFromDict(dictionary=expInfo, sortKeys=False, title=expName)
if dlg.OK == False:
core.quit() # user pressed cancel
expInfo['date'] = data.getDateStr() # add a simple timestamp
expInfo['expName'] = expName
expInfo['psychopyVersion'] = psychopyVersion
filename = _thisDir + os.sep + u'data/%s_%s_%s' % (expInfo['participant'], expName, expInfo['date'])
# An ExperimentHandler isn't essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName, version='',
extraInfo=expInfo, runtimeInfo=None,
originPath='/Users/gongxuanjun/OneDrive - University of California, Davis/projects/mouse_tracking/psychopy/mouse_tracking.py',
savePickle=True, saveWideText=True,
dataFileName=filename)
# save a log file for detail verbose info
logFile = logging.LogFile(filename + '.log', level=logging.EXP)
logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file
win = visual.Window(
size=(1024, 768), fullscr=True, screen=0,
winType='pyglet', allowGUI=False, allowStencil=False,
monitor='testMonitor', color=[0, 0, 0], colorSpace='rgb',
blendMode='avg', useFBO=True,
units='height')
thisExp.addData('exp_session', "mouse-tracking")
fixSpot = visual.Circle(win,
pos=(0, 0), radius=0.01, color='black') # set cursor stimuli
myMouse = event.Mouse(visible=False) # will use win by default
globalClock = core.Clock()
trialTimer = core.Clock()
# check fps
frame_rate = win.getActualFrameRate(nIdentical=60, nMaxFrames=100,
nWarmUpFrames=10, threshold=1)
# set mouse position and reset trialTimer
count = 0
for i in range(1, 4):
count += 1
thisExp.nextEntry()
thisExp.addData('count', count)
myMouse.setPos(newPos=[0, 0])
trialTimer.reset()
while trialTimer.getTime() <= 3:
# get mouse events
fixSpot.setPos(myMouse.getPos())
# drawing cursor
fixSpot.draw()
# saving data
thisExp.nextEntry()
thisExp.addData('position_cursor_x', fixSpot.pos[0])
thisExp.addData('position_cursor_y', fixSpot.pos[1])
event.clearEvents()
win.flip()