# Creating a grating with a only one color

**URL:** <https://discourse.psychopy.org/t/creating-a-grating-with-a-only-one-color/2660>\
**Category:** Coding\
**Created:** [June 23, 2017, 9:05pm UTC](https://discourse.psychopy.org/t/creating-a-grating-with-a-only-one-color/2660 "2017-06-23T21:05:31Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![djmannion](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/djmannion/32/37535_2.png) [@djmannion](https://discourse.psychopy.org/u/djmannion)\
**Post date:** [June 24, 2017, 3:25am UTC](https://discourse.psychopy.org/t/creating-a-grating-with-a-only-one-color/2660/2 "2017-06-24T03:25:49Z")

</div>

It is probably easiest to generate your own texture (see [here](https://groups.google.com/forum/#!topic/psychopy-users/yT1R2fhwafM) for this and other options), such as:

```python
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()

```

---

_[View the full topic](https://discourse.psychopy.org/t/creating-a-grating-with-a-only-one-color/2660)._
