psychopy.org | Reference | Downloads | Github

Creating a grating with a only one color

Hi,

I want to present only blue shades on my screen.
I want to create a grating that goes from blue to black.
How can I do that?

Thanks,
Boaz

It is probably easiest to generate your own texture (see here for this and other options), such as:

import numpy as np

import psychopy.visual
import psychopy.filters
import psychopy.event

win = psychopy.visual.Window(
    size=[400, 400],
    fullscr=False,
    units="pix"
)

grating_res = 256

grating = psychopy.filters.makeGrating(res=grating_res, cycles=5.0)

# initialise a 'black' texture
blue_grating = np.ones((grating_res, grating_res, 3)) * -1.0
# replace the blue channel with the grating
blue_grating[..., -1] = grating

stim = psychopy.visual.GratingStim(
    win=win,
    tex=blue_grating,
    mask="circle",
    size=(grating_res, grating_res)
)

stim.draw()

win.flip()

psychopy.event.waitKeys()

win.close()
1 Like