• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python mask.from_surface函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pygame.mask.from_surface函数的典型用法代码示例。如果您正苦于以下问题:Python from_surface函数的具体用法?Python from_surface怎么用?Python from_surface使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了from_surface函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

 def __init__(self, x, y, paddle_color, parent=None, owner=None):
     """
     Initialize it with spawn position
     :param x: x coordinate of the play-field
     :param y: y coordinate of the play-field
     :param paddle_color:
     :param parent: ?
     :param owner: ?
     :return:
     """
     Sprite.__init__(self)
     self.vx = 0
     self.vy = 0
     self.speed = 10
     self.paddle_color = paddle_color
     self.image = Assets.paddles[paddle_color]  # pygame.image.load("gfx/paddle.png")
     self.mask = mask.from_surface(self.image)
     self.rect = self.image.get_rect()
     self.rect.x = x
     self.rect.y = y
     self.attachment_points = [(8, 0), (self.rect.width-8, 0)]
     self.attachments = []
     # self.attachments = [LaserGunAttachment(self)]
     self.parent = parent
     self.owner = owner
开发者ID:Kranek,项目名称:BlockBuster,代码行数:25,代码来源:paddle.py


示例2: test_from_surface

    def test_from_surface(self):
        """  Does the mask.from_surface() work correctly?
        """

        mask_from_surface = mask.from_surface

        surf = surface.Surface((70,70), SRCALPHA, 32)

        surf.fill((255,255,255,255))

        amask = mask.from_surface(surf)
        #amask = mask_from_surface(surf)

        self.assertEqual(amask.get_at((0,0)), 1)
        self.assertEqual(amask.get_at((66,1)), 1)
        self.assertEqual(amask.get_at((69,1)), 1)

        surf.set_at((0,0), (255,255,255,127))
        surf.set_at((1,0), (255,255,255,128))
        surf.set_at((2,0), (255,255,255,0))
        surf.set_at((3,0), (255,255,255,255))

        amask = mask_from_surface(surf)
        self.assertEqual(amask.get_at((0,0)), 0)
        self.assertEqual(amask.get_at((1,0)), 1)
        self.assertEqual(amask.get_at((2,0)), 0)
        self.assertEqual(amask.get_at((3,0)), 1)

        surf.fill((255,255,255,0))
        amask = mask_from_surface(surf)
        self.assertEqual(amask.get_at((0,0)), 0)
开发者ID:CTPUG,项目名称:pygame_cffi,代码行数:31,代码来源:mask_test.py


示例3: change_size

    def change_size(self, new_width):
        """
        Function used to change the size of the palette. Rebuilds image from source and
        generates new collision Rect
        :param new_width: new Paddle width in pixels (min. 22px)
        :return:
        """
        paddleAsset = Assets.paddles[self.paddle_color]
        new_width = max(new_width, 22)  # 22 = (border(8) + colorbar(3))*2
        paddle_mid = Surface((38, 15))  # (2*paddle.rect.width, paddle.rect.height))
        # paddle_mid.blit(self.image, (0, 0), Rect(11, 0, 38, 15))
        paddle_mid.blit(paddleAsset, (0, 0), Rect(11, 0, 38, 15))
        paddle_mid = transform.scale(paddle_mid, (new_width-22, self.rect.height))
        new_paddle = Surface((new_width, self.rect.height), SRCALPHA)  # blank surface
        # new_paddle.fill(pygame.Color(0, 0, 0, 0), new_paddle.get_rect())
        new_paddle.blit(paddle_mid, (11, 0))
        new_paddle.blit(paddleAsset, (0, 0), Rect(0, 0, 11, 15))
        new_paddle.blit(paddleAsset, (new_width - 11, 0),
                        Rect(paddleAsset.get_rect().width - 11, 0, 11, 15))
        paddle_new_x = self.rect.x + self.rect.width/2 - new_paddle.get_rect().width/2
        self.rect = Rect(paddle_new_x, self.rect.y, new_paddle.get_rect().width,
                         new_paddle.get_rect().height)
        self.mask = mask.from_surface(new_paddle)
        self.image = new_paddle
        self.attachment_points[1] = (self.rect.width-8, 0)
        # self.paddle.attachment_points[1] =

        if self.rect.x <= PLAYFIELD_PADDING[0]:
            self.rect.x = PLAYFIELD_PADDING[0] + 1
        elif self.rect.x + self.rect.width >= LEVEL_WIDTH - PLAYFIELD_PADDING[0]:
            self.rect.x = LEVEL_WIDTH - PLAYFIELD_PADDING[0] - self.rect.width - 1
