Hi everyone,
I’m new to coding and need to create an approach-avoidance-task on Psychopy:
Participants should drag images towards them or push them away depending on the format of the image (landscape vs. portrait). There’s an old thread about a similar question but they weren’t using different formats, so unfortunatley it didn’t help me to solve my problem.
If I’m using the following code, it kind of works:
( I’f written the paramter formatheight (with (0.4, 0.5) for landscape and (0.5, 0.4 for portrait) into the xlxs-file, where the stimuli are defined and defined the size of the image as $formatheight)
#Start Routine
TestMousePosition = 0
TestMouse.setPos((0, 0))
ImageSizeX = formatheight[0]
ImageSizeY = formatheight[1]
ImageRatio = ImageSizeX / ImageSizeY
#Each Frame
TestMousePosition = TestMouse.getPos()[1]
if ImageRatio < 1:
if TestMousePosition > 0:
ImageSizeX += .008
ImageSizeY += .01
elif TestMousePosition < 0:
ImageSizeX -= .008
ImageSizeY -= .01
elif ImageRatio > 1:
if TestMousePosition > 0:
ImageSizeY += .008
ImageSizeX += .01
elif TestMousePosition < 0:
ImageSizeY -= .008
ImageSizeX -= .01
if (ImageSizeY >= 0) and (ImageSizeX >= 0):
TestImage.size = (ImageSizeX, ImageSizeY)
else:
TestImage.size = (0, 0)
Like this, the images do change their size with mouse-movements on the y-axis, they keep their formats while changing sizes and they don’t get flipped around, when the size-paramters turn negative.
I’d like to advance the code so that the size change of the image ist proportional to the amount of mouse movement. I’ve tried the following code, but it doesn’t provide me with any size changes (i’ve tried running it through visual study code and there I get the result I want):
#Begin Routine
TestMousePosition = 0
TestMouse.setPos((0, 0))
ImageSizeX = formatheight[0]
ImageSizeY = formatheight[1]
ImageRatio = ImageSizeX / ImageSizeY
MouseAnchor = 0
#Each frame:
TestMousePosition = TestMouse.getPos()[1]
MouseDifference = int(round(abs(MouseAnchor - TestMousePosition) / 0.1))
if ImageRatio < 1:
if TestMousePosition > 0:
for n in range(MouseDifference):
ImageSizeX += .004
ImageSizeY += .005
elif TestMousePosition < 0:
for n in range(MouseDifference):
ImageSizeX -= .004
ImageSizeY -= .005
elif ImageRatio > 1:
if TestMousePosition > 0:
for n in range(MouseDifference):
ImageSizeY += .004
ImageSizeX += .005
elif TestMousePosition < 0:
for n in range(MouseDifference):
ImageSizeY -= .004
ImageSizeX -= .005
if (ImageSizeY >= 0) and (ImageSizeX >= 0):
TestImage.size = (ImageSizeX, ImageSizeY)
else:
TestImage.size = (0, 0)
MouseAnchor = TestMousePosition
I’d be really greatful for help!
Laura