當前位置: 首頁>>代碼示例>>Python>>正文


Python Rectangle.draw方法代碼示例

本文整理匯總了Python中rectangle.Rectangle.draw方法的典型用法代碼示例。如果您正苦於以下問題:Python Rectangle.draw方法的具體用法?Python Rectangle.draw怎麽用?Python Rectangle.draw使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rectangle.Rectangle的用法示例。


在下文中一共展示了Rectangle.draw方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: BoundedActor

# 需要導入模塊: from rectangle import Rectangle [as 別名]
# 或者: from rectangle.Rectangle import draw [as 別名]
class BoundedActor( Actor ):
  """
    Actor class with bounding rectangle
  """
  def __init__( self, **kwargs ):
    """

      Keyword Arguments: 
        - model: 
        - texture: 
        - drawmode: 
        - rectdim: 
        - boundoffset: (x,y) offset of bounding rectangle from (0,0) in model coordinates, used
                       to position the bounding rectangle within the actor model
      
      self, model, texture=None, drawmode='polygon'
    """
    try:
      texture  = kwargs.get( 'texture', None )
      drawmode = kwargs.get( 'drawmode', 'polygon' )
      self._boundoffset = kwargs.get( 'boundoffset', (0,0) )
      super(BoundedActor,self).__init__( kwargs['model'], texture, drawmode )

      self._bound = Rectangle( **kwargs )
    except KeyError:
      print "Bounded Actor requires a model"
#=================================================================================================
  def draw( self, pos, name,drawbound=False ):
    """
    """
    super(BoundedActor,self).draw(pos,name)
    if drawbound: self._bound.draw((pos[0]+self._boundoffset[0],pos[1]+self._boundoffset[1]),name)
    else: self._bound.updatepos( (pos[0]+self._boundoffset[0],pos[1]+self._boundoffset[1]) )
#=================================================================================================
  def collide(self,point):
    """
    """
    return self._bound.collide(point)
開發者ID:doggerelverse,項目名稱:gelly,代碼行數:40,代碼來源:boundedactor.py

示例2: Map

# 需要導入模塊: from rectangle import Rectangle [as 別名]
# 或者: from rectangle.Rectangle import draw [as 別名]

#.........這裏部分代碼省略.........
			self.simStats.btPlaceTarget.setEnabled(False)
			self.simStats.btPlaceRobot.setEnabled(True)
			
			self.repaint()
			
		elif self.mouseActionType == Map.PlaceBlockAction:
			
			self.dragXend = x
			self.dragYend = y
			
			self.dragObject.updateDrag(self.dragXstart, self.dragYstart,
					self.dragXend, self.dragYend)
		
			self.objects.append(self.dragObject)
			self.dragObject = None
		
			self.saveToImage = True
			self.setChanged(True)
		
			self.mouseActionType = Map.NoAction
			#TODO
			#print(QMouseEvent.pos())
			self.repaint()
	
	
	def paintEvent(self, event):
		rect = self.contentsRect()
		
		if self.saveToImage == True:
			
			ImageMap.image = QtGui.QImage(rect.right(), rect.bottom(), QtGui.QImage.Format_RGB32)
			imagePainter = QtGui.QPainter(ImageMap.image)
			
			self.draw(imagePainter)
			
			ImageMap.image.save('image.jpg')
			
			self.saveToImage = False
	
		painter = QtGui.QPainter(self)
		self.draw(painter)
	
	
	def draw(self, painter):
		
		rect = self.contentsRect()
		
		painter.setPen(QtGui.QColor(0xff0000))
		#TODO
		#QtCore.qDebug('[sim_map.Map.paintEvent] %d %d %d %d' % (rect.top(), rect.left(), rect.bottom(), rect.right())) 
		painter.fillRect(0, 0, rect.right(), rect.bottom(), QtGui.QColor(0xffffff))
		
		for obj in self.objects:
			obj.draw(painter)
		
		if not self.dragObject is None:
			self.dragObject.draw(painter)
			
		if self.robot is not None and self.saveToImage != True:
			self.robot.draw(painter)
		
		if self.target is not None and self.saveToImage != True:
			self.target.draw(painter)
	
	
	def keyPressEvent(self, event):
開發者ID:paulvlase,項目名稱:intelligent_car,代碼行數:70,代碼來源:sim_map.py


注:本文中的rectangle.Rectangle.draw方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。