本文整理匯總了Python中surface.Surface.stroke方法的典型用法代碼示例。如果您正苦於以下問題:Python Surface.stroke方法的具體用法?Python Surface.stroke怎麽用?Python Surface.stroke使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類surface.Surface
的用法示例。
在下文中一共展示了Surface.stroke方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: render
# 需要導入模塊: from surface import Surface [as 別名]
# 或者: from surface.Surface import stroke [as 別名]
def render(self, text, antialias=True, color=(0,0,0), background=None, surface=None): #optional surface for text rendering
"""
Render text onto surface.
Arguments are text to render, and optional antialias, RGB color of text, RGB color of background, and surface for text rendering.
"""
if not surface:
w,h = self.size(text)
surf = Surface((w,h))
else:
surf = surface
w,h = surface.width, surface.height
if background:
surf.setFillStyle(Color(background))
surf.fillRect(0,0,w,h)
surf.setFont('%s %dpx %s' % (self.fontstyle, self.fontsize, self.fontname))
# if antialias: pass
surf.setFillStyle(Color(color))
surf.fillText(text,0,self.fontsize)
if self.underline:
surf.setLineWidth(1)
surf.setStrokeStyle(Color(color))
surf.setStroke(BasicStroke(1))
surf.moveTo(0, h-1)
surf.lineTo(w-1, h-1)
surf.stroke()
return surf
示例2: arc
# 需要導入模塊: from surface import Surface [as 別名]
# 或者: from surface.Surface import stroke [as 別名]
def arc(self, surface, color, rect, start_angle, stop_angle, width=1):
"""
Draw arc shape, and returns bounding Rect.
Argument include surface to draw, color, rect, start_angle, stop_angle.
Optional width argument of outline.
"""
if hasattr(rect, 'width'):
_rect = rect
else:
_rect = Rect(rect)
if _rect.width == _rect.height:
surface.beginPath()
surface.arc(_rect.x+int(_rect.width/2), _rect.y+int(_rect.height/2), int(_rect.width/2), -start_angle, -stop_angle, True)
if width:
surface.setLineWidth(width)
if hasattr(color, 'a'):
surface.setStrokeStyle(color)
else:
surface.setStrokeStyle(Color(color))
surface.stroke()
else:
surface.closePath()
if hasattr(color, 'a'):
surface.setFillStyle(color)
else:
surface.setFillStyle(Color(color))
surface.fill()
else:
if _rect.width < _rect.height:
dim = _rect.height
else:
dim = _rect.width
surf = Surface((dim,dim))
surf.beginPath()
xdim = int(dim/2)
surf.arc(xdim, xdim, xdim, -start_angle, -stop_angle, True)
if width:
surf.setLineWidth(width)
if hasattr(color, 'a'):
surface.setStrokeStyle(color)
else:
surface.setStrokeStyle(Color(color))
surf.stroke()
else:
surface.closePath()
if hasattr(color, 'a'):
surface.setFillStyle(color)
else:
surface.setFillStyle(Color(color))
surf.fill()
surface.drawImage(surf.canvas, 0, 0, dim, dim, _rect.x, _rect.y, _rect.width, _rect.height) #pyjs0.8 *.canvas
if surface._display:
return surface._display._surface_rect.clip(_rect)
else:
return surface.get_rect().clip(_rect)