本文整理汇总了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)
示例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):