def setAutoDraw(self, value, log=None): """Sets autoDraw for Form and any responseCtrl contained within """ for i in self.items: if i['responseCtrl']: i['responseCtrl'].setAutoDraw(value) BaseVisualStim.setAutoDraw(self, value, log)
def setAutoDraw(self, value, log=None): """Sets autoDraw for Form and any responseCtrl contained within """ for i in self.items: if i['responseCtrl']: i['responseCtrl'].__dict__['autoDraw'] = value self.win.addEditable(i['responseCtrl']) BaseVisualStim.setAutoDraw(self, value, log)
def setColor(self, color, colorSpace=None, operation='', log=True): """Set the color of the stimulus. See :ref:`colorspaces` for further information about the various ways to specify colors and their various implications. :Parameters: color : 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 :ref:`colorspaces`. 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 :ref:`colorspaces` 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 """ #call setColor from super class BaseVisualStim.setColor(self, color, colorSpace=colorSpace, operation=operation, log=log) #but then update text objects if necess if not self.useShaders: self._needSetText = True
def setColor(self, color, colorSpace=None, operation='', log=True): """Set the color of the stimulus. See :ref:`colorspaces` for further information about the various ways to specify colors and their various implications. :Parameters: color : 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 :ref:`colorspaces`. 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 :ref:`colorspaces` 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 """ #call setColor from super class BaseVisualStim.setColor(self, color, colorSpace=colorSpace, operation=operation, log=log) #but then update text objects if necess if not self.useShaders: self._needSetText=True
def __init__(self, win, image =None, mask =None, units ="", pos =(0.0,0.0), size =None, ori =0.0, color=(1.0,1.0,1.0), colorSpace='rgb', contrast=1.0, opacity=1.0, depth=0, interpolate=False, flipHoriz=False, flipVert=False, texRes=128, name='', autoLog=True, maskParams=None): """ :Parameters: image : The image file to be presented (most formats supported) mask : The alpha mask that can be used to control the outer shape of the stimulus + **None**, 'circle', 'gauss', 'raisedCos' + or the name of an image file (most formats supported) + or a numpy array (1xN or NxN) ranging -1:1 texRes: Sets the resolution of the mask (this is independent of the image resolution) maskParams: Various types of input. Default to None. This is used to pass additional parameters to the mask if those are needed. - For the 'raisedCos' mask, pass a dict: {'fringeWidth':0.2}, where 'fringeWidth' is a parameter (float, 0-1), determining the proportion of the patch that will be blurred by the raised cosine edge. """ BaseVisualStim.__init__(self, win, units=units, name=name, autoLog=autoLog) self.useShaders = win._haveShaders #use shaders if available by default, this is a good thing #initialise textures for stimulus self._texID = GL.GLuint() GL.glGenTextures(1, ctypes.byref(self._texID)) self._maskID = GL.GLuint() GL.glGenTextures(1, ctypes.byref(self._maskID)) self.maskParams= maskParams self.texRes=texRes # Other stuff self._imName = image self.isLumImage = None self.interpolate=interpolate self.flipHoriz = flipHoriz self.flipVert = flipVert self._requestedSize=size self._origSize=None#if an image texture is loaded this will be updated self.size = val2array(size) self.pos = numpy.array(pos,float) self.ori = float(ori) self.depth=depth #color and contrast etc self.contrast = float(contrast) self.opacity = float(opacity) self.__dict__['colorSpace'] = colorSpace #omit decorator self.setColor(color, colorSpace=colorSpace, log=False) self.rgbPedestal=[0,0,0]#does an rgb pedestal make sense for an image? # Set the image and mask self.setImage(image, log=False) self.setMask(mask, log=False) #fix scaling to window coords self._calcSizeRendered() self._calcPosRendered() # _verticesRendered for .contains() and .overlaps() v = [(-.5,-.5), (-.5,.5), (.5,.5), (.5,-.5)] self._verticesRendered = numpy.array(self._sizeRendered, dtype=float) * v #generate a displaylist ID self._listID = GL.glGenLists(1) self._updateList()#ie refresh display list
def __init__(self, win, tex="sin", mask="none", units="", pos=(0.0, 0.0), size=None, sf=None, ori=0.0, phase=(0.0, 0.0), texRes=128, rgb=None, dkl=None, lms=None, color=(1.0, 1.0, 1.0), colorSpace='rgb', contrast=1.0, opacity=1.0, depth=0, rgbPedestal=(0.0, 0.0, 0.0), interpolate=False, name='', autoLog=True, autoDraw=False, maskParams=None): """ :Parameters: texRes: resolution of the texture (if not loading from an image file) maskParams: Various types of input. Default to None. This is used to pass additional parameters to the mask if those are needed. - For the 'raisedCos' mask, pass a dict: {'fringeWidth':0.2}, where 'fringeWidth' is a parameter (float, 0-1), determining the proportion of the patch that will be blurred by the raised cosine edge. """ #what local vars are defined (these are the init params) for use by __repr__ self._initParams = dir() for unecess in ['self', 'rgb', 'dkl', 'lms']: self._initParams.remove(unecess) #initialise parent class BaseVisualStim.__init__(self, win, units=units, name=name, autoLog=False) self.useShaders = win._haveShaders #use shaders if available by default, this is a good thing # UGLY HACK: Some parameters depend on each other for processing. # They are set "superficially" here. # TO DO: postpone calls to createTexture, setColor and _calcCyclesPerStim whin initiating stimulus self.__dict__['contrast'] = 1 self.__dict__['size'] = 1 self.__dict__['sf'] = 1 self.__dict__['tex'] = tex #initialise textures and masks for stimulus self._texID = GL.GLuint() GL.glGenTextures(1, ctypes.byref(self._texID)) self._maskID = GL.GLuint() GL.glGenTextures(1, ctypes.byref(self._maskID)) self.texRes = texRes #must be power of 2 self.maskParams = maskParams self.interpolate = interpolate #NB Pedestal isn't currently being used during rendering - this is a place-holder self.rgbPedestal = val2array(rgbPedestal, False, length=3) self.__dict__[ 'colorSpace'] = colorSpace # No need to invoke decorator for color updating. It is done just below. if rgb != None: logging.warning( "Use of rgb arguments to stimuli are deprecated. Please use color and colorSpace args instead" ) self.setColor(rgb, colorSpace='rgb', log=False) elif dkl != None: logging.warning( "Use of dkl arguments to stimuli are deprecated. Please use color and colorSpace args instead" ) self.setColor(dkl, colorSpace='dkl', log=False) elif lms != None: logging.warning( "Use of lms arguments to stimuli are deprecated. Please use color and colorSpace args instead" ) self.setColor(lms, colorSpace='lms', log=False) else: self.setColor(color, colorSpace=colorSpace, log=False) # set other parameters self.ori = float(ori) self.phase = val2array(phase, False) self._origSize = None #if an image texture is loaded this will be updated self._requestedSize = size self.size = val2array(size) self.sf = val2array(sf) self.pos = val2array(pos, False, False) self.depth = depth self.tex = tex self.mask = mask self.contrast = float(contrast) self.opacity = float(opacity) self.autoLog = autoLog self.autoDraw = autoDraw #fix scaling to window coords self._calcCyclesPerStim() #generate a displaylist ID self._listID = GL.glGenLists(1) self._updateList() #ie refresh display list #set autoLog (now that params have been initialised) self.autoLog = autoLog if autoLog: logging.exp("Created %s = %s" % (self.name, str(self)))
def __init__(self, win, image=None, mask=None, units="", pos=(0.0, 0.0), size=None, ori=0.0, color=(1.0, 1.0, 1.0), colorSpace='rgb', contrast=1.0, opacity=1.0, depth=0, interpolate=False, flipHoriz=False, flipVert=False, texRes=128, name='', autoLog=True, maskParams=None): """ :Parameters: image : The image file to be presented (most formats supported) mask : The alpha mask that can be used to control the outer shape of the stimulus + **None**, 'circle', 'gauss', 'raisedCos' + or the name of an image file (most formats supported) + or a numpy array (1xN or NxN) ranging -1:1 texRes: Sets the resolution of the mask (this is independent of the image resolution) maskParams: Various types of input. Default to None. This is used to pass additional parameters to the mask if those are needed. - For the 'raisedCos' mask, pass a dict: {'fringeWidth':0.2}, where 'fringeWidth' is a parameter (float, 0-1), determining the proportion of the patch that will be blurred by the raised cosine edge. """ #what local vars are defined (these are the init params) for use by __repr__ self._initParams = dir() self._initParams.remove('self') BaseVisualStim.__init__(self, win, units=units, name=name, autoLog=False) #set autoLog at end of init self.useShaders = win._haveShaders #use shaders if available by default, this is a good thing #initialise textures for stimulus self._texID = GL.GLuint() GL.glGenTextures(1, ctypes.byref(self._texID)) self._maskID = GL.GLuint() GL.glGenTextures(1, ctypes.byref(self._maskID)) self.maskParams = maskParams self.texRes = texRes # Other stuff self._imName = image self.isLumImage = None self.interpolate = interpolate self.flipHoriz = flipHoriz self.flipVert = flipVert self._requestedSize = size self._origSize = None #if an image texture is loaded this will be updated self.size = val2array(size) self.pos = numpy.array(pos, float) self.ori = float(ori) self.depth = depth #color and contrast etc self.contrast = float(contrast) self.opacity = float(opacity) self.__dict__['colorSpace'] = colorSpace #omit decorator self.setColor(color, colorSpace=colorSpace, log=False) self.rgbPedestal = [0, 0, 0] #does an rgb pedestal make sense for an image? # Set the image and mask self.setImage(image, log=False) self.setMask(mask, log=False) #generate a displaylist ID self._listID = GL.glGenLists(1) self._updateList() #ie refresh display list self.autoLog = autoLog if autoLog: logging.exp("Created %s = %s" % (self.name, str(self)))
def __init__(self, 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, contrast=1.0, depth =0, interpolate=True, lineRGB=None, fillRGB=None, name='', autoLog=True): """ :Parameters: 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? interpolate : True or False If True the edge of the line will be antialiased. """ #what local vars are defined (these are the init params) for use by __repr__ self._initParams = dir() self._initParams.remove('self') # Initialize inheritance and remove unwanted methods BaseVisualStim.__init__(self, win, units=units, name=name, autoLog=False) #autoLog is set later self.__dict__['setColor'] = None self.__dict__['color'] = None self.__dict__['colorSpace'] = None self.contrast = float(contrast) self.opacity = float(opacity) self.pos = numpy.array(pos, float) self.closeShape=closeShape self.lineWidth=lineWidth self.interpolate=interpolate # Color stuff self.useShaders=False#since we don't ned to combine textures with colors self.__dict__['lineColorSpace'] = lineColorSpace self.__dict__['fillColorSpace'] = fillColorSpace if lineRGB!=None: logging.warning("Use of rgb arguments to stimuli are deprecated. Please use color and colorSpace args instead") self.setLineColor(lineRGB, colorSpace='rgb') else: self.setLineColor(lineColor, colorSpace=lineColorSpace) if fillRGB!=None: logging.warning("Use of rgb arguments to stimuli are deprecated. Please use color and colorSpace args instead") self.setFillColor(fillRGB, colorSpace='rgb') else: self.setFillColor(fillColor, colorSpace=fillColorSpace) # Other stuff self.depth=depth self.ori = numpy.array(ori,float) self.size = numpy.array([0.0,0.0]) self.setSize(size, log=False) self.setVertices(vertices, log=False) self._calcVerticesRendered() #set autoLog (now that params have been initialised) self.autoLog= autoLog if autoLog: logging.exp("Created %s = %s" %(self.name, str(self)))
def __init__(self, win, tex="sin", mask="none", units="", pos=(0.0, 0.0), size=None, sf=None, ori=0.0, phase=(0.0, 0.0), texRes=128, rgb=None, dkl=None, lms=None, color=(1.0, 1.0, 1.0), colorSpace='rgb', contrast=1.0, opacity=1.0, depth=0, rgbPedestal=(0.0, 0.0, 0.0), interpolate=False, name='', autoLog=True, autoDraw=False, maskParams=None): """ :Parameters: texRes: resolution of the texture (if not loading from an image file) maskParams: Various types of input. Default to None. This is used to pass additional parameters to the mask if those are needed. - For the 'raisedCos' mask, pass a dict: {'fringeWidth':0.2}, where 'fringeWidth' is a parameter (float, 0-1), determining the proportion of the patch that will be blurred by the raised cosine edge. """ #what local vars are defined (these are the init params) for use by __repr__ self._initParams = dir() for unecess in ['self', 'rgb', 'dkl', 'lms']: self._initParams.remove(unecess) #initialise parent class BaseVisualStim.__init__(self, win, units=units, name=name, autoLog=False) self.useShaders = win._haveShaders #use shaders if available by default, this is a good thing # UGLY HACK: Some parameters depend on each other for processing. # They are set "superficially" here. # TO DO: postpone calls to createTexture, setColor and _calcCyclesPerStim whin initiating stimulus self.__dict__['contrast'] = 1 self.__dict__['size'] = 1 self.__dict__['sf'] = 1 self.__dict__['tex'] = tex #initialise textures and masks for stimulus self._texID = GL.GLuint() GL.glGenTextures(1, ctypes.byref(self._texID)) self._maskID = GL.GLuint() GL.glGenTextures(1, ctypes.byref(self._maskID)) self.texRes = texRes #must be power of 2 self.maskParams = maskParams self.interpolate = interpolate #NB Pedestal isn't currently being used during rendering - this is a place-holder self.rgbPedestal = val2array(rgbPedestal, False, length=3) self.__dict__['colorSpace'] = colorSpace # No need to invoke decorator for color updating. It is done just below. if rgb != None: logging.warning("Use of rgb arguments to stimuli are deprecated. Please use color and colorSpace args instead") self.setColor(rgb, colorSpace='rgb', log=False) elif dkl != None: logging.warning("Use of dkl arguments to stimuli are deprecated. Please use color and colorSpace args instead") self.setColor(dkl, colorSpace='dkl', log=False) elif lms != None: logging.warning("Use of lms arguments to stimuli are deprecated. Please use color and colorSpace args instead") self.setColor(lms, colorSpace='lms', log=False) else: self.setColor(color, colorSpace=colorSpace, log=False) # set other parameters self.ori = float(ori) self.phase = val2array(phase, False) self._origSize = None #if an image texture is loaded this will be updated self._requestedSize = size self.size = val2array(size) self.sf = val2array(sf) self.pos = val2array(pos, False, False) self.depth = depth self.tex = tex self.mask = mask self.contrast = float(contrast) self.opacity = float(opacity) self.autoLog = autoLog self.autoDraw = autoDraw #fix scaling to window coords self._calcCyclesPerStim() #generate a displaylist ID self._listID = GL.glGenLists(1) self._updateList()#ie refresh display list #set autoLog (now that params have been initialised) self.autoLog= autoLog if autoLog: logging.exp("Created %s = %s" %(self.name, str(self)))
def setOpacity(self, newOpacity, operation='', log=None): BaseVisualStim.setOpacity(self, newOpacity, operation='', log=None) self._setTextShaders()
def __init__(self, win, units ='', nDots =1, coherence =0.5, fieldPos =(0.0,0.0), fieldSize = (1.0,1.0), fieldShape = 'sqr', dotSize =2.0, dotLife = 3, dir =0.0, speed =0.5, rgb =None, color=(1.0,1.0,1.0), colorSpace='rgb', opacity = 1.0, contrast = 1.0, depth =0, element=None, signalDots='same', noiseDots='direction', name='', autoLog=True): """ :Parameters: nDots : int number of dots to be generated fieldPos : (x,y) or [x,y] specifying the location of the centre of the stimulus. fieldSize : (x,y) or [x,y] or single value (applied to both dimensions) Sizes can be negative and can extend beyond the window. fieldShape : *'sqr'* or 'circle' Defines the envelope used to present the dots dotSize specified in pixels (overridden if `element` is specified) dotLife : int Number of frames each dot lives for (default=3, -1=infinite) dir : float (degrees) direction of the coherent dots speed : float speed of the dots (in *units*/frame) signalDots : 'same' or *'different'* If 'same' then the signal and noise dots are constant. If different then the choice of which is signal and which is noise gets randomised on each frame. This corresponds to Scase et al's (1996) categories of RDK. noiseDots : *'direction'*, 'position' or 'walk' Determines the behaviour of the noise dots, taken directly from Scase et al's (1996) categories. For 'position', noise dots take a random position every frame. For 'direction' noise dots follow a random, but constant direction. For 'walk' noise dots vary their direction every frame, but keep a constant speed. element : *None* or a visual stimulus object This can be any object that has a ``.draw()`` method and a ``.setPos([x,y])`` method (e.g. a GratingStim, TextStim...)!! See `ElementArrayStim` for a faster implementation of this idea. """ #what local vars are defined (these are the init params) for use by __repr__ self._initParams = __builtins__['dir']() self._initParams.remove('self') BaseVisualStim.__init__(self, win, units=units, name=name, autoLog=False)#set autoLog at end of init self.nDots = nDots #pos and size are ambiguous for dots so DotStim explicitly has #fieldPos = pos, fieldSize=size and then dotSize as additional param self.fieldPos = self.pos = val2array(fieldPos, False, False) self.fieldSize = self.size = val2array(fieldSize, False) if type(dotSize) in [tuple,list]: self.dotSize = numpy.array(dotSize) else: self.dotSize=dotSize self.fieldShape = fieldShape self.dir = dir self.speed = speed self.element = element self.dotLife = dotLife self.signalDots = signalDots self.noiseDots = noiseDots self.opacity = float(opacity) self.contrast = float(contrast) self.useShaders=False#not needed for dots? self.colorSpace=colorSpace if rgb!=None: logging.warning("Use of rgb arguments to stimuli are deprecated. Please use color and colorSpace args instead") self.setColor(rgb, colorSpace='rgb') else: self.setColor(color) self.depth=depth #initialise the dots themselves - give them all random dir and then #fix the first n in the array to have the direction specified self.coherence=round(coherence*self.nDots)/self.nDots#store actual coherence self. _verticesBase = self._dotsXY = self._newDotsXY(self.nDots) #initialise a random array of X,Y self._dotsSpeed = numpy.ones(self.nDots, 'f')*self.speed#all dots have the same speed self._dotsLife = abs(dotLife)*numpy.random.rand(self.nDots)#abs() means we can ignore the -1 case (no life) #determine which dots are signal self._signalDots = numpy.zeros(self.nDots, dtype=bool) self._signalDots[0:int(self.coherence*self.nDots)]=True #numpy.random.shuffle(self._signalDots)#not really necessary #set directions (only used when self.noiseDots='direction') self._dotsDir = numpy.random.rand(self.nDots)*2*pi self._dotsDir[self._signalDots] = self.dir*pi/180 self._update_dotsXY() self.autoLog= autoLog if autoLog: logging.exp("Created %s = %s" %(self.name, str(self)))
def __init__(self, win, tex ="sqrXsqr", mask ="none", units ="", pos =(0.0,0.0), size =(1.0,1.0), radialCycles=3, angularCycles=4, radialPhase=0, angularPhase=0, ori =0.0, texRes =64, angularRes=100, visibleWedge=(0, 360), rgb =None, color=(1.0,1.0,1.0), colorSpace='rgb', dkl=None, lms=None, contrast=1.0, opacity=1.0, depth=0, rgbPedestal = (0.0,0.0,0.0), interpolate=False, name='', autoLog=True): """ :Parameters: texRes : (default= *128* ) resolution of the texture (if not loading from an image file) angularRes : (default= *100* ) 100, the number of triangles used to make the sti radialPhase : the phase of the texture from the centre to the perimeter of the stimulus (in radians) angularPhase : the phase of the texture around the stimulus (in radians) """ BaseVisualStim.__init__(self, win, units=units, name=name, autoLog=autoLog) self.useShaders = win._haveShaders #use shaders if available by default, this is a good thing # UGLY HACK again. (See same section in GratingStim for ideas) self.__dict__['contrast'] = 1 self.__dict__['size'] = 1 self.__dict__['sf'] = 1 self.__dict__['tex'] = tex #initialise textures for stimulus self._texID = GL.GLuint() GL.glGenTextures(1, ctypes.byref(self._texID)) self._maskID = GL.GLuint() GL.glGenTextures(1, ctypes.byref(self._maskID)) self.maskParams = None self.maskRadialPhase = 0 self.texRes = texRes #must be power of 2 self.interpolate = interpolate self.rgbPedestal = val2array(rgbPedestal, False, length=3) #these are defined by the GratingStim but will just cause confusion here! self.setSF = None self.setPhase = None self.colorSpace=colorSpace if rgb!=None: logging.warning("Use of rgb arguments to stimuli are deprecated. Please use color and colorSpace args instead") self.setColor(rgb, colorSpace='rgb') elif dkl!=None: logging.warning("Use of dkl arguments to stimuli are deprecated. Please use color and colorSpace args instead") self.setColor(dkl, colorSpace='dkl') elif lms!=None: logging.warning("Use of lms arguments to stimuli are deprecated. Please use color and colorSpace args instead") self.setColor(lms, colorSpace='lms') else: self.setColor(color) self.ori = float(ori) self.angularRes = angularRes self.radialPhase = radialPhase self.radialCycles = radialCycles self.visibleWedge = visibleWedge self.angularCycles = angularCycles self.angularPhase = angularPhase self.pos = numpy.array(pos, float) self.depth=depth self.__dict__['sf'] = 1 self.size = val2array(size, False) self.tex = tex self.mask = mask self.contrast = float(contrast) self.opacity = float(opacity) # self._triangleWidth = pi*2/self.angularRes self._angles = numpy.arange(0,pi*2, self._triangleWidth, dtype='float64') #which vertices are visible? self._visible = (self._angles>=(self.visibleWedge[0]*pi/180))#first edge of wedge self._visible[(self._angles+self._triangleWidth)*180/pi>(self.visibleWedge[1])] = False#second edge of wedge self._nVisible = numpy.sum(self._visible)*3 #do the scaling to the window coordinate system self._calcPosRendered() self._calcSizeRendered()#must be done BEFORE _updateXY self._updateTextureCoords() self._updateMaskCoords() self._updateXY() if not self.useShaders: #generate a displaylist ID self._listID = GL.glGenLists(1) self._updateList()#ie refresh display list
def __init__(self, win, text="Hello World", font="", pos=(0.0,0.0), depth=0, rgb=None, color=(1.0,1.0,1.0), colorSpace='rgb', opacity=1.0, contrast=1.0, units="", ori=0.0, height=None, antialias=True, bold=False, italic=False, alignHoriz='center', alignVert='center', fontFiles=[], wrapWidth=None, flipHoriz=False, flipVert=False, name='', autoLog=True): """ :Parameters: win: A :class:`Window` object. Required - the stimulus must know where to draw itself text: The text to be rendered height: Height of the characters (including the ascent of the letter and the descent) antialias: boolean to allow (or not) antialiasing the text bold: Make the text bold (better to use a bold font name) italic: Make the text italic (better to use an actual italic font) alignHoriz: The horizontal alignment ('left', 'right' or 'center') alignVert: The vertical alignment ('top', 'bottom' or 'center') fontFiles: A list of additional files if the font is not in the standard system location (include the full path) wrapWidth: The width the text should run before wrapping flipHoriz : boolean Mirror-reverse the text in the left-right direction flipVert : boolean Mirror-reverse the text in the up-down direction """ #what local vars are defined (these are the init params) for use by __repr__ self._initParams = dir() self._initParams.remove('self') BaseVisualStim.__init__(self, win, units=units, name=name, autoLog=False) self.useShaders = win._haveShaders #use shaders if available by default, this is a good thing self._needUpdate = True self.alignHoriz = alignHoriz self.alignVert = alignVert self.antialias = antialias self.bold=bold self.italic=italic self.text='' #NB just a placeholder - real value set below self.depth=depth self.ori=ori self.flipHoriz = flipHoriz self.flipVert = flipVert self._pygletTextObj=None self.pos= numpy.array(pos, float) #height in pix (needs to be done after units which is done during _Base.__init__) if height==None: if self.units in defaultLetterHeight: height = defaultLetterHeight[self.units] else: raise AttributeError, "TextStim does now know a default letter height for units %s" %(repr(self.units)) if wrapWidth==None: if self.units in defaultWrapWidth: wrapWidth = defaultWrapWidth[self.units] else: raise AttributeError, "TextStim does now know a default wrap width for units %s" %(repr(self.units)) #treat letter height and wrapWidth as vertices (in degFlatPos they should not be 'corrected') wh = convertToPix(pos = numpy.array([0,0]), vertices=numpy.array([wrapWidth,height]), units=self.units, win=self.win) self._wrapWidthPix, self.heightPix = wh #generate the texture and list holders self._listID = GL.glGenLists(1) if not self.win.winType=="pyglet":#pygame text needs a surface to render to self._texID = GL.GLuint() GL.glGenTextures(1, ctypes.byref(self._texID)) self.colorSpace=colorSpace if rgb!=None: logging.warning("Use of rgb arguments to stimuli are deprecated. Please use color and colorSpace args instead") self.setColor(rgb, colorSpace='rgb', log=False) else: self.setColor(color, log=False) self._calcPosRendered() for thisFont in fontFiles: pyglet.font.add_file(thisFont) self.setFont(font, log=False) self.opacity = float(opacity) self.contrast = float(contrast) self.setText(text, log=False) #self.width and self.height get set with text and calcSizeRendered is called self._needUpdate = True #set autoLog (now that params have been initialised) self.autoLog= autoLog if autoLog: logging.exp("Created %s = %s" %(self.name, str(self)))
def __init__(self, win, text="Hello World", font="", pos=(0.0, 0.0), depth=0, rgb=None, color=(1.0, 1.0, 1.0), colorSpace='rgb', opacity=1.0, contrast=1.0, units="", ori=0.0, height=None, antialias=True, bold=False, italic=False, alignHoriz='center', alignVert='center', fontFiles=[], wrapWidth=None, flipHoriz=False, flipVert=False, name='', autoLog=True): """ :Parameters: win: A :class:`Window` object. Required - the stimulus must know where to draw itself text: The text to be rendered height: Height of the characters (including the ascent of the letter and the descent) antialias: boolean to allow (or not) antialiasing the text bold: Make the text bold (better to use a bold font name) italic: Make the text italic (better to use an actual italic font) alignHoriz: The horizontal alignment ('left', 'right' or 'center') alignVert: The vertical alignment ('top', 'bottom' or 'center') fontFiles: A list of additional files if the font is not in the standard system location (include the full path) wrapWidth: The width the text should run before wrapping flipHoriz : boolean Mirror-reverse the text in the left-right direction flipVert : boolean Mirror-reverse the text in the up-down direction """ #what local vars are defined (these are the init params) for use by __repr__ self._initParams = dir() self._initParams.remove('self') BaseVisualStim.__init__(self, win, units=units, name=name, autoLog=False) self.useShaders = win._haveShaders #use shaders if available by default, this is a good thing self._needUpdate = True self.alignHoriz = alignHoriz self.alignVert = alignVert self.antialias = antialias self.bold = bold self.italic = italic self.text = '' #NB just a placeholder - real value set below self.depth = depth self.ori = ori self.wrapWidth = wrapWidth self.flipHoriz = flipHoriz self.flipVert = flipVert self._pygletTextObj = None self.pos = numpy.array(pos, float) #height in pix (needs to be done after units which is done during _Base.__init__) if self.units == 'cm': if height == None: self.height = 1.0 #default text height else: self.height = height self.heightPix = cm2pix(self.height, win.monitor) elif self.units in ['deg', 'degs']: if height == None: self.height = 1.0 else: self.height = height self.heightPix = deg2pix(self.height, win.monitor) elif self.units == 'norm': if height == None: self.height = 0.1 else: self.height = height self.heightPix = self.height * win.size[1] / 2 elif self.units == 'height': if height == None: self.height = 0.2 else: self.height = height self.heightPix = self.height * win.size[1] else: #treat units as pix if height == None: self.height = 20 else: self.height = height self.heightPix = self.height if self.wrapWidth == None: if self.units in ['height', 'norm']: self.wrapWidth = 1 elif self.units in ['deg', 'degs']: self.wrapWidth = 15 elif self.units == 'cm': self.wrapWidth = 15 elif self.units in ['pix', 'pixels']: self.wrapWidth = 500 if self.units == 'norm': self._wrapWidthPix = self.wrapWidth * win.size[0] / 2 elif self.units == 'height': self._wrapWidthPix = self.wrapWidth * win.size[0] elif self.units in ['deg', 'degs']: self._wrapWidthPix = deg2pix(self.wrapWidth, win.monitor) elif self.units == 'cm': self._wrapWidthPix = cm2pix(self.wrapWidth, win.monitor) elif self.units in ['pix', 'pixels']: self._wrapWidthPix = self.wrapWidth #generate the texture and list holders self._listID = GL.glGenLists(1) if not self.win.winType == "pyglet": #pygame text needs a surface to render to self._texID = GL.GLuint() GL.glGenTextures(1, ctypes.byref(self._texID)) self.colorSpace = colorSpace if rgb != None: logging.warning( "Use of rgb arguments to stimuli are deprecated. Please use color and colorSpace args instead" ) self.setColor(rgb, colorSpace='rgb', log=False) else: self.setColor(color, log=False) self._calcPosRendered() for thisFont in fontFiles: pyglet.font.add_file(thisFont) self.setFont(font, log=False) self.opacity = float(opacity) self.contrast = float(contrast) self.setText( text, log=False ) #self.width and self.height get set with text and calcSizeRednered is called self._needUpdate = True #set autoLog (now that params have been initialised) self.autoLog = autoLog if autoLog: logging.exp("Created %s = %s" % (self.name, str(self)))
def __init__(self, win, text="Hello World", font="", pos=(0.0,0.0), depth=0, rgb=None, color=(1.0,1.0,1.0), colorSpace='rgb', opacity=1.0, contrast=1.0, units="", ori=0.0, height=None, antialias=True, bold=False, italic=False, alignHoriz='center', alignVert='center', fontFiles=[], wrapWidth=None, flipHoriz=False, flipVert=False, name='', autoLog=True): """ :Parameters: win: A :class:`Window` object. Required - the stimulus must know where to draw itself text: The text to be rendered height: Height of the characters (including the ascent of the letter and the descent) antialias: boolean to allow (or not) antialiasing the text bold: Make the text bold (better to use a bold font name) italic: Make the text italic (better to use an actual italic font) alignHoriz: The horizontal alignment ('left', 'right' or 'center') alignVert: The vertical alignment ('top', 'bottom' or 'center') fontFiles: A list of additional files if the font is not in the standard system location (include the full path) wrapWidth: The width the text should run before wrapping flipHoriz : boolean Mirror-reverse the text in the left-right direction flipVert : boolean Mirror-reverse the text in the up-down direction """ BaseVisualStim.__init__(self, win, units=units, name=name, autoLog=autoLog) self.useShaders = win._haveShaders #use shaders if available by default, this is a good thing self._needUpdate = True self.alignHoriz = alignHoriz self.alignVert = alignVert self.antialias = antialias self.bold=bold self.italic=italic self.text='' #NB just a placeholder - real value set below self.depth=depth self.ori=ori self.wrapWidth=wrapWidth self.flipHoriz = flipHoriz self.flipVert = flipVert self._pygletTextObj=None self.pos= numpy.array(pos, float) #height in pix (needs to be done after units which is done during _Base.__init__) if self.units=='cm': if height==None: self.height = 1.0#default text height else: self.height = height self.heightPix = cm2pix(self.height, win.monitor) elif self.units in ['deg', 'degs']: if height==None: self.height = 1.0 else: self.height = height self.heightPix = deg2pix(self.height, win.monitor) elif self.units=='norm': if height==None: self.height = 0.1 else: self.height = height self.heightPix = self.height*win.size[1]/2 elif self.units=='height': if height==None: self.height = 0.2 else: self.height = height self.heightPix = self.height*win.size[1] else: #treat units as pix if height==None: self.height = 20 else: self.height = height self.heightPix = self.height if self.wrapWidth ==None: if self.units in ['height','norm']: self.wrapWidth=1 elif self.units in ['deg', 'degs']: self.wrapWidth=15 elif self.units=='cm': self.wrapWidth=15 elif self.units in ['pix', 'pixels']: self.wrapWidth=500 if self.units=='norm': self._wrapWidthPix= self.wrapWidth*win.size[0]/2 elif self.units=='height': self._wrapWidthPix= self.wrapWidth*win.size[0] elif self.units in ['deg', 'degs']: self._wrapWidthPix= deg2pix(self.wrapWidth, win.monitor) elif self.units=='cm': self._wrapWidthPix= cm2pix(self.wrapWidth, win.monitor) elif self.units in ['pix', 'pixels']: self._wrapWidthPix=self.wrapWidth #generate the texture and list holders self._listID = GL.glGenLists(1) if not self.win.winType=="pyglet":#pygame text needs a surface to render to self._texID = GL.GLuint() GL.glGenTextures(1, ctypes.byref(self._texID)) self.colorSpace=colorSpace if rgb!=None: logging.warning("Use of rgb arguments to stimuli are deprecated. Please use color and colorSpace args instead") self.setColor(rgb, colorSpace='rgb', log=False) else: self.setColor(color, log=False) self._calcPosRendered() for thisFont in fontFiles: pyglet.font.add_file(thisFont) self.setFont(font, log=False) self.opacity = float(opacity) self.contrast = float(contrast) self.setText(text, log=False) #self.width and self.height get set with text and calcSizeRednered is called self._needUpdate = True
def __init__(self, win, filename = "", units = 'pix', size = None, pos =(0.0,0.0), ori =0.0, flipVert = False, flipHoriz = False, color=(1.0,1.0,1.0), colorSpace='rgb', opacity=1.0, name='', loop=False, autoLog=True, depth=0.0,): """ :Parameters: filename : a string giving the relative or absolute path to the movie. Can be any movie that AVbin can read (e.g. mpeg, DivX) flipVert : True or *False* If True then the movie will be top-bottom flipped flipHoriz : True or *False* If True then the movie will be right-left flipped loop : bool, optional Whether to start the movie over from the beginning if draw is called and the movie is done. """ BaseVisualStim.__init__(self, win, units=units, name=name, autoLog=autoLog) if not havePygletMedia: raise ImportError, """pyglet.media is needed for MovieStim and could not be imported. This can occur for various reasons; - psychopy.visual was imported too late (after a lib that uses scipy) - no audio output is enabled (no audio card or no speakers attached) - avbin is not installed """ self._movie=None # the actual pyglet media object self._player=pyglet.media.ManagedSoundPlayer() self._player._on_eos=self._onEos self.filename=filename self.duration=None self.loop = loop if loop and pyglet.version>='1.2': logging.error("looping of movies is not currently supported for pyglet>=1.2 only for version 1.1.4") self.loadMovie( self.filename ) self.format=self._movie.video_format self.pos = numpy.asarray(pos, float) self.depth=depth self.flipVert = flipVert self.flipHoriz = flipHoriz self.colorSpace=colorSpace self.setColor(color, colorSpace=colorSpace, log=False) self.opacity = float(opacity) self.status=NOT_STARTED #size if size == None: self.size= numpy.array([self.format.width, self.format.height] , float) else: self.size = val2array(size) self.ori = ori self._calcPosRendered() self._calcSizeRendered() # enable self.contains(), overlaps(); currently win must have pix units: self._calcVertices() #check for pyglet if win.winType!='pyglet': logging.Error('Movie stimuli can only be used with a pyglet window') core.quit()
def __init__(self, win, units='', nDots=1, coherence=0.5, fieldPos=(0.0, 0.0), fieldSize=(1.0, 1.0), fieldShape='sqr', dotSize=2.0, dotLife=3, dir=0.0, speed=0.5, rgb=None, color=(1.0, 1.0, 1.0), colorSpace='rgb', opacity=1.0, contrast=1.0, depth=0, element=None, signalDots='same', noiseDots='direction', name='', autoLog=True): """ :Parameters: nDots : int number of dots to be generated fieldPos : (x,y) or [x,y] specifying the location of the centre of the stimulus. fieldSize : (x,y) or [x,y] or single value (applied to both dimensions) Sizes can be negative and can extend beyond the window. fieldShape : *'sqr'* or 'circle' Defines the envelope used to present the dots dotSize specified in pixels (overridden if `element` is specified) dotLife : int Number of frames each dot lives for (default=3, -1=infinite) dir : float (degrees) direction of the coherent dots speed : float speed of the dots (in *units*/frame) signalDots : 'same' or *'different'* If 'same' then the signal and noise dots are constant. If different then the choice of which is signal and which is noise gets randomised on each frame. This corresponds to Scase et al's (1996) categories of RDK. noiseDots : *'direction'*, 'position' or 'walk' Determines the behaviour of the noise dots, taken directly from Scase et al's (1996) categories. For 'position', noise dots take a random position every frame. For 'direction' noise dots follow a random, but constant direction. For 'walk' noise dots vary their direction every frame, but keep a constant speed. element : *None* or a visual stimulus object This can be any object that has a ``.draw()`` method and a ``.setPos([x,y])`` method (e.g. a GratingStim, TextStim...)!! See `ElementArrayStim` for a faster implementation of this idea. """ #what local vars are defined (these are the init params) for use by __repr__ self._initParams = __builtins__['dir']() self._initParams.remove('self') BaseVisualStim.__init__(self, win, units=units, name=name, autoLog=False) #set autoLog at end of init self.nDots = nDots #pos and size are ambiguous for dots so DotStim explicitly has #fieldPos = pos, fieldSize=size and then dotSize as additional param self.fieldPos = self.pos = val2array(fieldPos, False, False) self.fieldSize = self.size = val2array(fieldSize, False) if type(dotSize) in [tuple, list]: self.dotSize = numpy.array(dotSize) else: self.dotSize = dotSize self.fieldShape = fieldShape self.dir = dir self.speed = speed self.element = element self.dotLife = dotLife self.signalDots = signalDots self.noiseDots = noiseDots self.opacity = float(opacity) self.contrast = float(contrast) self.useShaders = False #not needed for dots? self.colorSpace = colorSpace if rgb != None: logging.warning( "Use of rgb arguments to stimuli are deprecated. Please use color and colorSpace args instead" ) self.setColor(rgb, colorSpace='rgb') else: self.setColor(color) self.depth = depth #initialise the dots themselves - give them all random dir and then #fix the first n in the array to have the direction specified self.coherence = round( coherence * self.nDots) / self.nDots #store actual coherence self._verticesBase = self._dotsXY = self._newDotsXY( self.nDots) #initialise a random array of X,Y self._dotsSpeed = numpy.ones( self.nDots, 'f') * self.speed #all dots have the same speed self._dotsLife = abs(dotLife) * numpy.random.rand( self.nDots) #abs() means we can ignore the -1 case (no life) #determine which dots are signal self._signalDots = numpy.zeros(self.nDots, dtype=bool) self._signalDots[0:int(self.coherence * self.nDots)] = True #numpy.random.shuffle(self._signalDots)#not really necessary #set directions (only used when self.noiseDots='direction') self._dotsDir = numpy.random.rand(self.nDots) * 2 * pi self._dotsDir[self._signalDots] = self.dir * pi / 180 self._update_dotsXY() self.autoLog = autoLog if autoLog: logging.exp("Created %s = %s" % (self.name, str(self)))
def __init__( self, win, filename="", units='pix', size=None, pos=(0.0, 0.0), ori=0.0, flipVert=False, flipHoriz=False, color=(1.0, 1.0, 1.0), colorSpace='rgb', opacity=1.0, volume=1.0, name='', loop=False, autoLog=True, depth=0.0, ): """ :Parameters: filename : a string giving the relative or absolute path to the movie. Can be any movie that AVbin can read (e.g. mpeg, DivX) flipVert : True or *False* If True then the movie will be top-bottom flipped flipHoriz : True or *False* If True then the movie will be right-left flipped volume : The nominal level is 1.0, and 0.0 is silence, see pyglet.media.Player loop : bool, optional Whether to start the movie over from the beginning if draw is called and the movie is done. """ #what local vars are defined (these are the init params) for use by __repr__ self._initParams = dir() self._initParams.remove('self') BaseVisualStim.__init__(self, win, units=units, name=name, autoLog=False) if not havePygletMedia: raise ImportError, """pyglet.media is needed for MovieStim and could not be imported. This can occur for various reasons; - psychopy.visual was imported too late (after a lib that uses scipy) - no audio output is enabled (no audio card or no speakers attached) - avbin is not installed """ self._movie = None # the actual pyglet media object self._player = pyglet.media.ManagedSoundPlayer() self._player.volume = volume self._player_default_on_eos = self._player._on_eos self.filename = filename self.duration = None self.loop = loop if loop and pyglet.version >= '1.2': logging.error( "looping of movies is not currently supported for pyglet>=1.2 only for version 1.1.4" ) self.loadMovie(self.filename) self.format = self._movie.video_format self.pos = numpy.asarray(pos, float) self.depth = depth self.flipVert = flipVert self.flipHoriz = flipHoriz self.colorSpace = colorSpace self.setColor(color, colorSpace=colorSpace, log=False) self.opacity = float(opacity) self.status = NOT_STARTED #size if size == None: self.size = numpy.array([self.format.width, self.format.height], float) else: self.size = val2array(size) self.ori = ori self._updateVertices() #check for pyglet if win.winType != 'pyglet': logging.error( 'Movie stimuli can only be used with a pyglet window') core.quit() #set autoLog (now that params have been initialised) self.autoLog = autoLog if autoLog: logging.exp("Created %s = %s" % (self.name, str(self)))
def __init__(self, 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, contrast=1.0, depth=0, interpolate=True, lineRGB=None, fillRGB=None, name='', autoLog=True): """ :Parameters: 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? interpolate : True or False If True the edge of the line will be antialiased. """ #what local vars are defined (these are the init params) for use by __repr__ self._initParams = dir() self._initParams.remove('self') # Initialize inheritance and remove unwanted methods BaseVisualStim.__init__(self, win, units=units, name=name, autoLog=False) #autoLog is set later self.__dict__['setColor'] = None self.__dict__['color'] = None self.__dict__['colorSpace'] = None self.contrast = float(contrast) self.opacity = float(opacity) self.pos = numpy.array(pos, float) self.closeShape = closeShape self.lineWidth = lineWidth self.interpolate = interpolate # Color stuff self.useShaders = False #since we don't ned to combine textures with colors self.__dict__['lineColorSpace'] = lineColorSpace self.__dict__['fillColorSpace'] = fillColorSpace if lineRGB != None: logging.warning( "Use of rgb arguments to stimuli are deprecated. Please use color and colorSpace args instead" ) self.setLineColor(lineRGB, colorSpace='rgb') else: self.setLineColor(lineColor, colorSpace=lineColorSpace) if fillRGB != None: logging.warning( "Use of rgb arguments to stimuli are deprecated. Please use color and colorSpace args instead" ) self.setFillColor(fillRGB, colorSpace='rgb') else: self.setFillColor(fillColor, colorSpace=fillColorSpace) # Other stuff self.depth = depth self.ori = numpy.array(ori, float) self.size = numpy.array([0.0, 0.0]) self.setSize(size, log=False) self.setVertices(vertices, log=False) #set autoLog (now that params have been initialised) self.autoLog = autoLog if autoLog: logging.exp("Created %s = %s" % (self.name, str(self)))