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


Python Surface.lock方法代码示例

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


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

示例1: render

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import lock [as 别名]
    def render(self, text, antialias = True, 
               forecolor=(255, 255, 255, 255), 
               backcolor=(255, 255, 255, 0)):
        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 0,
            NSBackgroundColorAttributeName: _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))
            #print "surface size is ", size

            filter_size = self.shadow_filter_size()
            border = self.border_size()
            
            result = []
            result_size = (size[0] + border*2, size[1] + border*2)
            #print "result size is ", result_size
            for y in range(result_size[1]):
                result.append([(0, 0, 0, 0)] * result_size[0])
            
            # Filter the character appropriately.
            s.lock()
            for y in range(size[1]):
                for x in range(size[0]):
                    color = s.get_at((x, y))
                    s.set_at((x, y), (255, 255, 255, color[3]))

            if filter_size == 3:
                factors = [[1, 2, 1],
                           [2, 4, 2],
                           [1, 2, 1]]
            elif filter_size == 5:
                factors = [[1,  4,  6,  4,  1],
                           [4,  16, 24, 16, 4],
                           [6,  24, 36, 24, 6],
                           [4,  16, 24, 16, 4],
                           [1,  4,  6,  4,  1]]
            elif filter_size == 7:
                factors = [[1,  6,   15,  20,  15,  6,   1],
                           [6,  36,  90,  120, 90,  36,  6],
                           [15, 90,  225, 300, 225, 90,  15],
                           [20, 120, 300, 400, 300, 120, 20],
                           [15, 90,  225, 300, 225, 90,  15],
                           [6,  36,  90,  120, 90,  36,  6],
                           [1,  6,   15,  20,  15,  6,   1]]
            else:
                print "factors for filter size", filter_size, "not defined!"
                factors = 0

            # Filter a shadow.
            for ry in range(result_size[1]):
                for rx in range(result_size[0]):
                    inpos = (rx - int(border), ry - int(border))
                    count = 0
                    colorsum = 0
                    u = 0
                    v = 0
                    for a in filter_range(filter_size):
                        v = 0
                        for b in filter_range(filter_size):
                            x, y = (inpos[0] + a, inpos[1] + b)
                            factor = factors[u][v]
                            if x >= 0 and y >= 0 and x < size[0] and y < size[1]:
                                colorsum += factor * s.get_at((x, y))[3]
                            count += factor
                            v += 1
                        u += 1
                    if count > 0:
                        result_color = (int(colorsum) + count/2) / count
                    else:
                        result_color = 0
                    result[ry][rx] = (0, 0, 0, min(255, result_color*1.4))

            # Blend the glyph itself to the result.
            for y in range(size[1]):
                for x in range(size[0]):
                    color = s.get_at((x, y))
                    result[border + y][border + x] = \
                        alpha_blend(color, result[border + y][border + x])
                    result[border + y][border + x] = \
                        alpha_blend(color, result[border + y][border + x])
                    #result[border + y][border + x] = \
                    #    alpha_blend(color, result[border + y][border + x])

            s.unlock()
                    
            glyph_rgba = Numeric.array(result, typecode=Numeric.UnsignedInt8)
            return glyph_rgba, result_size
开发者ID:cmbruns,项目名称:Doomsday-Engine,代码行数:102,代码来源:createfont_osx.py

示例2: randint

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import lock [as 别名]
    return noise.snoise2((x+cdx),(y+cdy),1,1) > 0.5

mdx = randint(-2048,2048)
mdy = randint(-2048,2048)
def spouses(x, y):
    global mdx
    global mdy
    m = noise.snoise2((x+mdx),(y+mdy),1,1)
    m = max(0, m)
    return int(4*m) + 1

shownoise = '-shownoise' in [a.lower() for a in argv]
           
background = Surface(screen.get_size())
if shownoise:
    background.lock()
    for y in range(0, background.get_height()):
        for x in range(0, background.get_width()):
            background.set_at((x,y), grayvalue(noiseat(x,y)))
    background.unlock()
else:
    background.fill((255,255,255))

screen.blit(background, (0,0))

sprites = Group()

def personat(x,y):
    return noiseat(x*8,y*8) <= 0.95

for x in range(0, background.get_width(), 8):
开发者ID:tps12,项目名称:Generation-Generation,代码行数:33,代码来源:main.py

示例3: VisualTimer

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import lock [as 别名]
class VisualTimer(object):
    """
    Display a timer
    """

    def __init__(self, finish, rect=None, color=(255, 255, 255)):
        self.time = 0
        self.finish = float(finish)

        if rect == None:
            rect = Rect(0, 0, 100, 16)

        self.rect = Rect(rect)

        self.size = self.rect.width
        self.color = color

        self.image = Surface(self.rect.size)
        self.finished = 0

    def set_alarm(self, time):
        self.finish = float(time)
        self.reset()

    def reset(self):
        self.time = 0
        self.finished = 0

    def update(self, time):
        if self.finished:
            return

        time += self.time

        if time <= self.finish:
            self.time = time
        else:
            self.finished = 1

    def draw(self, surface):
        if not self.finished:
            self.render()

        surface.blit(self.image, self.rect.topleft)

    def render(self):
        i = ceil(self.size * (self.time / self.finish))

        w, h = self.rect.size
        self.image.lock()

        self.image.fill((32, 32, 32))
        self.image.fill(self.color, (0, 0, i, self.rect.height))

        # Make the corners look pretty
        self.image.fill((0, 0, 0), (0, 0, 1, 1))
        self.image.fill((0, 0, 0), (w - 1, 0, 1, 1))
        self.image.fill((0, 0, 0), (w - 1, h - 1, 1, 1))
        self.image.fill((0, 0, 0), (0, h - 1, 1, 1))

        self.image.unlock()
开发者ID:bitcraft,项目名称:mh,代码行数:63,代码来源:gui.py


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