psychopy.org | Reference | Downloads | Github

Blending by multiplication?

Hi,

I’m new to PsychoPy and am in the process of learning about stimuli. I gave my self the challenge of generating a flashing checkerboard as a first test. I was able to generate something very close to what I wanted by combining two gratings at 90 deg offset with the phases switching between 0 and 0.5. However, blending doesn’t quite give me the desired pattern - one set of corners are grey (a mix of black and white), where the white top grating blends with the bottom black grating. Is there a way to multiply two stimuli rather than add them? Or is there a different approach I should adopt for this problem?

thanks!

Here is a sample code that reproduces what I describe:

from psychopy import visual, core, event

#create a window to draw in
myWin = visual.Window((800,800), allowGUI=False, blendMode='add')


#INITIALISE SOME STIMULI
grating1 = visual.GratingStim(myWin, mask=None, pos=(0,0), tex='sqr',
                              color=[1.0, 1.0, 1.0], opacity=1.0,
                              size=(1.0, 1.0), sf=(4,0), ori=0)

grating2 = visual.GratingStim(myWin, mask=None, pos=(0,0), tex='sqr',
                              color=[1.0, 1.0, 1.0], opacity=0.5,
                              size=(1.0, 1.0), sf=(4,0), ori=90)

trialClock = core.Clock()
t = 0
while t < 40:    # quits after 20 secs

    t = trialClock.getTime()

    grating1.setPhase(np.round(2*t)/2)  # drift at 1Hz
    grating1.draw()  #redraw it

    grating2.setPhase(np.round(2*t)/2)  # drift at 1Hz
    grating2.draw()  #redraw it

    myWin.flip()          #update the screen

    #handle key presses each frame
    for keys in event.getKeys():
        if keys in ['escape','q']:
            core.quit()