本文整理匯總了Python中surface.Surface.rotate方法的典型用法代碼示例。如果您正苦於以下問題:Python Surface.rotate方法的具體用法?Python Surface.rotate怎麽用?Python Surface.rotate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類surface.Surface
的用法示例。
在下文中一共展示了Surface.rotate方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: rotate
# 需要導入模塊: from surface import Surface [as 別名]
# 或者: from surface.Surface import rotate [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