I am working on an experimental design and code for a psychopy/python course. I am very new to coding, so excuse any jargon mistakes.
Design: Where's Waldo search experiment. Between-subjects, IDV: manipulates the size of the image to reduce visual noise (i.e. cropped = smaller image size = smaller search area)
- Image size by group: G1: full-size; G2: 2/3 size; G3: 1/3 size
- DV Measures: time to find Waldo, click accuracy (True v. False guesses)
I have a test script that I am using to identify the (x,y) coordinates of 'click-points' so I can define the coordinates of Waldo’s hiding spot within each image. I will use image-coordinate pairings to define True response within experimental conditions.
- Here: ‘click-point’ = Waldo's location in the image
Once I have these coordinates, I intend to write some For loops with an If Boolean statement code for the mouse clicks:
click == found (Waldo's coordinates in the image) == True == next trial
click == miss (not Waldo's coordinates) == False == try again
Here: ‘click-point’ = coordinates within the image related to the participant's guess
Currently, I have my test script collecting a mouse location. However, it is tracking location based on where the mouse's initial position is within the window instead of where I click.
Question: Do you know how to get it to track location at the ‘click-point’ instead of its first identified position within the window?
#figuring out how to define a mouse click location in an image object
#=====================
#IMPORT SETTINGS
#=====================
from psychopy import visual, event
import numpy as np
import os
#=====================
#PATH SETTINGS
#=====================
main_dir = os.getcwd()
data_dir = os.path.join(main_dir,'experimentData')
image_dir = os.path.join(main_dir, 'images')
#=====================
#WINDOW SETTINGS
#=====================
win = visual.Window(units='norm', size= [1000,642], fullscr=None)
#=====================
#STIMULUS SETTINGS
#=====================
waldoImage = visual.ImageStim(win, size=2, interpolate=True) #interpolate >> helping with blurry image??
waldoImage.image = os.path.join(image_dir, 'wallpaperflare.com_wallpaper (2).jpg') #original size = 1920 x 1233 px
mouse = event.Mouse()
x = visual.TextStim(win, text='x', color='black')
findWaldo = np.array([]) #Waldo locations list
waldoImage.draw()
win.flip()
if mouse.getPressed(waldoImage):
# if mouse.isPressedIn(waldoImage): #tried this instead, but did not work
loc = mouse.getPos() #location = mouse starting point in the window, not where moved to and clicked
findWaldo = np.append(findWaldo, loc)
event.waitKeys() # just to help control flow for testing
# test coordinates of collected location
waldoImage.draw()
x.pos = findWaldo
x.draw() # at collected mouse coordinates
win.flip()
event.waitKeys() # just to help control flow for testing
win.close()
print(findWaldo) # testing coordinate collection is working