当前位置: 首页>>代码示例>>Python>>正文


Python Surface.convert_alpha方法代码示例

本文整理汇总了Python中pygame.Surface.convert_alpha方法的典型用法代码示例。如果您正苦于以下问题:Python Surface.convert_alpha方法的具体用法?Python Surface.convert_alpha怎么用?Python Surface.convert_alpha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygame.Surface的用法示例。


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

示例1: compileSVASheet

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert_alpha [as 别名]
def compileSVASheet(sheet, color):
    color = tuple([255-c for c in color])
    
    width = sheet.get_width()
    height = sheet.get_height() / 3
    
    colorSurf = Surface((width, height))
    colorSurf.fill(color)
    
    colorSurf.blit(sheet, (0, 0), None, BLEND_MULT)
    
    # Now create a white surface so we can invert the Saturation map
    result = Surface((width, height), SRCALPHA)
    result.fill((255, 255, 255))
    
    result.blit(colorSurf, (0, 0), None, BLEND_RGB_SUB)
    
    # Multiply this with the Value Map
    result.blit(sheet, (0, -height), None, BLEND_MULT)
    
    # copy the alpha mask from the spritesheet
    alpha = Surface((width, height))
    alpha.blit(sheet, (0, -2 * height))
    
    #convert the (nearly done) Surface to per pixel alpha
    result.convert_alpha()
    
    # Use Numpy here
    numWhite = surfarray.pixels_alpha( result )
    
    numAlpha = surfarray.pixels3d( alpha )
    
    numWhite[ :, : ] = numAlpha[ :, :, 0 ]
    
    return result.copy()
开发者ID:roSievers,项目名称:Orbital4,代码行数:37,代码来源:recolor.py

示例2: set_alpha_from_intensity

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert_alpha [as 别名]
def set_alpha_from_intensity(surface, alpha_factor, decay_mode, color):
    if not HAS_PIL:
        raise Exception("PIL was not found on this machine.")
    if not HAS_NUMPY:
        raise Exception("NumPy was not found on this machine.")
    rect = surface.get_rect()
    newsurf = Surface(rect.size, SRCALPHA, depth=surface.get_bitsize())
    newsurf = newsurf.convert_alpha()
    newsurf.blit(surface, (0, 0))
    arrayrgb = surfarray.pixels3d(newsurf)
    arraya = surfarray.pixels_alpha(newsurf)
    bulk_color = tuple(color)
    for x in range(rect.left, rect.right):
        for y in range(rect.top, rect.bottom):
            color = tuple(arrayrgb[x][y])
            light = square_color_norm(color)
            alpha = float(light)/MAX_NORM * 255
            arrayrgb[x][y][0] = bulk_color[0]
            arrayrgb[x][y][1] = bulk_color[1]
            arrayrgb[x][y][2] = bulk_color[2]
            if decay_mode == "linear":
                actual_alpha = int(255 - alpha)
            elif decay_mode == "exponential":
                tuning_factor = 1.03
                actual_alpha = int(255*tuning_factor**-alpha)
##            elif decay_mode == "quadratic":
##                pass
            else:
                raise Exception("decay_mode not recognized: " + decay_mode)
            actual_alpha *= alpha_factor
            arraya[x][y] = actual_alpha
    return newsurf
开发者ID:YannThorimbert,项目名称:ThorPy-1.0,代码行数:34,代码来源:pilgraphics.py

示例3: render

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert_alpha [as 别名]
    def render(self, text, antialias, forecolor, backcolor=(0,0,0,255)):
        size = self.size(text)
        img = NSImage.alloc().initWithSize_(size)
        img.lockFocus()

        NSString.drawAtPoint_withAttributes_(text, (0.0, 0.0), {
            NSFontAttributeName: self._font,
            NSUnderlineStyleAttributeName: self._isUnderline and 1.0 or None,
            NSBackgroundColorAttributeName: backcolor and _getColor(backcolor) or None,
            NSForegroundColorAttributeName: _getColor(forecolor),
        })

        rep = NSBitmapImageRep.alloc().initWithFocusedViewRect_(((0.0, 0.0), size))
        img.unlockFocus()
        if rep.samplesPerPixel() == 4:
            s = Surface(size, SRCALPHA|SWSURFACE, 32, [-1<<24,0xff<<16,0xff<<8,0xff])
            
            a = Numeric.reshape(Numeric.fromstring(rep.bitmapData(), typecode=Numeric.Int32), (size[1], size[0]))
            blit_array(s, Numeric.swapaxes(a,0,1))
            return s.convert_alpha()
