def test_chop_subsurface(surface): """Test transform.chop with a subsurface as the source""" obj = _make_object() surface.blit(obj, (20, 20)) obj_sub = obj.subsurface((20, 20, 20, 15)) obj1 = transform.chop(obj_sub, (10, 10, 10, 10)) obj2 = transform.chop(obj_sub, (10, 10, 0, 0)) # Chop out everything obj3 = transform.chop(obj_sub, (0, 0, 20, 15)) surface.blit(obj_sub, (20, 190)) surface.blit(obj1, (80, 190)) surface.blit(obj2, (160, 190)) surface.blit(obj3, (190, 190))
def test_chop(surface): """Simple tests of transform.chop""" obj = _make_object() obj1 = transform.chop(obj, (10, 10, 10, 10)) obj2 = transform.chop(obj, (10, 10, 20, 20)) obj3 = transform.chop(obj, (0, 0, 100, 100)) obj4 = transform.chop(obj, (5, 5, 50, 50)) surface.blit(obj, (20, 20)) surface.blit(obj1, (80, 20)) surface.blit(obj2, (160, 20)) surface.blit(obj3, (240, 20)) surface.blit(obj4, (320, 20))
def __animate(self, game): if ((game.frame % self.animInterval) == 0): self.anim_frame += 1 if (self.anim_frame > self.maxFrames): self.anim_frame = 1 if (self.anim_frame <= 0): self.anim_frame = self.maxFrames imageString = self.sprname + "_" + str(self.anim_frame) # if we flip the y then we must move adjust the rect.x if self.flips[1]: self.rect.x = self.orgRect.x + self.posPercent * self.orgRect.height - self.orgRect.height + TILE_SIZE else: self.rect.x = self.orgRect.x # clip part of the image img = transform.chop(game.images[imageString][0], Rect(0,0,0,self.posPercent * self.orgRect.height)) # apply flipping and rotation if required if self.flips[0] or self.flips[1]: img = transform.flip(img, self.flips[0], self.flips[1]) if self.rotation != 0: img = transform.rotate(img, self.rotation) self.setimage(img)
def __animate(self, game): if ((game.frame % self.animInterval) == 0): self.anim_frame += 1 if (self.anim_frame > self.maxFrames): self.anim_frame = 1 if (self.anim_frame <= 0): self.anim_frame = self.maxFrames imageString = self.sprname + "_" + str(self.anim_frame) # if we flip the y then we must move adjust the rect.x if self.flips[1]: self.rect.x = self.orgRect.x + self.posPercent * self.orgRect.height - self.orgRect.height + TILE_SIZE else: self.rect.x = self.orgRect.x # clip part of the image img = transform.chop( game.images[imageString][0], Rect(0, 0, 0, self.posPercent * self.orgRect.height)) # apply flipping and rotation if required if self.flips[0] or self.flips[1]: img = transform.flip(img, self.flips[0], self.flips[1]) if self.rotation != 0: img = transform.rotate(img, self.rotation) self.setimage(img)
def __animate(self, g): #rotate the image (creates new surface) img = transform.rotate(g.images[self.sprname][0], self.rotation) # now since the surface is rotated it is also bigger so we need to clip it so # that the size is same as the original surface's size, this is really slow rect = img.get_rect() ydif = (rect.height - self.orgRect.height) / 2 xdif = (rect.width - self.orgRect.width) / 2 img = transform.chop(img, Rect(0, rect.height - ydif, 0, ydif)) img = transform.chop(img, Rect(0, 0, 0, ydif)) img = transform.chop(img, Rect(rect.width - xdif, 0, xdif, 0)) img = transform.chop(img, Rect(0, 0, xdif, 0)) self.setimage(img)
def link(file_name_1, file_name_2): try: image1 = load(file_name_1).convert_alpha() image2 = load(file_name_2).convert_alpha() w, h = image1.get_size() image1 = chop(image1, (0, 0, 0, h - half_y)) w, h = image1.get_size() w2, h2 = image2.get_size() to_image = Image.new('RGB', (w, h + h2)) save(image1, file_name_1) open_image = Image.open(file_name_1) to_image.paste(open_image, (0, 0)) open_image = Image.open(file_name_2) to_image.paste(open_image, (0, h)) to_image.save(file_name_1) #image3=load(file_name_1).convert_alpha() trans(file_name_1) return 0 except: print(file_name_1 + ' failed') return 1
def test_chop(surface): """Simple tests of transform.chop""" obj = _make_object() obj1 = transform.chop(obj, (10, 10, 10, 10)) obj2 = transform.chop(obj, (10, 10, 20, 20)) obj3 = transform.chop(obj, (0, 0, 100, 100)) obj4 = transform.chop(obj, (5, 5, 50, 50)) surface.blit(obj, (20, 20)) surface.blit(obj1, (80, 20)) surface.blit(obj2, (160, 20)) surface.blit(obj3, (240, 20)) surface.blit(obj4, (320, 20)) obj_sub = obj.subsurface((20, 20, 20, 15)) obj1 = transform.chop(obj_sub, (10, 10, 10, 10)) obj2 = transform.chop(obj_sub, (10, 10, 0, 0)) # Chop out everything obj3 = transform.chop(obj_sub, (0, 0, 20, 15)) surface.blit(obj_sub, (20, 190)) surface.blit(obj1, (80, 190)) surface.blit(obj2, (160, 190)) surface.blit(obj3, (190, 190))