本文整理汇总了Python中surface.Surface.translate方法的典型用法代码示例。如果您正苦于以下问题:Python Surface.translate方法的具体用法?Python Surface.translate怎么用?Python Surface.translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类surface.Surface
的用法示例。
在下文中一共展示了Surface.translate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rotate
# 需要导入模块: from surface import Surface [as 别名]
# 或者: from surface.Surface import translate [as 别名]
def rotate(self, surface, angle):
"""
Return Surface rotated by the given angle.
"""
if not angle:
return surface.copy()
theta = angle*self.deg_rad
width_i = surface.get_width()
height_i = surface.get_height()
cos_theta = math.fabs( math.cos(theta) )
sin_theta = math.fabs( math.sin(theta) )
width_f = int( (width_i*cos_theta)+(height_i*sin_theta) )
height_f = int( (width_i*sin_theta)+(height_i*cos_theta) )
if width_f%2:
width_f += 1
if height_f%2:
height_f += 1
surf = Surface((width_f,height_f))
surf.saveContext()
surf.translate(width_f/2.0, height_f/2.0)
surf.rotate(-theta)
surf.drawImage(surface.canvas, -width_i/2, -height_i/2) #pyjs0.8 *.canvas
# surf.drawImage(surface, -width_i/2, -height_i/2)
surf.restoreContext()
return surf
示例2: flip
# 需要导入模块: from surface import Surface [as 别名]
# 或者: from surface.Surface import translate [as 别名]
def flip(self, surface, xbool=True, ybool=False):
"""
Return Surface that is flipped horizontally, vertically, or both.
"""
surf = Surface((surface.get_width(),surface.get_height()))
surf.saveContext()
if xbool and ybool:
surf.translate(surface.get_width(), surface.get_height())
surf.scale(-1, -1)
elif xbool:
surf.translate(surface.get_width(), 0)
surf.scale(-1, 1)
elif ybool:
surf.translate(0, surface.get_height())
surf.scale(1, -1)
surf.drawImage(surface.canvas, 0, 0) #pyjs0.8 *.canvas
# surf.drawImage(surface, 0, 0)
surf.restoreContext()
return surf