开发者ID:Kranek,项目名称:BlockBuster,代码行数:31,代码来源:paddle.py


示例4: text

 def text(self, value):
     self._text = value
     self.image = self._render(value)
     self.rect = Rect((self.rect[0], self.rect[1]), self.image.get_rect()[2:])
     self.col_rect = self.rect.copy()
     self.mask = mask.from_surface(self.image)
     self.create_feet()
开发者ID:Fenixin,项目名称:yogom,代码行数:7,代码来源:textsprites.py


示例5: __init__

 def __init__(self, tag, initial_position, rotation=0, fontname=DEFAULT_FONT, fontzoom=5):
     Sprite.__init__(self)
     self.tag = copy(tag)
     self.rotation = rotation
     
     font_spec = load_font(fontname)
     
     #fonter = font.Font(os.path.join(FONT_DIR, font_spec['ttf']), int(tag['size'] * fontzoom)).render(tag['tag'], True, tag['color'])
     # changing to allow for arbitrary local fonts
     fonter = font.Font(font_spec['ttf'], int(tag['size'] * fontzoom)).render(tag['tag'], True, tag['color'])
     self.tag['size'] *= fontzoom
     fonter = transform.rotate(fonter, rotation)
     frect = fonter.get_bounding_rect()
     frect.x = -frect.x
     frect.y = -frect.y
     self.fontoffset = (-frect.x, -frect.y)
     font_sf = Surface((frect.width, frect.height), pygame.SRCALPHA, 32)
     font_sf.blit(fonter, frect)
     self.image = font_sf
     self.rect = font_sf.get_rect()
     self.rect.width += TAG_PADDING
     self.rect.height += TAG_PADDING
     self.rect.x = initial_position[0]
     self.rect.y = initial_position[1]
     self.mask = mask.from_surface(self.image)
     self.mask = self.mask.convolve(CONVMASK, None, (TAG_PADDING, TAG_PADDING))
开发者ID:davepeake,项目名称:PyTagCloud,代码行数:26,代码来源:__init__.py


示例6: flip

 def flip(self):
     pos = (self.rect.x, self.rect.y)
     angle = 90 if self.rotation == 0 else - 90
     self.image = transform.rotate(self.image, angle)
     self.rect = self.image.get_rect()
     self.rect.x, self.rect.y = pos
     self.mask = mask.from_surface(self.image)
     self.mask = self.mask.convolve(CONVMASK, None, (TAG_PADDING, TAG_PADDING))
开发者ID:mooseburger,项目名称:PyTagCloud,代码行数:8,代码来源:__init__.py


示例7: __init__

 def __init__(self, game, pos, direction, speed=4):
     Sprite.__init__(self)
     self.game = game
     self.image = game.get_tile_surface('b.dot')
     self.mask = mask.from_surface(self.image)
     self.pos = Vector(pos)
     self.direction = direction
     self.speed = speed
开发者ID:krother,项目名称:tilegamelib,代码行数:8,代码来源:invaders.py


示例8: collides

	def collides(self,monster):
		"""
			Checks if the monster collides with a specific monster
		"""
		if self.rect.colliderect(monster.rect):
			#Here need to pix perfect collision
 			trectmonst = self.rect.clip(monster.rect).move(-monster.rect.x,-monster.rect.y)
 			trectstick = self.rect.clip(monster.rect).move(-self.rect.x,-self.rect.y)

			tmonstmask = mask.from_surface(monster.image.subsurface(trectmonst))
 			tcurrentmask = mask.from_surface(self.image.subsurface(trectstick))

			col = tcurrentmask.overlap(tmonstmask,(0,0))
                	if col == None: return False,0,0
                	else: return True,col[0]+self.rect.x,col[1]+self.rect.y

		else: return False,0,0
