psychopy.org | Reference | Downloads | Github

Different Color for Background vs Border

Hi all,

I have a experiment running in Fullscreen mode with a viewScale factor so the section of interest is smaller than the full screen size. I want the borders (like a letterboxed video) to be black, but I want the background color in the center section (the screensize * viewScale) to be gray. Specifically, when I call textStim to add text to the screen, I want the edge of the screen to be black but the center to be gray (http://www.psychopy.org/api/visual/textstim.html?highlight=textstim#psychopy.visual.TextStim)

I haven’t found a function yet to do this. Is this kind of functionality supported or should I try to use a .png image for the background?

Thanks,

Jackson

Hi Jackson,

There are a massive number of stimulus arrangements people need. PsychoPy generally caters for this by providing simple stimulus classes that can be combined as needed, rather than providing specific stimuli or functions for particular arrangements.

So you should think less along the lines of “is there a function for this” and more along the lines of “how would I draw this”? In this case, effectively you just want to draw a rectangle in the middle of the screen that is different to the background colour.

Given that you know the size of the desired central area, at the beginning of the experiment, just create a rectangular ShapeStim (http://www.psychopy.org/api/visual/shapestim.html) with those dimensions, centred at position (0,0), and coloured grey, and draw it before other stimuli so that it appears as the background to them.

You can control the colour of the “borders” by simply specifying the color attribute of the window when it is created (http://www.psychopy.org/api/visual/window.html#psychopy.visual.Window). i.e. the black background colour of the window acts as the background of the central grey rectangle you draw.

1 Like

Hi Michael,

Thank you for the suggestion. I put the following code before the displaying of my instructions and it worked:

            grayBox = visual.ShapeStim(win=s.win,lineWidth=0,fillColor=[0,0,0],pos=(0,0),vertices=((1,1),(-1,1),(-1,-1),(1,-1)),closeShape=True,opacity=1.0)
			grayBox.draw()

However now that the box is drawing I’m realizing the viewScale is not changing the placement of my instruction text. I use the height units for placing instruction text. Now I’m thinking perhaps the easiest way is to simply multiply the height value by the viewScale before assigning it, since it seems height is relative to the Window size, which is not changed by viewScale.

Please correct me if I’m wrong in any part of my understanding of height, units, window, and viewScale.

Great. Just make sure that you only create the grayBox stimulus once (e.g. at the start of the experiment). You don’t need to re-create it every time you display instructions (in general, object creation is a time-expensive process, compared to adjusting the properties of a stimulus that already exists.

I’m a bit lost about what you want to achieve with your text stimulus. You should give us concrete details of how you calculate your ‘viewScale’ variable and precisely what you want to specify for the text stimulus location.

Great idea for changing the background color of the screen in any routine! :smiley: !