Choose colours of annulus using visual.RadialStim

Hi all,

I am want to create an annulus made of 2 colours ([0.5,0.5, -1] = background and [1, 1, 1]) using grating stim. I have only found a way to select one colour. When I set the colour to [0.5, 0.5, -1], it switches the other colour to blue instead of keeping it black. Does anyone know how to prevent this from happening//manually establishing the 2 colours of the annulus?

This is my code:

# Define parameters for the annulus
inner_radius = 7
outer_radius =10

# Create a radial stimulus for the outer checkered pattern
outer_stim = visual.RadialStim(win=win, mask='circle', size=(outer_radius, outer_radius),
                               angularCycles=16, radialCycles=1, color = [ 0.5, 0.5, -1.0], interpolate=False)

# Create a radial stimulus for the inner pattern
inner_stim = visual.Circle(win=win, size=(inner_radius, inner_radius), fillColor=[ 0.5, 0.5, -1.0])

And this is the result:

Thanks in advance!

I am not sure I understand the desired appearance, so some questions:

  1. do you want the background of the screen to always be yellow?

  2. for your annulus, do you want one half of it in one colour (e.g., blue) and the other half in a different colour and if so what colour?

  3. by ‘select’, do you mean “click one of the sides of the annulus and know which side was clicked”, or, do you mean “change the colour of one half, perhaps trial by trial.”

  4. can you sketch a diagram of what you want? Or, point to a paper containing a picture of what you are trying to draw?

Note: one thing that catches me frequently is when i re-use code that does not have ‘units=’ and ‘colorSpace=’ explicit in the visual.Stim types. Being explicit helps me remember the correct unit ranges especially so I don’t draw things off the screen.

Hi Ben,

  1. I always want the background to be yellow
  2. I want the annulus to be black ([1, 1, 1]) and yellow ([0.5,0.5, -1]), so it looks like an array of blocks rather than a checkered annulus. I.e. I want the blue blocks to be black instead.
  3. By select I mean being able to set the checkers to black and yellow
  4. Here is an image of it:

Thanks for your note about the units!! I’ll add that on the code:)


Ok, I remember figuring this out a long time ago. You want two colours of sectors. The sectors alternate yellow, black.

There may be a way to do this with transparency, but as far as I can tell, the sectors that you do not define are drawn in the complement of the colour you do define. So, the sectors you called Yellow, were in fact Yellow but the others were drawn in Yellow’s complement which is Blue. There is no easy way (actually I hope there is) to tell the Radial Stim to draw the missing sectors in a specified colour or make them invisible so the background show through. To get what you want, conceptually you can draw the even numbered sectors in black and the odd numbered sectors in background Yellow (then add your background coloured circle in the middle to truncate the sectors. Here is a sample using units=‘pix’ and colourSpace=rgb

Yellow= ( 1.0,  1.0, -1.0)
Black=  (-1.0, -1.0, -1.0)
inner_radius = 256
outer_radius =396
inner_stim = visual.Circle(win=the_screen, size=(inner_radius, inner_radius),  pos=(0,0), units='pix',colorSpace='rgb', fillColor=Yellow )

for p in range(0,360,30)  :
    piece1=visual.Pie(the_screen, radius=outer_radius, start=p, end=p+15, edges=32, units='pix', lineWidth=0, lineColor=False,
                   fillColor=Black, pos=(0, 0), interpolate=False, colorSpace='rgb')
    piece2=visual.Pie(the_screen, radius=outer_radius, start=p+15, end=p+30, edges=32, units='pix', lineWidth=0, lineColor=False,
                   fillColor=Yellow, pos=(0, 0), interpolate=False, colorSpace='rgb')



You can fix the magic numbers that set the section widths (the 30 in the ‘p in range’ and the +15 in the pieces).

If you are going to animate this or redraw it frequently, it is a good idea to premake and save a set of these and the just draw the bitmaps. If you have a really powerful machine and graphics card, then drawing these on the fly might be ok.

Hi Ben,

Sorry for the very late reply!!! This worked wonders, it’s just what we needed. Thank you so much for your help!!!