开发者ID:FertileMule,项目名称:pykurin,代码行数:17,代码来源:cMonster.py


示例9: map_collision

 def map_collision(self, mapp, obj_rect, obj_mask):
     """Return True if map and object collide"""
     surf_map = Surface((obj_rect.width, obj_rect.height),
                        pygame.SRCALPHA)
     surf_map.blit(mapp.collision_text, (0, 0), obj_rect)
     mask_map = mask.from_surface(surf_map)
     if mask_map.overlap(obj_mask, (0, 0)) is not None:
         return True
     return False
开发者ID:PetarDDobrev,项目名称:Python-Final-Project,代码行数:9,代码来源:collision.py


示例10: __init__

 def __init__(self, sprite_filename, speed):
 
     Sprite.__init__(self)
     
     self.image = pygame.image.load(sprite_filename).convert_alpha()
     self.rect = self.image.get_rect()
     self.mask = mask.from_surface(self.image)
     
     self.speed = speed
开发者ID:rubiximus,项目名称:yars-revenge,代码行数:9,代码来源:asprite.py


示例11: __init__

 def __init__(self, x, y, w, h):
     Sprite.__init__(self)
     self.image = Surface((w, h), SRCALPHA, 32)        
     self.image.fill((255,0,0))
     self.rect = self.image.get_rect()
     self.rect.x = x
     self.rect.y = y
     self.mask = mask.from_surface(self.image)
     
     self.border = Surface((self.rect.width, self.rect.height), SRCALPHA, 32)        
     pygame.draw.rect(self.border, (255, 0, 0), Rect(0 , 0, self.rect.width , self.rect.height), 1)
开发者ID:niksite,项目名称:PyTagCloud,代码行数:11,代码来源:intersection_tests.py


示例12: collide

	def collide(self, group):
		if self.sprite.maskDirty:
			self.sprite.maskDirty = False
			AVRSprite.spriteLock.acquire()
			self.sprite.mask = mask.from_surface(self.transformedSurface)
			AVRSprite.spriteLock.release()
		
		sprites = sprite.spritecollide(self.sprite, group.group, False)
		results = []
		for s in sprites:
			if s == self.sprite:
				continue
			if s.maskDirty:
				s.maskDirty = False
				AVRSprite.spriteLock.acquire()
				s.mask = mask.from_surface(s.AVRSprite.transformedSurface)
				AVRSprite.spriteLock.release()
			if sprite.collide_mask(self.sprite, s) != None:
				results.append(s.AVRSprite.handle)
		return results
开发者ID:eddiecastropineda,项目名称:CollegeBound,代码行数:20,代码来源:AVRSprite.py


示例13: split_row

def split_row(parent, parent_cols, row, height, width):
    """split_frame helper function
    splits a single row of source surface
    """
    
    images = []
    masks = []
    
    for col in range(parent_cols):
        current_image = parent.subsurface((col*width, row*height, width, height))
        images.append(current_image)
        masks.append(mask.from_surface(current_image))
        
    return images, masks
开发者ID:rubiximus,项目名称:yars-revenge,代码行数:14,代码来源:animated_facing_sprite.py


示例14: test_from_surface_2

    def test_from_surface_2(self):
        surf = surface.Surface((300, 100), depth=32, flags=SRCALPHA)
        surf.fill((0, 0, 0, 0xff))
        for x in range(200):
            surf.set_at((x, 20), (0, 0, 0, x))
        M = mask.from_surface(surf)
        self.assertEqual(M.get_at((0, 0)), 1)
        self.assertEqual(M.get_at((20, 20)), 0)
        self.assertEqual(M.get_at((21, 20)), 0)
        self.assertEqual(M.get_at((50, 20)), 0)
        self.assertEqual(M.get_at((127, 20)), 0)
        self.assertEqual(M.get_at((128, 20)), 1)
        self.assertEqual(M.get_at((129, 20)), 1)
        self.assertEqual(M.get_at((200, 20)), 1)
        self.assertEqual(M.get_at((21, 21)), 1)
        # Different threshold

        M = mask.from_surface(surf, 50)
        self.assertEqual(M.get_at((50, 20)), 0)
        self.assertEqual(M.get_at((51, 20)), 1)
        self.assertEqual(M.get_at((127, 20)), 1)
        self.assertEqual(M.get_at((128, 20)), 1)
        self.assertEqual(M.get_at((129, 20)), 1)