开发者ID:123jefferson,项目名称:MiniBloq-Sparki,代码行数:22,代码来源:macfont.py

示例4: Creature

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert_alpha [as 别名]
class Creature(Sprite):
    '''
        Class represents a 
    '''
    def __init__(self, x=0, y=0, theta=0):
        self.y = x
        self.y = y
        self.theta = theta
        self.v = 1
        self.energy = 5000 + abs(50 * randn())
        self.brain = createEmpty(10, 10)
        self.width = CREATURE_WIDTH
        self.height = CREATURE_HEIGHT
        
        self.senses = []
        
        self.base_image = Surface((self.width, self.height), pygame.SRCALPHA, 32)
        self.base_image = self.base_image.convert_alpha()
        
        self.brain_data = None
        
        self.rect = (0, 0, self.width, self.height)
        self._render()
        self.image = pygame.transform.rotate(self.base_image, theta)
        
    ''' updates the creature for the next round '''
    def tick(self):
        self.brain.elapseTime(10, [(randrange(1, 1000) * 1.0)/ 1000 for _ in xrange(10)])
        self.y -= math.sin(deg2rad(self.theta)) * self.v
        self.y += math.cos(deg2rad(self.theta)) * self.v 
        self.theta += (random.randrange(60)) - 30
        self.image = pygame.transform.rotate(self.base_image, self.theta)
        
    ''' rendering for the basic, ugly creature '''
    def _render(self):
        pygame.draw.circle(self.base_image, pygame.Color(0, 128, 64), (self.width/2, self.height/2), self.width/2, self.width/2)
        s = sqrt(2) * 12
        pygame.draw.rect(self.base_image, pygame.Color(0, 128, 64), (round(12.5 - s/2), round(12.5 - s/2), s, s))
        pygame.draw.line(self.base_image, pygame.Color(255, 10, 10), (12, 12), (24, 12), 1)
开发者ID:justonium,项目名称:BrainEvolver,代码行数:41,代码来源:Creature.py

示例5: load_pygame

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert_alpha [as 别名]
def load_pygame(filename):
    """
    load a tiled TMX map for use with pygame
    """

    from pygame import Surface
    import pygame, os

    tiledmap = load_tmx(filename)

    # cache will find duplicate tiles to reduce memory usage
    # mostly this is a problem in the blank areas of a tilemap
    cache = {}

    # just a precaution to make sure tileset images are added in the correct order
    for firstgid, t in sorted([(t.firstgid, t) for t in tiledmap.tilesets]):
        path = os.path.join(os.path.dirname(tiledmap.filename), t.source)

        image = pygame.image.load(path)

        w, h = image.get_rect().size

        tile_size = (t.tilewidth, t.tileheight)

        # some tileset images may be slightly larger than the tiles area
        # ie: may include a banner, copyright, etc.  this compensates for that
        for y in range(0, int(h / t.tileheight) * t.tileheight, t.tileheight):
            for x in range(0, int(w / t.tilewidth) * t.tilewidth, t.tilewidth):

                # somewhat handle transparency, though colorkey handling is not tested
                if t.trans is None:
                    tile = Surface(tile_size, pygame.SRCALPHA)
                else:
                    tile = Surface(tile_size)

                # blit the smaller portion onto a new image from the larger one
                tile.blit(image, (0, 0), ((x, y), tile_size))

                # make a unique id for this image, not sure if this is the best way, but it works
                key = pygame.image.tostring(tile, "RGBA")

                # make sure we don't have a duplicate tile
                try:
                    tile = cache[key]
                except KeyError:
                    if t.trans is None:
                        tile = tile.convert_alpha()
                    else:
                        tile = tile.convert()
                        tile.set_colorkey(t.trans)

                    # update the cache
                    cache[key] = tile

                tiledmap.images.append(tile)

    # correctly handle transformed tiles.  currently flipped tiles
    # work by creating a new gid for the flipped tile and changing the gid
    # in the layer to the new gid.
    for layer in tiledmap.tilelayers:
        for x, y, gid, trans in layer.flipped_tiles:
            fx = trans & FLIP_X == FLIP_X
            fy = trans & FLIP_Y == FLIP_Y

            tile = pygame.transform.flip(tiledmap.images[gid], fx, fy)
            tiledmap.images.append(tile)

            # change the original gid in the layer data to the new gid
            layer.data[y][x] = len(tiledmap.images) - 1

        del layer.flipped_tiles
    del cache

    return tiledmap
