Package psychopy :: Module visual :: Class ShapeStim
[frames] | no frames]

Class ShapeStim

source code


Create geometric (vector) shapes by defining vertex locations.

Shapes can be outlines or filled, by setting lineRGB and fillRGB to rgb triplets, or None. They can also be rotated (stim.setOri(__)) and translated (stim.setPos(__)) like any other stimulus.

NB for now the fill of objects is performed using glBegin(GL_POLYGON) and that is limited to convex shapes. With concavities you get unpredictable results (e.g. add a fill color to the arrow stim below). To create concavities, you can combine multiple shapes, or stick to just outlines. (If anyone wants to rewrite ShapeStim to use glu tesselators that would be great!)

Instance Methods
 
__init__(self, win, units='', lineWidth=1.0, lineColor=(1.0, 1.0, 1.0), lineColorSpace='rgb', fillColor=(0.0, 0.0, 0.0), fillColorSpace='rgb', vertices=((-0.5, 0), (0, 0.5), (0.5, 0)), closeShape=True, pos=(0, 0), ori=0.0, opacity=1.0, depth=0, interpolate=True, lineRGB=None, fillRGB=None)
:Parameters: win : A :class:`~psychopy.visual.Window` object (required)
source code
 
setLineRGB(self, value, operation='')
DEPRECATED since v1.60.05: Please use setLineColor
source code
 
setFillRGB(self, value, operation='')
DEPRECATED since v1.60.05: Please use setFillColor
source code
 
setLineColor(self, color, colorSpace=None, operation='') source code
 
setFillColor(self, color, colorSpace=None, operation='') source code
 
setVertices(self, value=None, operation='')
Set the xy values of the vertices (relative to the centre of the field).
source code
 
draw(self, win=None)
Draw the stimulus in its relevant window.
source code

Inherited from _BaseVisualStim: setColor, setContr, setDKL, setDepth, setLMS, setOpacity, setOri, setPos, setRGB, setSize, setUseShaders

Method Details

__init__(self, win, units='', lineWidth=1.0, lineColor=(1.0, 1.0, 1.0), lineColorSpace='rgb', fillColor=(0.0, 0.0, 0.0), fillColorSpace='rgb', vertices=((-0.5, 0), (0, 0.5), (0.5, 0)), closeShape=True, pos=(0, 0), ori=0.0, opacity=1.0, depth=0, interpolate=True, lineRGB=None, fillRGB=None)
(Constructor)

source code 

:Parameters:
    win :
        A :class:`~psychopy.visual.Window` object (required)
        
    units :  **None**, 'norm', 'cm', 'deg' or 'pix'  
        If None then the current units of the :class:`~psychopy.visual.Window` will be used. 
        See :ref:`units` for explanation of other options.
        
    lineRGB :
     
        - (r,g,b) or [r,g,b] 
        - or a single intensity value (which will be applied to all guns).
        
        **NB** units range -1:1 (so 0.0 is GREY). See :ref:`rgb` for details.
        
    fillRGB : 
    
        - (r,g,b) or [r,g,b] 
        - or a single intensity value (which will be applied to all guns).
        
        **NB** units range -1:1 (so 0.0 is GREY). See :ref:`rgb` for details.
        
    lineWidth : int (or float?) 
        specifying the line width in **pixels**
        
    vertices : a list of lists or a numpy array (Nx2) 
        specifying xy positions of each vertex
        
    closeShape : True or False
        Do you want the last vertex to be automatically connected to the first?
        
    pos : tuple, list or 2x1 array
        the position of the anchor for the stimulus (relative to which the vertices are drawn)
        
    ori : float or int
        the shape can be rotated around the anchor
        
    opacity : float
        1.0 is opaque, 0.0 is transparent
        
    depth : 0
        This can be used to choose which
        stimulus overlays which. (more negative values are nearer).
        At present the window does not do perspective rendering
        but could do if that's really useful(?!)
        
    interpolate : True or False
        If True the edge of the line will be antialiased.
        
        

Overrides: _BaseVisualStim.__init__

setVertices(self, value=None, operation='')

source code 

Set the xy values of the vertices (relative to the centre of the field). Values should be:

  • an array/list of Nx2 coordinates.

draw(self, win=None)

source code 
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.
Overrides: _BaseVisualStim.draw