本文整理汇总了Python中psychopy.tools.monitorunittools.convertToPix函数的典型用法代码示例。如果您正苦于以下问题:Python convertToPix函数的具体用法?Python convertToPix怎么用?Python convertToPix使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了convertToPix函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _updateVertices
def _updateVertices(self):
"""
"""
#then combine with position and convert to pix
pos = convertToPix(vertices = [0,0], pos = self.pos, units=self.units, win=self.win)
size = convertToPix(vertices = self.size, pos = 0, units=self.units, win=self.win)
try:
size=size[0]
except:
pass
#assign to self attrbute
self.__dict__['posPix'] = pos
self.__dict__['sizePix'] = size
self._needVertexUpdate = False
示例2: _updateVertices
def _updateVertices(self):
"""Sets Stim.verticesPix from fieldPos and
"""
#Handle the orientation, size and location of each element in native units
#
radians = 0.017453292519943295
verts = numpy.zeros([self.nElements*4, 3],'d')
#rotate 'width' and 'height' and find their effects on X and Y
wx = -self.sizes[:,0]*numpy.cos(self.oris[:]*radians)/2
wy = self.sizes[:,0]*numpy.sin(self.oris[:]*radians)/2
hx = self.sizes[:,1]*numpy.sin(self.oris[:]*radians)/2
hy = self.sizes[:,1]*numpy.cos(self.oris[:]*radians)/2
#X
verts[0::4,0] = + wx + hx#TopR
verts[1::4,0] = - wx + hx#TopL
verts[2::4,0] = - wx - hx#BotL
verts[3::4,0] = + wx - hx#BotR
#Y
verts[0::4,1] = + wy + hy
verts[1::4,1] = - wy + hy
verts[2::4,1] = - wy - hy
verts[3::4,1] = + wy - hy
#Z
verts[:,2] = 1#self.depths + self.fieldDepth
#Now shift by fieldPos and convert to appropriate units
pos = numpy.tile(self.xys+self.fieldPos, (1,4)).reshape([self.nElements*4,2])
verts[:,:2] = convertToPix(vertices = verts[:,:2], pos = pos, units=self.units, win = self.win)
#assign to self attrbute
self.__dict__['verticesPix'] = numpy.require(verts,requirements=['C'])#make sure it's contiguous
self._needVertexUpdate = False
示例3: posPix
def posPix(self):
"""This determines the coordinates in pixels of the position for the
current stimulus, accounting for pos and units. This property should
automatically update if `pos` is changed"""
#because this is a property getter we can check /on-access/ if it needs updating :-)
if self._needVertexUpdate:
self.__dict__['posPix'] = convertToPix(vertices = [0,0], pos = self.pos, units=self.units, win = self.win)
self._needVertexUpdate = False
return self.__dict__['posPix']
示例4: setHeight
def setHeight(self,height, log=True):
"""Set the height of the letters (including the entire box that surrounds the letters
in the font). The width of the letters is then defined by the font.
"""
self.heightPix = convertToPix(pos = numpy.array([0,0]),
vertices=numpy.array([0,height]),
units=self.units, win=self.win)[1]
#need to update the font to reflect the change
self.setFont(self.fontname, log=False)
logAttrib(self, log, 'height', height)
示例5: setHeight
def setHeight(self, height, log=True):
"""Set the height of the letters (including the entire box that surrounds the letters
in the font). The width of the letters is then defined by the font.
"""
self.heightPix = convertToPix(
pos=numpy.array([0, 0]), vertices=numpy.array([0, height]), units=self.units, win=self.win
)[1]
# need to update the font to reflect the change
self.setFont(self.fontname, log=False)
if log and self.autoLog:
self.win.logOnFlip("Set %s height=%.2f" % (self.name, height), level=logging.EXP, obj=self)
示例6: wrapWidth
def wrapWidth(self, wrapWidth):
"""Int/float or None (set default).
The width the text should run before wrapping.
:ref:`Operations <attrib-operations>` supported."""
if wrapWidth is 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))
self.__dict__['wrapWidth'] = wrapWidth
self._wrapWidthPix = convertToPix(pos = numpy.array([0, 0]), vertices=numpy.array([self.wrapWidth, 0]), units=self.units, win=self.win)[0]
self._needSetText = True
示例7: height
def height(self, height):
"""Float/int or None (set default).
The height of the letters (including the entire box that surrounds the letters
in the font). The width of the letters is then defined by the font.
:ref:`Operations <attrib-operations>` supported."""
#height in pix (needs to be done after units which is done during _Base.__init__)
if height is 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))
self.__dict__['height'] = height
self._heightPix = convertToPix(pos = numpy.array([0, 0]), vertices=numpy.array([0, self.height]), units=self.units, win=self.win)[1]
#need to update the font to reflect the change
self.setFont(self.font, log=False)
示例8: _updateVertices
def _updateVertices(self):
"""Sets Stim.verticesPix from fieldPos.
"""
# Handle the orientation, size and location of
# each element in native units
radians = 0.017453292519943295
# so we can do matrix rotation of coords we need shape=[n*4,3]
# but we'll convert to [n,4,3] after matrix math
verts = numpy.zeros([self.nElements * 4, 3], 'd')
wx = -self.sizes[:, 0] * numpy.cos(self.oris[:] * radians) / 2
wy = self.sizes[:, 0] * numpy.sin(self.oris[:] * radians) / 2
hx = self.sizes[:, 1] * numpy.sin(self.oris[:] * radians) / 2
hy = self.sizes[:, 1] * numpy.cos(self.oris[:] * radians) / 2
# X vals of each vertex relative to the element's centroid
verts[0::4, 0] = -wx - hx
verts[1::4, 0] = +wx - hx
verts[2::4, 0] = +wx + hx
verts[3::4, 0] = -wx + hx
# Y vals of each vertex relative to the element's centroid
verts[0::4, 1] = -wy - hy
verts[1::4, 1] = +wy - hy
verts[2::4, 1] = +wy + hy
verts[3::4, 1] = -wy + hy
# set of positions across elements
positions = self.xys + self.fieldPos
# depth
verts[:, 2] = self.depths + self.fieldDepth
# rotate, translate, scale by units
if positions.shape[0] * 4 == verts.shape[0]:
positions = positions.repeat(4, 0)
verts[:, :2] = convertToPix(vertices=verts[:, :2], pos=positions,
units=self.units, win=self.win)
verts = verts.reshape([self.nElements, 4, 3])
# assign to self attribute; make sure it's contiguous
self.__dict__['verticesPix'] = numpy.require(verts,
requirements=['C'])
self._needVertexUpdate = False
示例9: contains
def contains(self, x, y=None, units=None):
"""Determines if a point x,y is inside the extent of the stimulus.
Can accept variety of input options:
+ two separate args, x and y
+ one arg (list, tuple or array) containing two vals (x,y)
+ an object with a getPos() method that returns x,y, such
as a :class:`~psychopy.event.Mouse`. Returns `True` if the point is
within the area defined by `vertices`.
This method handles complex shapes, including concavities and self-crossings.
Note that, if your stimulus uses a mask (such as a Gaussian blob) then
this is not accounted for by the `contains` method; the extent of the
stmulus is determined purely by the size, pos and orientation settings
(and by the vertices for shape stimuli).
See coder demo, shapeContains.py
"""
#get the object in pixels
if hasattr(x, 'verticesPix'):
xy = x.verticesPix #access only once - this is a property (slower to access)
units = 'pix' #we can forget about the units
elif hasattr(x, 'getPos'):
xy = x.getPos()
units = x.units
elif type(x) in [list, tuple, numpy.ndarray]:
xy = numpy.array(x)
else:
xy = numpy.array((x,y))
#try to work out what units x,y has
if units is None:
if hasattr(xy, 'units'):
units = xy.units
else:
units = self.units
if units != 'pix':
xy = convertToPix(xy, pos=0, units=units, win=self.win)
# ourself in pixels
selfVerts = self.verticesPix
return pointInPolygon(xy[0], xy[1], poly = selfVerts)
示例10: _updateVertices
def _updateVertices(self):
"""Sets Stim.verticesPix from pos and size
"""
if hasattr(self, 'vertices'):
verts = self.vertices
else:
verts = self._verticesBase
#check wheher stimulus needs flipping in either direction
flip = numpy.array([1,1])
if hasattr(self, 'flipHoriz'):
flip[0] = self.flipHoriz*(-2)+1#True=(-1), False->(+1)
if hasattr(self, 'flipVert'):
flip[1] = self.flipVert*(-2)+1#True=(-1), False->(+1)
# set size and orientation
verts = numpy.dot(self.size*verts*flip, self._rotationMatrix)
#then combine with position and convert to pix
verts = convertToPix(vertices=verts, pos=self.pos, win=self.win, units=self.units)
#assign to self attrbute
self.__dict__['verticesPix'] = verts
self._needVertexUpdate = False
self._needUpdate = True #but we presumably need to update the list
示例11: _calcPosRendered
def _calcPosRendered(self):
"""Calculate the pos of the stimulus in pixels"""
self._posRendered = convertToPix(pos=self.pos,
vertices=numpy.array([0, 0]),
units=self.units, win=self.win)
示例12: __init__
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')
super(TextStim, self).__init__(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)
#.........这里部分代码省略.........