psychopy.org | Reference | Downloads | Github

Change of stimulus color saturation with time

Dear Group,

I am using Windows 10; PsychoPy version: 3; Python version 3.

My experiment has 2 conditions represented by 2 colors- red and green. I want to display a change of color from 0 saturation to 1 (full saturation) within a duration of 3 seconds. This is why I am using HSV format.
I have tried to modify the code earlier posted in this forum (please follow link here)

Since I am new with Python and PsychoPy, I tried using the build version first and then working on the script generated by it.

This is how my script looks like where I tried to implement the change of colour.

(Imager- assigning the colour in np.array; but the main color pointer is indicated in the excel file called conditions, where it gets the input for the colour according to the conditions)

Imager= np.array([180,0,1])
angleStart = 3/2 * np.pi
angleStop = 2 * np.pi
angleStepNum = 100
angles = np.linspace(angleStart, angleStop, num=angleStepNum)

Imagery = visual.Polygon(
win=win, name=‘Imagery’,
edges=1000, size=(0.1, 0.1),
ori=0, pos=(0, 0),
lineWidth=0.3, lineColor=[1,1,1], lineColorSpace=‘rgb’,
fillColor= Imager, fillColorSpace=‘hsv’,
opacity=1, depth=-2.0, interpolate=True)
for angle in angles:
#for frame in range(nFrames):
Imager = [Imager[0],np.cos(angle),Imager[2]]
Imagery.setFillColor(Imager)

The script is running perfectly with no error. However, in this particular window it takes the colour values (i.e. Imager) directly from the excel sheet instead of changing the saturation level. It appears that the script is not taking the loop into consideration.
Also, I have not taken the time into consideration yet. Any suggestions regarding that would also be nice.

Any help from the forum will be extremely helpful.

Thanks in advance,

Best,
Kinkini Bhadra
PhD student
University of Geneva

Hi Kinkini,

Is what you’ve posted all within the loop? If you’re setting Imager to a value at the beginning, then it will set it to that value each iteration. To set it to a value initially then transform that value, you need to set that initial value before the loop starts.

Thanks,

Todd

Dear Todd,

Thank you so much for your response.
I exactly did that afterwards and it’s working fine now.

Thanks a lot!

  • Kinkini