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


Python Surface.set_at方法代码示例

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


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

示例1: test_bottom

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import set_at [as 别名]
 def test_bottom(self):
     """
     L{loadTerrainFromSurface} places a single C{GRASS} voxel for a
     zero-valued pixel in the image data.
     """
     surface = Surface((1, 1))
     surface.set_at((0, 0), (0, 0, 0))
     terrain = loadTerrainFromSurface(surface)
     self.assertEquals(terrain.dict(), {(0, 0, 0): GRASS})
开发者ID:eriknelson,项目名称:gam3,代码行数:11,代码来源:test_terrain.py

示例2: convert_to_grayscale

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import set_at [as 别名]
def convert_to_grayscale(surf):
    """Convert a Surface to grayscale, pixel by pixel.  Quite slow."""
    # pylint: disable=E1121
    gray = Surface(surf.get_size(), 0, 8)
    # pylint: enable=E1121
    w, h = surf.get_size()
    for x in xrange(w):
        for y in xrange(h):
            red, green, blue, alpha = surf.get_at((x, y))
            average = (red + green + blue) // 3
            gs_color = (average, average, average, alpha)
            gray.set_at((x, y), gs_color)
    return gray
开发者ID:aruse,项目名称:Bludgeon,代码行数:15,代码来源:image.py

示例3: test_height

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import set_at [as 别名]
 def test_height(self):
     """
     L{loadTerrainFromSurface} uses the red color component to determine how
     many voxels to stack.
     """
     surface = Surface((1, 1))
     surface.set_at((0, 0), (3, 0, 0))
     terrain = loadTerrainFromSurface(surface)
     self.assertEquals(
         terrain.dict(),
         {(0, 0, 0): MOUNTAIN,
          (0, 1, 0): MOUNTAIN,
          (0, 2, 0): GRASS})
开发者ID:eriknelson,项目名称:gam3,代码行数:15,代码来源:test_terrain.py

示例4: test_varyingZ

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import set_at [as 别名]
 def test_varyingZ(self):
     """
     L{loadTerrainFromSurface} varies the z coordinate of the loaded terrain
     with the y coordinate of the image data.
     """
     surface = Surface((1, 2))
     surface.set_at((0, 0), (3, 0, 0))
     surface.set_at((0, 1), (2, 0, 0))
     terrain = loadTerrainFromSurface(surface)
     self.assertEquals(
         terrain.dict(),
         {(0, 0, 0): MOUNTAIN, (0, 0, 1): MOUNTAIN,
          (0, 1, 0): MOUNTAIN, (0, 1, 1): GRASS,
          (0, 2, 0): GRASS})
开发者ID:eriknelson,项目名称:gam3,代码行数:16,代码来源:test_terrain.py

示例5: test_loadImageTerrain

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import set_at [as 别名]
    def test_loadImageTerrain(self):
        """
        If the terrain option is specified as a file containing image-based
        terrain data, terrain data is loaded from it.
        """
        temp = FilePath(self.mktemp())
        temp.makedirs()
        terrain = temp.child("terrain.png")
        surface = Surface((2, 1))
        surface.set_at((0, 0), (1, 0, 0))
        surface.set_at((1, 0), (3, 0, 0))
        save(surface, terrain.path)

        service = gam3plugin.makeService({
                "port": 123, "log-directory": None, "terrain": terrain.path})
        gam3 = service.getServiceNamed(GAM3_SERVICE_NAME)
        self.assertEquals(
            gam3.world.terrain.dict(),
            {(1, 0, 0): MOUNTAIN, (0, 0, 0): GRASS,
             (1, 1, 0): MOUNTAIN,
             (1, 2, 0): GRASS})
开发者ID:eriknelson,项目名称:gam3,代码行数:23,代码来源:test_twistd_plugin.py

示例6: Layer

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import set_at [as 别名]
class Layer(Rect,object):
    
    def __init__(self,rect,alpha,delta):
        Rect.__init__(self,rect)
        self.surface = Surface(self.size,SRCALPHA)
        self.alpha   = alpha
        self.delta   = delta
    
    def render(self):
        scr.blit(self.surface,self)
        array = surfarray.pixels_alpha(self.surface)
        array[(self.alpha<array)&(array<self.alpha+self.delta)] = self.alpha
        array[array>self.alpha] = array[array>self.alpha]-self.delta
    
    def blit(self,*arg):
        self.surface.blit(*arg)
        
    def fill(self,*arg):
        self.surface.fill(*arg)
        
    def set_at(self,*arg):
        self.surface.set_at(*arg)
开发者ID:conallCurran,项目名称:MassEffectShooter,代码行数:24,代码来源:layer.py

示例7: scaleImageInFile

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import set_at [as 别名]
def scaleImageInFile(path):
	print "loading", path
	try:
		sourceImage = pygame.image.load(path)
	except:
		print 'An error occurred loading image \"%s\"' % path
		sys.exit(2)
	# copy the source image into the target image, though we're about to overwrite it we want its format
	targetImage = Surface((sourceImage.get_width() * 2, sourceImage.get_height() * 2), sourceImage.get_flags(), sourceImage)
	for x in range(0, sourceImage.get_width()):
		for y in range(0, sourceImage.get_height()):
			# determine neighboring pixels
			# TODO check diagonal edges
			#a = sourceImage.get_at((x - 1, y - 1)) if y > 0 and x > 0 else sourceImage.get_at((x, y))
			b = sourceImage.get_at((x, y - 1)) if y > 0 else sourceImage.get_at((x, y))
			#c = sourceImage.get_at((x + 1, y - 1)) if y > 0 and (x + 1) < sourceImage.get_width() else sourceImage.get_at((x, y))
			d = sourceImage.get_at((x - 1, y)) if x > 0 else sourceImage.get_at((x, y))
			e = sourceImage.get_at((x, y))
			f = sourceImage.get_at((x + 1, y)) if (x + 1) < sourceImage.get_width() else sourceImage.get_at((x, y))
			#g = sourceImage.get_at((x - 1, y + 1)) if (y + 1) < sourceImage.get_height() and x > 0 else sourceImage.get_at((x, y))
			h = sourceImage.get_at((x, y + 1)) if (y + 1) < sourceImage.get_height() else sourceImage.get_at((x, y))
			#i = sourceImage.get_at((x + 1, y + 1)) if (y + 1) < sourceImage.get_height() and (x + 1) < sourceImage.get_width() else sourceImage.get_at((x, y))
			
			if b != h and d != f:
				e0 = d if d == b else e
				e1 = f if b == f else e
				e2 = d if d == h else e
				e3 = f if h == f else e
			else:
				e0 = e
				e1 = e
				e2 = e
				e3 = e
			
			# figure out target coordinates for e0, e1, e2, e3
			targetImage.set_at((x * 2, y * 2), e0)
			targetImage.set_at((x * 2 + 1, y * 2), e1)
			targetImage.set_at((x * 2, y * 2 + 1), e2)
			targetImage.set_at((x * 2 + 1, y * 2 + 1), e3)
			
	# write image back to file
	filename, extension = os.path.splitext(path)
	newPath = filename + '.scaled2x' + extension
	pygame.image.save(targetImage, newPath)
			
	# print happy message
	print "Scaled up version is at", newPath
开发者ID:barbeque,项目名称:Learning,代码行数:49,代码来源:scale2x.py

示例8: randint

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import set_at [as 别名]
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):
    for y in range(0, background.get_height(), 8):
        present = personat(x/8, y/8)
        if shownoise and not present:
开发者ID:tps12,项目名称:Generation-Generation,代码行数:33,代码来源:main.py

示例9: render

# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import set_at [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


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