Пример #1
0
 def rotozoom(self, surface, angle, size):
     """
     Return Surface rotated and resized by the given angle and size.
     """
     if not angle:
         width = int(surface.get_width() * size)
         height = int(surface.get_height() * size)
         return self.scale(surface, (width, height))
     theta = angle * self.deg_rad
     width_i = int(surface.get_width() * size)
     height_i = int(surface.get_height() * size)
     cos_theta = _fabs(_cos(theta))
     sin_theta = _fabs(_sin(theta))
     width_f = int(_ceil((width_i * cos_theta) + (height_i * sin_theta)))
     if width_f % 2:
         width_f += 1
     height_f = int(_ceil((width_i * sin_theta) + (height_i * cos_theta)))
     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, 0, 0, surface.get_width(),
                    surface.get_height(), -width_i / 2, -height_i / 2,
                    width_i, height_i)
     surf.restoreContext()
     return surf
Пример #2
0
 def rotozoom(self, surface, angle, size):
     """
     Return Surface rotated and resized by the given angle and size.
     """
     if not angle:
         width = int(surface.get_width()*size)
         height = int(surface.get_height()*size)
         return self.scale(surface, (width, height))
     theta = angle*self.deg_rad
     width_i = int(surface.get_width()*size)
     height_i = int(surface.get_height()*size)
     cos_theta = _fabs( _cos(theta) )
     sin_theta = _fabs( _sin(theta) )
     width_f = int( _ceil((width_i*cos_theta)+(height_i*sin_theta)) )
     if width_f % 2:
         width_f += 1
     height_f = int( _ceil((width_i*sin_theta)+(height_i*cos_theta)) )
     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, 0, 0, surface.get_width(), surface.get_height(), -width_i/2, -height_i/2, width_i, height_i)
     surf.restoreContext()
     return surf
Пример #3
0
 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 = _fabs(_cos(theta))
     sin_theta = _fabs(_sin(theta))
     width_f = int((width_i * cos_theta) + (height_i * sin_theta))
     height_f = int((width_i * sin_theta) + (height_i * cos_theta))
     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)
     surf.restoreContext()
     return surf
Пример #4
0
 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 = _fabs( _cos(theta) )
     sin_theta = _fabs( _sin(theta) )
     width_f = int( (width_i*cos_theta)+(height_i*sin_theta) )
     height_f = int( (width_i*sin_theta)+(height_i*cos_theta) )
     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)
     surf.restoreContext()
     return surf