當前位置: 首頁>>代碼示例>>Python>>正文


Python pygame.PixelArray方法代碼示例

本文整理匯總了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) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:21,代碼來源:surflock_test.py

示例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) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:24,代碼來源:pixelarray_test.py

示例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) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:26,代碼來源:pixelarray_test.py

示例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) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:20,代碼來源:pixelarray_test.py

示例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))) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:19,代碼來源:pixelarray_test.py

示例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]) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:19,代碼來源:pixelarray_test.py

示例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) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:19,代碼來源:pixelarray_test.py

示例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" 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:25,代碼來源:pixelarray_test.py

示例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) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:21,代碼來源:pixelarray_test.py

示例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]) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:21,代碼來源:pixelarray_test.py

示例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) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:24,代碼來源:pixelarray_test.py

示例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 ()) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:18,代碼來源:pixelarray_test.py

示例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) 
開發者ID:stemkoski,項目名稱:three.py,代碼行數:29,代碼來源:TestUpdatingTexture.py

示例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 
開發者ID:digiholic,項目名稱:universalSmashSystem,代碼行數:7,代碼來源:spriteManager.py


注:本文中的pygame.PixelArray方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。