psychopy.org | Reference | Downloads | Github

Zoom on any part of a stimulus

Hello,

I have an ImageStim (called gradient) that I am currently able to zoom in/out on, including a target placed overtop of it using the following code at every frame (units = px):

wheel = mouse.getWheelRel()[1]  

if np.any(gradient.size < (1114.4,752)):
    if wheel > 0 :
        gradient.size += (20)
        target.size += (5)
elif np.any(gradient.size > (8358,5640)):
    if wheel < 0:
        gradient.size -= (20)
        target.size -= (5)
else:
    if wheel > 0 :
        gradient.size += (20)
        target.size += (5)
    elif wheel < 0:
        gradient.size -= (20)
        target.size -= (5)

However, this only allows me to zoom into the centre of the gradient ImageStim. I want to be able to zoom in wherever the mouse is, but I can’t find a way to elegantly do this without resetting the centre of the gradient, making the image “jump”. Has anyone figured out a similar solution?

Thanks in advance!