psychopy.org | Reference | Downloads | Github

Changing image size during mousepress

OS (Win7):
PsychoPy version (e.g. 2020.2.10):
Standard Standalone? (y)

What are you trying to achieve?:
In my experiment, participants must ‘produce’ a ‘flower stem’ (see image) by pressing the mouse. So, basically, the green part of the flower will increase in size, but only in length, and only downwards!.

image

What did you try to make it work?:
Right now I can increase the height of the stem, but it increases on both ends, so that’s no good. I tried to adjust the position of the midpoint of the stem while the stem ‘grows’, but I couldn’t get that to work. My experiment screen settings are set to pix.

I also tried to draw a green rectangle (that’s basically what it is) by using Shapes, but that wouldn’t appear on the screen.

What specifically went wrong when you tried that?:
For the first ‘solution’ (i.e. change the position of the image while it increases) i get “ValueError: Invalid parameter. Single numbers are not accepted. Should be tuple/list/array of length 2”

Surely there’s an easy way to fix this, but I can’t seem to work it out. Any help is much appreciated!

-Sabine

What position are you putting here?

OK here’s what I’ve got.

In the code component Begin Experiment:

w = 28 (pix)
h = 33 (pix)

x = 0
y = 35

Then for each frame:

if mouse.getPressed()[0]:
h = h *1.01 # increases image height
stim.size = [w,h] # w and h are defined earlier
# here i’d add a simple formula that would change the position
stim.pos = [x,y]
stim.draw()

-Sabine

Try the following

if mouse.getPressed()[0]:
     h = round(h *1.01) # increases image height
     stim.setSize([w,h]) # w and h are defined earlier
     y=52-round(h/2) #Try this. I'm trying to keep the number of pixels as an integer.
     stim.setPos([x,y])
# If stim is the name of the component it is already being automatically drawn so stim.draw() isn't needed.

YES it works! Thanks a heap!

Ok so I’ve actually stumbled upon an issue with this… two issues actually.

  1. Doing this task on a computer with a different screen resolution will mess up the alignment of the images (i.e. the initial position of the green stem is in the middle of the sunflower head instead of below it)

  2. the height of the stem after a button press depends on the screen resolution of the monitor. Apparently pixels are not the same size? (I had no idea…)

Some info:
a. My general experiment settings are ‘norm’ and ‘full screen’ (i cannot change that -well I can but it would mess up the other 40+ routines)
b. The green polygon that is manipulated is the only component that is set to ‘pixels’.
c. I am recording the final height of the flower stem in pixels.

What is the best (easiest?) way to work around these issues? I suppose using a set window size should help with the alignment, but how can I figure out the pixel size for each device? Would retrieving the screen resolution help? How do i do that?

Link to the task: Pavlovia
If you want to see what the issue is, then try this on two different screens (i.e. with diff resolutions)

Thanks,
-Sabine

OK nevermind, simply setting the component units to pix fixed the issue :grimacing: