Rectangle Object Single Sided Expansion Problems

Hi,

I am implementing a “health bar” in my research. I thought of using a simple method of expanding a rectangle. I could change the colour of the rectangle via inverting it and then using an “if” loop to check and change the rectangle colour if its positive or negative.

#rectangle expand or shrink. 

if berry_resp.corr:
    width += 0.05
else:
    width -= 0.05

if width >= 0.001:
    HPcolour = "green"
elif width <= 0.001:
    HPcolour = "red"

However, I have been asked to implement the health bar in a different fashion which requires me to expand only a single side of the rectangle. The proposal is as follows;
Similar to game health bars, if you give enough correct answers the rectangle will expand towards the right and be green, and if you give wrong answers it will expand towards the left side displayed in red.
My problem is that PsychoPY polygon rectangle object expands in both ways and I could not find the parameter that makes this happen. What I want to do is;
Have 2 rectangle objects: Red, Green. If participant gives correct answer expand the green one, if the participant gives incorrect answer if green is expanded shrink it, if there the green is not expanded, expand Red towards the left.

Is it possible to disable the both-sided expansion of rectangles? If so, could you please enlighten me ^-^

Thank you very much in advance,
KKacar

I think what you’re asking is how to set rectangles to be anchored left - i.e. when it grows or expands horizontally, the left side stays in one place while the right side moves? We’re hoping to implement anchoring on all visual stimuli eventually, so far we’ve only got it on TextBox components (as these are brand new so were built with anchoring from the ground up). You can simulate this effect manually in the mean time! When you add/subtract 0.05 to width, you have to add/subtract 0.05/2 to the horizontal position. Like this:

if berry_resp.corr:
    width += 0.05
    xpos += 0.05/2
else:
    width -= 0.05
    xpos -= 0.05/2

and then set the position of your health bar to set every frame and be (xpos, whatever your original y was)

Here’s a minimal example, where I create a health bar which increases as time passes, remaining anchored to the left:
healthBar.psyexp (5.8 KB)

THANK YOU VERY MUCH!!!

This has worked perfectly and exactly as I have wanted it to!
I hope you have a great day!

Thank you,
KKacar