开发者ID:Robmaister,项目名称:RPI-Game-Jam-9-22-12,代码行数:76,代码来源:tmxloader3.py

示例6: Level

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert_alpha [as 别名]

#.........这里部分代码省略.........
        """
        Decides what to do with the block, based on the block type (sigh), and performs
        appropriate action
        :param block: Block to operate on
        :param item: If the block has a hard-assigned item in level, it will be spawned
        :param func: Function of the block that returns its points-value
        :return:
        """
        return_v = func()
        if isinstance(block, BlockExplosive):
            rect = block.rect
            self.entities.append(Explosion(rect.x + rect.width/2 - Explosion.WIDTH/2,
                                           rect.y + rect.height/2 - Explosion.HEIGHT/2))

        if block.dead:
            self.player.add_points(return_v)
            self.block_count -= 1
            if not isinstance(block, BlockExplosive):
                self.spawn_item(block.rect.x, block.rect.y, item)
        self.blocks_surface_dirty = True

    def draw(self):
        """
        Method called each frame to (re)draw the objects and UI
        :return:
        """
        self.screen.blit(Assets.background, (self.draw_offset[0], self.draw_offset[1]))

        self.screen.blit(Assets.border, (self.draw_offset[0], self.draw_offset[1]))
        self.screen.blit(Assets.border, (self.draw_offset[0] + LEVEL_WIDTH - PLAYFIELD_PADDING[0],
                                         self.draw_offset[1]))
        if self.blocks_surface_dirty:
            self.blocks_surface = Surface((LEVEL_WIDTH, LEVEL_HEIGHT), SRCALPHA, 32)
            self.blocks_surface = self.blocks_surface.convert_alpha()
            self.blocks_surface_dirty = False
            for row in self.blocks:
                for block in row:
                    if block is not None and not block.dead:
                        block.draw(self.blocks_surface)
        self.screen.blit(self.blocks_surface, self.draw_offset)
        self.paddle.draw(self.screen, self.draw_offset)

        if not self.ball.dead:
            self.ball.draw(self.screen, self.draw_offset)

        # draw entities
        for entity in self.entities:
            if not entity.dead:
                entity.draw(self.screen, self.draw_offset)

        # draw upper bar
        draw.rect(self.screen, (0, 0, 0), (self.draw_offset[0] + PLAYFIELD_PADDING[0], self.draw_offset[1],
                                           LEVEL_WIDTH - PLAYFIELD_PADDING[0] * 2, PLAYFIELD_PADDING[1]))

        self.screen.blit(self.score_label,
                         (self.draw_offset[0] + PLAYFIELD_PADDING[0] + 10, self.draw_offset[1]))
        self.screen.blit(self.lives_label,
                         (self.draw_offset[0] + PLAYFIELD_PADDING[0] + 150, self.draw_offset[1]))
        self.screen.blit(self.level_label,
                         (self.draw_offset[0] + LEVEL_WIDTH - 100, self.draw_offset[1]))

    def update(self):
        """
        Method called each frame, to update the state of entities based on input events and
        previous state of the game
        :return:
开发者ID:Kranek,项目名称:BlockBuster,代码行数:70,代码来源:levels.py

示例7: simple_alpha_frame

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert_alpha [as 别名]
def simple_alpha_frame(size, color=constants.BRIGHT, alpha=200):
    surface = Surface(size, flags=SRCALPHA)
    color = gac(color, alpha)
    surface.fill(color)
    return surface.convert_alpha()
开发者ID:YannThorimbert,项目名称:Thorpy-1.5.2a,代码行数:7,代码来源:graphics.py

示例8: __init__

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import convert_alpha [as 别名]
class hud:

    def __init__(self, statusBarWidth=100, hpBarHeight=25, spBarHeight=10,
        screenWidth=1024, screenHeight=768, HPBarMaxColor=(50,20,20),
        SPBarMaxColor=(100,100,100), HPBarCurrentColor=(155,20,20),
        SPBarCurrentColor=(200,200,200), eventWindowColor = (20,20,20,200), nameMargin = 10):

        self.screenWidth = screenWidth
        self.screenHeight = screenHeight

        self.statusBarWidth = statusBarWidth

        self.HPBarMaxB1Dim = Rect(0,0,self.statusBarWidth,hpBarHeight)
        self.SPBarMaxB1Dim = Rect(0,hpBarHeight,self.statusBarWidth,spBarHeight)
        self.HPBarMaxB2Dim = Rect(self.screenWidth-self.statusBarWidth,0,self.statusBarWidth,hpBarHeight)
        self.SPBarMaxB2Dim = Rect(self.screenWidth-self.statusBarWidth,hpBarHeight,self.statusBarWidth,spBarHeight)

        self.HPBarCurrentB1Dim = Rect(0,0,self.statusBarWidth,hpBarHeight)
        self.SPBarCurrentB1Dim = Rect(0,hpBarHeight,self.statusBarWidth,spBarHeight)
        self.HPBarCurrentB2Dim = Rect(self.screenWidth-self.statusBarWidth,0,self.statusBarWidth,hpBarHeight)
        self.SPBarCurrentB2Dim = Rect(self.screenWidth-self.statusBarWidth,hpBarHeight,self.statusBarWidth,spBarHeight)

        self.HPBarMaxColor = HPBarMaxColor
        self.SPBarMaxColor = SPBarMaxColor
        self.HPBarCurrentColor = HPBarCurrentColor
        self.SPBarCurrentColor = SPBarCurrentColor

        self.nameMargin = nameMargin

        #self.timeDim = Rect(x,y,Width,Height)

        self.eventWindowDim = Rect(0,self.screenHeight/4*3,self.screenWidth,self.screenHeight)
        self.eventWindowSurface = Surface((int(self.screenWidth),int(self.screenHeight/4)), flags=SRCALPHA)
        self.eventWindowSurface.fill(eventWindowColor)
        self.eventWindowSurface.convert_alpha()
        self.eventWindowTextPos = (10,0)
        self.events = []

        self.timeDim = None


        self.eventWindowColor = eventWindowColor #Color(eventWindowColor[0],eventWindowColor[1],eventWindowColor[2],eventWindowColor[3],)

        self.nameFont = font.SysFont("Arial",12)
        self.timeFont = font.SysFont("Arial",20)
        self.roundFont = font.SysFont("Arial",12)
        self.eventWindowFont = font.SysFont("Arial",12)

    def updateHPBars(self, B1HPpercent, B2HPpercent):
        B1HPCurrentWidth = B1HPpercent * self.statusBarWidth
        B2HPCurrentWidth = B2HPpercent * self.statusBarWidth
        self.HPBarCurrentB1Dim.left = self.statusBarWidth-B1HPCurrentWidth
        self.HPBarCurrentB1Dim.width = B1HPCurrentWidth
        self.HPBarCurrentB2Dim.width = B2HPCurrentWidth


    def updateSPBars(self, B1SPpercent, B2SPpercent):
        B1SPCurrentWidth = B1SPpercent * self.statusBarWidth
        B2SPCurrentWidth = B2SPpercent * self.statusBarWidth

        self.SPBarCurrentB1Dim.left = self.statusBarWidth-B1SPCurrentWidth
        self.SPBarCurrentB1Dim.width = B1SPCurrentWidth
        self.SPBarCurrentB2Dim.width = B2SPCurrentWidth
开发者ID:ffists7,项目名称:fbsim,代码行数:65,代码来源:hud.py


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