Python Issue With Phase of Grating Stimuli

I am trying to get multiple stimuli to move around the screen with the same constant phase speed. For some reason when I try to get all of my stimuli to phase at the same rate it always seems that one is going slow, the next a but faster, another a bit faster, and the final fourth one even faster. Any ideas on how to resolve the issues or point out any mistakes? Thanks!

This is written in the “Each Frame” tab of a custom code in the builder GUI:

print("timer = " + str(timer.getTime()))
if(timer.getTime() > 0):
for stim in stimsArr:
stim.phase = (100.0,100.0)

print(stimsArr[i].phase)
for i in range(len(stimsArr)):

    if(posToPix(stimsArr[i])[0] >=xright or posToPix(stimsArr[i])[0] <= xleft):
        dxdy[i][0] *= -1

    if(posToPix(stimsArr[i])[1] <=ytop or posToPix(stimsArr[i])[1] >= ybot):
        dxdy[i][1] *= -1
    
    if i == 0:
        print("dx: " + str(dx) + " dy: " + str(dy))
        
        print(posToPix(stimsArr[i]))
    stimsArr[i].pos += (dxdy[i][0],dxdy[i][1])

win.flip()

If you are using the Builder interface the you should not add flip commands. There is an automatic flip at the end of each frame

Thanks for the input!

I removed the win.flip() and it doesn’t seem to have resolved the problem. It didn’t change the way the program ran so I guess it was a bit redundant.

Any other thoughts on the phase issue?

Thanks!

I figured it out. I tried to format the code in pixels to make one step easier and ended up making the rest of the steps much more difficult. Keep PsychoPy in norm folks!

Thanks for the input!

1 Like