Previous topic

Rect

Next topic

SimpleImageStim

This Page

Quick links

ShapeStim

class psychopy.visual.ShapeStim(win, units='', lineWidth=1.0, lineColor=(1.0, 1.0, 1.0), lineColorSpace='rgb', fillColor=None, fillColorSpace='rgb', vertices=((-0.5, 0), (0, 0.5), (0.5, 0)), closeShape=True, pos=(0, 0), size=1, ori=0.0, opacity=1.0, depth=0, interpolate=True, lineRGB=None, fillRGB=None, name='', autoLog=True)

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!)

Parameters :
win :

A Window object (required)

units : None, ‘norm’, ‘cm’, ‘deg’ or ‘pix’

If None then the current units of the Window will be used. See Units for the window and stimuli for explanation of other options.

lineColor :

Could be a:

  • web name for a color (e.g. ‘FireBrick’);
  • hex value (e.g. ‘#FF0047’);
  • tuple (1.0,1.0,1.0); list [1.0,1.0, 1.0]; or numpy array.

If the last three are used then the color space should also be given See Color spaces

lineColorSpace:

The color space controlling the interpretation of the lineColor. See Color spaces

fillColor :

Could be a:

  • web name for a color (e.g. ‘FireBrick’);
  • hex value (e.g. ‘#FF0047’);
  • tuple (1.0,1.0,1.0); list [1.0,1.0, 1.0]; or numpy array.

If the last three are used then the color space should also be given See Color spaces

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)

size : float, int, tuple, list or 2x1 array

Scales the ShapeStim up or down. Size is independent of the units, i.e. setting the size to 1.5 will make the stimulus to be 1.5 times it’s original size as defined by the vertices. Use a 2-tuple to scale asymmetrically.

ori : float or int

the shape can be rotated around the anchor

opacity : float

1.0 is opaque, 0.0 is transparent

depth:

The depth argument is deprecated and may be removed in future versions. Depth is controlled simply by drawing order.

interpolate : True or False

If True the edge of the line will be antialiased.

name : string

The name of the object to be using during logged messages about this stim

draw(win=None)

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.

setAutoDraw(val)

Add or remove a stimulus from the list of stimuli that will be automatically drawn on each flip

Parameters :
  • val: True/False

    True to add the stimulus to the draw list, False to remove it

setAutoLog(val=True)

Turn on (or off) autoLogging for this stimulus.

Parameters :
  • val: True (default) or False
setColor(color, colorSpace=None, operation='')

For ShapeStim use setLineColor() or setFillColor()

setContr(newContr, operation='')

Set the contrast of the stimulus

setDKL(newDKL, operation='')

DEPRECATED since v1.60.05: Please use setColor

setDepth(newDepth, operation='')
setFillColor(color, colorSpace=None, operation='')

Sets the color of the shape fill. See PatchStim.setColor() for further details of how to use this function.

Note that shapes where some vertices point inwards will usually not ‘fill’ correctly.

setFillRGB(value, operation='')

DEPRECATED since v1.60.05: Please use setFillColor()

setLMS(newLMS, operation='')

DEPRECATED since v1.60.05: Please use setColor

setLineColor(color, colorSpace=None, operation='')

Sets the color of the shape edge. See PatchStim.setColor() for further details of how to use this function.

setLineRGB(value, operation='')

DEPRECATED since v1.60.05: Please use setLineColor()

setOpacity(newOpacity, operation='')
setOri(newOri, operation='')

Set the stimulus orientation in degrees

setPos(newPos, operation='', units=None)

Set the stimulus position in the specified (or inherited) units

setRGB(newRGB, operation='')

DEPRECATED since v1.60.05: Please use setColor

setSize(value, operation='')

Sets the size of the shape. Size is independent of the units of shape and will simply scale the shape’s vertices by the factor given. Use a tuple or list of two values to scale asymmetrically.

setUseShaders(val=True)

Set this stimulus to use shaders if possible.

setVertices(value=None, operation='')

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

  • an array/list of Nx2 coordinates.