开发者ID:CTPUG,项目名称:pygame_cffi,代码行数:23,代码来源:mask_test.py


示例15: __init__

    def __init__(self, word, word_o, color, angle):
        Sprite.__init__(self)
        self.word = word
        self.angle = angle

        # Determine Word dimensions
        w_rect = word_o.get_bounding_rect()
        w_rect.x = -w_rect.x + WORD_PADDING
        w_rect.y = -w_rect.y + WORD_PADDING
        w_rect.width += WORD_PADDING * 2
        w_rect.height += WORD_PADDING * 2

        # Draw Word on a surface
        word_sf = Surface((w_rect.width, w_rect.height), SRCALPHA, 32)
        word_sf.blit(word_o, w_rect)
        self.rect = word_sf.get_rect()
        self.image = word_sf.copy()
        self.msf = word_sf.copy()

        # Create custom mask
        m1 = mask.from_surface(self.msf)
        cr, crw = [], []
        for c in [x for x in range(w_rect.width) if x % PXL == 0]:
            for r in [y for y in range(w_rect.height) if y % PXL == 0]:
                if m1.get_at((c, r)) != 0:
                    crw.append((c - PXL, r - PXL))
                    crw.append((c - PXL, r))
                    crw.append((c, r - PXL))
                    crw.append((c, r))
                    crw.append((c + PXL, r + PXL))
                    crw.append((c, r + PXL))
                    crw.append((c + PXL, r))
                    crw.append((c + PXL, r - PXL))
                    crw.append((c - PXL, r + PXL))
                    cr.append((c, r))
        for c, r in crw:
            draw.rect(self.msf, color, Rect((c, r), (PXL, PXL)))
        for i in enumerate(cr):
            c, r = i[1]
            j = 1
            if i[0] + 1 >= len(cr):
                break
            next_cr = cr[i[0] + 1]
            while next_cr[0] == c and next_cr[1] != r + PXL * j:
                draw.rect(self.msf, color, Rect((c, r + j * PXL), (PXL, PXL)))
                j += 1

        self._rotate()
开发者ID:nullicorn,项目名称:scwordcloudapp,代码行数:48,代码来源:word.py


示例16: __init__

 def __init__(self, x, y, owner=None):
     """
     Init with owner to give him points for each destroyed block
     :param x: x coordinate of the play-field
     :param y: y coordinate of the play-field
     :param owner: Player-class object
     :return:
     """
     Sprite.__init__(self)
     self.vx = 0
     self.vy = -8
     self.image = Assets.projectile_laser
     self.rect = self.image.get_rect()
     self.rect.x = x
     self.rect.y = y
     self.mask = from_surface(self.image)
     self.owner = owner
     self.dead = False
开发者ID:Kranek,项目名称:BlockBuster,代码行数:18,代码来源:projectiles.py


示例17: pygame_convert

def pygame_convert(original, colorkey, force_colorkey, pixelalpha):
    """
    this method does several tests on a surface to determine the optimal
    flags and pixel format for each tile.

    this is done for the best rendering speeds and removes the need to
    convert() the images on your own

    original is a surface and MUST NOT HAVE AN ALPHA CHANNEL
    """
    from pygame import Surface, mask, RLEACCEL
    
    tile_size = original.get_size()

    # count the number of pixels in the tile that are not transparent
    px = mask.from_surface(original).count()

    # there are no transparent pixels in the image
    if px == tile_size[0] * tile_size[1]:
        tile = original.convert()

    # there are transparent pixels, and set to force a colorkey
    elif force_colorkey:
        tile = Surface(tile_size)
        tile.fill(force_colorkey)
        tile.blit(original, (0,0))
        tile.set_colorkey(force_colorkey, RLEACCEL)

    # there are transparent pixels, and tiled set a colorkey
    elif colorkey:
        tile = original.convert()
        tile.set_colorkey(colorkey, RLEACCEL)

    # there are transparent pixels, and set for perpixel alpha
    elif pixelalpha:
        tile = original.convert_alpha()

    # there are transparent pixels, and we won't handle them
    else:
        tile = original.convert()

    return tile
