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
def convert_image(self, image): """ Return the image as a Surface. """ if env.canvas._isCanvas: img = image.getElement() surface = Surface((img.width,img.height)) surface.drawImage(image, 0, 0) else: surface = Surf(image) return surface
def convert_image(self, image): """ Return the image as a Surface. """ if env.canvas._isCanvas: img = image.getElement() surface = Surface((img.width, img.height)) surface.drawImage(image, 0, 0) else: surface = Surf(image) return surface
def scale(self, surface, size, dest=None): """ Return Surface resized by the given size. An optional destination surface can be provided. """ if not dest: surf = Surface(size) else: surf = dest surf.drawImage(surface.canvas, 0, 0, surface.get_width(), surface.get_height(), 0, 0, size[0], size[1]) #pyjs0.8 *.canvas # surf.drawImage(surface, 0, 0, surface.get_width(), surface.get_height(), 0, 0, size[0], size[1]) return surf
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