Stimulus object for drawing arbitrary bitmaps, textures and shapes. One of the main stimuli for PsychoPy.
Formally PatchStim is just a texture behind an optional transparency mask (an ‘alpha mask’). Both the texture and mask can be arbitrary bitmaps and their combination allows an enormous variety of stimuli to be drawn in realtime.
Examples:
myGrat = PatchStim(tex='sin',mask='circle') #gives a circular patch of grating
myGabor = PatchStim(tex='sin',mask='gauss') #gives a 'Gabor' patchgrating
myImage = PatchStim(tex='face.jpg',mask=None) #simply draws the image face.jpg
An PatchStim can be rotated scaled and shifted in position, its texture can be drifted in X and/or Y and it can have a spatial frequency in X and/or Y (for an image file that simply draws multiple copies in the patch).
Also since transparency can be controlled two PatchStims can combine e.g. to form a plaid.
Using Patchstim with images from disk (jpg, tif, png...)
Ideally images to be rendered should be square with ‘power-of-2’ dimensions e.g. 16x16, 128x128. Any image that is not will be upscaled (with linear interp) to the nearest such texture by PsychoPy. The size of the stimulus should be specified in the normal way using the appropriate units (deg, pix, cm...). Be sure to get the aspect ratio the same as the image (if you don’t want it stretched!).
Why can’t I have a normal image, drawn pixel-by-pixel? PatchStims are rendered using OpenGL textures. This is more powerful than using simple screen blitting - it allows the rotation, masking, transparency to work.
| Parameters : |
color:
|
|---|
Clear the textures associated with the given stimulus. As of v1.61.00 this is called automatically during garbage collection of your stimulus, so doesn’t need calling explicitly by the user.
Draw the stimulus in its relevant window. You must call this method after every MyWin.flip() if you want the stimulus to appear on that frame and then update the screen again.
Add or remove a stimulus from the list of stimuli that will be automatically drawn on each flip
| Parameters : |
|
|---|
Turn on (or off) autoLogging for this stimulus.
| Parameters : |
|
|---|
Set the color of the stimulus. See Color spaces for further information about the various ways to specify colors and their various implications.
| Parameters : |
|---|
Can be specified in one of many ways. If a string is given then it is interpreted as the name of the color. Any of the standard html/X11 color names <http://www.w3schools.com/html/html_colornames.asp> can be used. e.g.:
myStim.setColor('white')
myStim.setColor('RoyalBlue')#(the case is actually ignored)
A hex value can be provided, also formatted as with web colors. This can be provided as a string that begins with # (not using python’s usual 0x000000 format):
myStim.setColor('#DDA0DD')#DDA0DD is hexadecimal for plum
You can also provide a triplet of values, which refer to the coordinates in one of the Color spaces. If no color space is specified then the color space most recently used for this stimulus is used again.
myStim.setColor([1.0,-1.0,-1.0], ‘rgb’)#a red color in rgb space myStim.setColor([0.0,45.0,1.0], ‘dkl’) #DKL space with elev=0, azimuth=45 myStim.setColor([0,0,255], ‘rgb255’) #a blue stimulus using rgb255 space
Lastly, a single number can be provided, x, which is equivalent to providing [x,x,x].
myStim.setColor(255, ‘rgb255’) #all guns o max
colorSpace : string or None
defining which of the Color spaces to use. For strings and hex values this is not needed. If None the default colorSpace for the stimulus is used (defined during initialisation).
operation : one of ‘+’,’-‘,’*’,’/’, or ‘’ for no operation (simply replace value)
for colors specified as a triplet of values (or single intensity value) the new value will perform this operation on the previous color
thisStim.setColor([1,1,1],’rgb255’,’+’)#increment all guns by 1 value thisStim.setColor(-1, ‘rgb’, ‘*’) #multiply the color by -1 (which in this space inverts the contrast) thisStim.setColor([10,0,0], ‘dkl’, ‘+’)#raise the elevation from the isoluminant plane by 10 deg
Set the contrast of the stimulus
DEPRECATED since v1.60.05: Please use setColor
DEPRECATED since v1.60.05: Please use setColor
Set the stimulus orientation in degrees
Set the stimulus position in the specified (or inherited) units
DEPRECATED since v1.60.05: Please use setColor
Set the stimulus size [X,Y] in the specified (or inherited) units
Set this stimulus to use shaders if possible.