本文整理汇总了Python中pygame.PixelArray方法的典型用法代码示例。如果您正苦于以下问题:Python pygame.PixelArray方法的具体用法?Python pygame.PixelArray怎么用?Python pygame.PixelArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame
的用法示例。
在下文中一共展示了pygame.PixelArray方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pxarray_ref
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import PixelArray [as 别名]
def test_pxarray_ref(self):
sf = pygame.Surface((5, 5))
ar = pygame.PixelArray(sf)
ar2 = pygame.PixelArray(sf)
self.assertEqual(sf.get_locked(), True)
self.assertEqual(sf.get_locks(), (ar, ar2))
del ar
self.assertEqual(sf.get_locked(), True)
self.assertEqual(sf.get_locks(), (ar2,))
ar = ar2[:]
self.assertEqual(sf.get_locked(), True)
self.assertEqual(sf.get_locks(), (ar2,))
del ar
self.assertEqual(sf.get_locked(), True)
self.assertEqual(len(sf.get_locks()), 1)
示例2: test_close_raises
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import PixelArray [as 别名]
def test_close_raises(self):
""" when you try to do an operation after it is closed.
"""
s = pygame.Surface((10,10))
a = pygame.PixelArray(s)
a.close()
def do_operation():
a[:]
self.assertRaises (ValueError, do_operation)
def do_operation2():
a[:] = 1
self.assertRaises (ValueError, do_operation2)
def do_operation3():
a.make_surface()
self.assertRaises (ValueError, do_operation3)
def do_operation4():
for x in a:
pass
self.assertRaises (ValueError, do_operation4)
示例3: test_as_class
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import PixelArray [as 别名]
def test_as_class (self):
# Check general new-style class freatures.
sf = pygame.Surface ((2, 3), 0, 32)
ar = pygame.PixelArray (sf)
self.assertRaises (AttributeError, getattr, ar, 'nonnative')
ar.nonnative = 'value'
self.assertEqual (ar.nonnative, 'value')
r = weakref.ref (ar)
self.assertTrue (r() is ar)
del ar
gc.collect ()
self.assertTrue (r() is None)
class C (pygame.PixelArray):
def __str__ (self):
return "string (%i, %i)" % self.shape
ar = C (sf)
self.assertEqual (str (ar), "string (2, 3)")
r = weakref.ref (ar)
self.assertTrue (r() is ar)
del ar
gc.collect ()
self.assertTrue (r() is None)
示例4: test_get_column
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import PixelArray [as 别名]
def test_get_column (self):
for bpp in (8, 16, 24, 32):
sf = pygame.Surface ((6, 8), 0, bpp)
sf.fill ((0, 0, 255))
val = sf.map_rgb ((0, 0, 255))
ar = pygame.PixelArray (sf)
ar2 = ar.__getitem__ (1)
self.assertEqual (len(ar2), 8)
self.assertEqual (ar2.__getitem__ (0), val)
self.assertEqual (ar2.__getitem__ (1), val)
self.assertEqual (ar2.__getitem__ (2), val)
ar2 = ar.__getitem__ (-1)
self.assertEqual (len(ar2), 8)
self.assertEqual (ar2.__getitem__ (0), val)
self.assertEqual (ar2.__getitem__ (1), val)
self.assertEqual (ar2.__getitem__ (2), val)
示例5: test_set_pixel
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import PixelArray [as 别名]
def test_set_pixel (self):
for bpp in (8, 16, 24, 32):
sf = pygame.Surface ((10, 20), 0, bpp)
sf.fill ((0, 0, 0))
ar = pygame.PixelArray (sf)
ar.__getitem__ (0).__setitem__ (0, (0, 255, 0))
self.assertEqual (ar[0][0], sf.map_rgb ((0, 255, 0)))
ar.__getitem__ (1).__setitem__ (1, (128, 128, 128))
self.assertEqual (ar[1][1], sf.map_rgb ((128, 128, 128)))
ar.__getitem__(-1).__setitem__ (-1, (128, 128, 128))
self.assertEqual (ar[9][19], sf.map_rgb ((128, 128, 128)))
ar.__getitem__ (-2).__setitem__ (-2, (128, 128, 128))
self.assertEqual (ar[8][-2], sf.map_rgb ((128, 128, 128)))
示例6: test_contains
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import PixelArray [as 别名]
def test_contains (self):
for bpp in (8, 16, 24, 32):
sf = pygame.Surface ((10, 20), 0, bpp)
sf.fill ((0, 0, 0))
sf.set_at ((8, 8), (255, 255, 255))
ar = pygame.PixelArray (sf)
self.assertTrue ((0, 0, 0) in ar)
self.assertTrue ((255, 255, 255) in ar)
self.assertFalse ((255, 255, 0) in ar)
self.assertFalse (0x0000ff in ar)
# Test sliced array
self.assertTrue ((0, 0, 0) in ar[8])
self.assertTrue ((255, 255, 255) in ar[8])
self.assertFalse ((255, 255, 0) in ar[8])
self.assertFalse (0x0000ff in ar[8])
示例7: test_make_surface__subclassed_surface
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import PixelArray [as 别名]
def test_make_surface__subclassed_surface(self):
"""Ensure make_surface can handle subclassed surfaces."""
expected_size = (3, 5)
expected_flags = 0
expected_depth = 32
original_surface = SurfaceSubclass(expected_size, expected_flags,
expected_depth)
pixelarray = pygame.PixelArray(original_surface)
surface = pixelarray.make_surface()
self.assertIsNot(surface, original_surface)
self.assertIsInstance(surface, pygame.Surface)
self.assertNotIsInstance(surface, SurfaceSubclass)
self.assertEqual(surface.get_size(), expected_size)
self.assertEqual(surface.get_flags(), expected_flags)
self.assertEqual(surface.get_bitsize(), expected_depth)
示例8: test_replace
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import PixelArray [as 别名]
def test_replace (self):
#print "replace start"
for bpp in (8, 16, 24, 32):
sf = pygame.Surface ((10, 10), 0, bpp)
sf.fill ((255, 0, 0))
rval = sf.map_rgb ((0, 0, 255))
oval = sf.map_rgb ((255, 0, 0))
ar = pygame.PixelArray (sf)
ar[::2].replace ((255, 0, 0), (0, 0, 255))
self.assertEqual (ar[0][0], rval)
self.assertEqual (ar[1][0], oval)
self.assertEqual (ar[2][3], rval)
self.assertEqual (ar[3][6], oval)
self.assertEqual (ar[8][9], rval)
self.assertEqual (ar[9][9], oval)
ar[::2].replace ((0, 0, 255), (255, 0, 0), weights=(10, 20, 50))
self.assertEqual (ar[0][0], oval)
self.assertEqual (ar[2][3], oval)
self.assertEqual (ar[3][6], oval)
self.assertEqual (ar[8][9], oval)
self.assertEqual (ar[9][9], oval)
#print "replace end"
示例9: test_2dslice_assignment
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import PixelArray [as 别名]
def test_2dslice_assignment (self):
w = 2 * 5 * 8
h = 3 * 5 * 9
sf = pygame.Surface ((w, h), 0, 32)
ar = pygame.PixelArray (sf)
size = (w, h)
strides = (1, w)
offset = 0
self._test_assignment (sf, ar, size, strides, offset)
xslice = slice (None, None, 2)
yslice = slice (None, None, 3)
ar, size, strides, offset = self._array_slice (
ar, size, (xslice, yslice), strides, offset)
self._test_assignment (sf, ar, size, strides, offset)
xslice = slice (5, None, 5)
yslice = slice (5, None, 5)
ar, size, strides, offset = self._array_slice (
ar, size, (xslice, yslice), strides, offset)
self._test_assignment (sf, ar, size, strides, offset)
示例10: test_shape
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import PixelArray [as 别名]
def test_shape(self):
for shape in [[4, 16], [5, 13]]:
w, h = shape
sf = pygame.Surface (shape, 0, 32)
ar = pygame.PixelArray (sf)
ai = arrinter.ArrayInterface (ar)
ai_shape = [ai.shape[i] for i in range(ai.nd)]
self.assertEqual (ai_shape, shape)
ar2 = ar[::2,:]
ai2 = arrinter.ArrayInterface (ar2)
w2 = len(([0] * w)[::2])
ai_shape = [ai2.shape[i] for i in range(ai2.nd)]
self.assertEqual (ai_shape, [w2, h])
ar2 = ar[:,::2]
ai2 = arrinter.ArrayInterface (ar2)
h2 = len(([0] * h)[::2])
ai_shape = [ai2.shape[i] for i in range(ai2.nd)]
self.assertEqual (ai_shape, [w, h2])
示例11: test_flags
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import PixelArray [as 别名]
def test_flags (self):
aim = arrinter
common_flags = (aim.PAI_NOTSWAPPED | aim.PAI_WRITEABLE |
aim.PAI_ALIGNED)
s = pygame.Surface ((10, 2), 0, 32)
ar = pygame.PixelArray (s)
ai = aim.ArrayInterface (ar)
self.assertEqual (ai.flags, common_flags | aim.PAI_FORTRAN)
ar2 = ar[::2,:]
ai = aim.ArrayInterface (ar2)
self.assertEqual (ai.flags, common_flags)
s = pygame.Surface ((8, 2), 0, 24)
ar = pygame.PixelArray (s)
ai = aim.ArrayInterface (ar)
self.assertEqual (ai.flags, common_flags | aim.PAI_FORTRAN)
s = pygame.Surface ((7, 2), 0, 24)
ar = pygame.PixelArray (s)
ai = aim.ArrayInterface (ar)
self.assertEqual (ai.flags, common_flags)
示例12: test_pixel_array
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import PixelArray [as 别名]
def test_pixel_array (self):
for bpp in (8, 16, 24, 32):
sf = pygame.Surface ((10, 20), 0, bpp)
sf.fill ((0, 0, 0))
ar = pygame.PixelArray (sf)
self.assertEqual (ar._pixels_address, sf._pixels_address)
if sf.mustlock ():
self.assertTrue (sf.get_locked ())
self.assertEqual (len (ar), 10)
del ar
if sf.mustlock ():
self.assertFalse (sf.get_locked ())
示例13: initialize
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import PixelArray [as 别名]
def initialize(self):
self.setWindowTitle('Updating Textures')
self.setWindowSize(800,800)
self.renderer = Renderer()
self.renderer.setViewportSize(800,800)
self.renderer.setClearColor(0.25, 0.25, 0.25)
self.scene = Scene()
self.camera = PerspectiveCamera()
self.camera.transform.setPosition(0, 0, 2)
self.camera.transform.lookAt(0, 0, 0)
self.cameraControls = FirstPersonController(self.input, self.camera)
self.canvas = pygame.Surface( (128,128), pygame.SRCALPHA )
self.canvas.fill( [255,255,255] )
self.pixels = pygame.PixelArray(self.canvas)
self.canvasID = OpenGLUtils.initializeSurface(self.canvas)
geometry = QuadGeometry(width=1, height=1, widthResolution=1, heightResolution=1)
material = SurfaceBasicMaterial(texture=self.canvasID)
# disable filtering to see individual pixels more clearly
material.linearFiltering = False
mesh = Mesh(geometry, material)
self.scene.add(mesh)
示例14: recolor
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import PixelArray [as 别名]
def recolor(self,_image,_fromColor,_toColor):
arr = pygame.PixelArray(_image)
arr.replace(_fromColor,_toColor)
del arr
self.changed = True