开发者ID:shackra,项目名称:PyTMX,代码行数:42,代码来源:tmxloader.py


示例18: __init__

 def __init__(self, tag, initial_position, rotation=0, fontname='fonts/Arial.ttf', fontzoom=5):
     Sprite.__init__(self)
     self.tag = tag
     self.rotation = rotation
     fonter = font.Font(fontname, int(tag['size'] * fontzoom)).render(tag['tag'], True, tag['color'])
     self.tag['size'] *= fontzoom
     fonter = transform.rotate(fonter, rotation)
     frect = fonter.get_bounding_rect()
     frect.x = -frect.x
     frect.y = -frect.y
     self.fontoffset = (-frect.x, -frect.y)
     font_sf = Surface((frect.width, frect.height), pygame.SRCALPHA, 32)
     font_sf.blit(fonter, frect)
     self.image = font_sf
     self.rect = font_sf.get_rect()
     self.rect.width += TAG_PADDING
     self.rect.height += TAG_PADDING
     self.rect.x = initial_position[0]
     self.rect.y = initial_position[1]
     self.mask = mask.from_surface(self.image)
     self.mask = self.mask.convolve(CONVMASK, None, (TAG_PADDING, TAG_PADDING))
开发者ID:mooseburger,项目名称:PyTagCloud,代码行数:21,代码来源:__init__.py


示例19: init_masks

    def init_masks(self):
        """ Init the mask for the sprite. 

        NOTE: any additional rect created must be, in general, inside
        of col_rect. That way collisions will work properly
        
        """
        
        # Create a mask with the image
        # TODO, NOTE TO SELF: The mask will use the first frame
        # in the animation! ALWAYS
        self.mask = mask.from_surface(self.image)
        #~ self.view_mask()

        # Feet mask
        self.feet_mask = mask.Mask((self.rect.width, 1))
        h = self.rect.height
        s_at = self.feet_mask.set_at
        g_at = self.mask.get_at
        for x in xrange(self.rect.width):
            if g_at((x, h - 1)):
                s_at((x, 0), 1)
开发者ID:Fenixin,项目名称:yogom,代码行数:22,代码来源:sprites.py


示例20: Surface

ECCENTRICITY = 1.5

LOWER_START = 0.45
UPPER_START = 0.55

FONT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fonts')
DEFAULT_FONT = 'Droid Sans'
DEFAULT_PALETTE = 'default'
FONT_CACHE = simplejson.load(open(os.path.join(FONT_DIR, 'fonts.json'), 'r'))

pygame.init()
convsurf = Surface((2 * TAG_PADDING, 2 * TAG_PADDING))
convsurf.fill((255, 0, 255))
convsurf.set_colorkey((255, 0, 255))
draw.circle(convsurf, (0, 0, 0), (TAG_PADDING, TAG_PADDING), TAG_PADDING)
CONVMASK = mask.from_surface(convsurf)

LAYOUT_HORIZONTAL = 0
LAYOUT_VERTICAL = 1
LAYOUT_MOST_HORIZONTAL = 2
LAYOUT_MOST_VERTICAL = 3
LAYOUT_MIX = 4

LAYOUTS = (
           LAYOUT_HORIZONTAL,
           LAYOUT_VERTICAL,
           LAYOUT_MOST_HORIZONTAL,
           LAYOUT_MOST_VERTICAL,
           LAYOUT_MIX
           )
开发者ID:johnlaudun,项目名称:PyTagCloud,代码行数:30,代码来源:__init__.py



注:本文中的pygame.mask.from_surface函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python midi.get_count函数代码示例发布时间:2022-05-25
下一篇:
Python image.load函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap