Python pygame 模块,Color() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用pygame.Color()

项目:sc8pr    作者:dmaccarthy    | 项目源码 | 文件源码
def __init__(self, srf, bg=None, decompress=zlib.decompress):
        if hasattr(srf, "image"): srf = srf.image
        t = type(srf)
        if t is str:
            srf = pygame.image.load(srf)
            if bg: srf = style(srf, bg)
            elif not hasAlpha(srf): srf = srf.convert_alpha()
        elif t is bytes:
            mode, w, h = struct.unpack("!3I", bg)
            if mode & 2: srf = decompress(srf)
            mode = "RGBA" if mode & 1 else "RGB"
            srf = pygame.image.fromstring(srf, (w,h), mode)
        elif t in (list, tuple):
            srf = pygame.Surface(srf, pygame.SRCALPHA)
            if bg: srf.fill(bg if type(bg) is pygame.Color else rgba(bg))
        self.original = srf
        self.dumpCache()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_slice(self):
        #"""|tags: python3_ignore|"""

        # slicing a color gives you back a tuple.
        # do all sorts of slice combinations.
        c = pygame.Color(1,2,3,4)

        self.assertEquals((1,2,3,4), c[:])
        self.assertEquals((1,2,3), c[:-1])

        self.assertEquals((), c[:-5])

        self.assertEquals((1,2,3,4), c[:4])
        self.assertEquals((1,2,3,4), c[:5])
        self.assertEquals((1,2), c[:2])
        self.assertEquals((1,), c[:1])
        self.assertEquals((), c[:0])


        self.assertEquals((2,), c[1:-2])
        self.assertEquals((3, 4), c[-2:])
        self.assertEquals((4,), c[-1:])


        # NOTE: assigning to a slice is currently unsupported.
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_length(self):
        # should be able to unpack to r,g,b,a and r,g,b
        c = pygame.Color(1,2,3,4)
        self.assertEquals(len(c), 4)

        c.set_length(3)
        self.assertEquals(len(c), 3)

        # it keeps the old alpha anyway...
        self.assertEquals(c.a, 4)

        # however you can't get the alpha in this way:
        self.assertRaises (IndexError, lambda x:c[x], 4)



        c.set_length(4)
        self.assertEquals(len(c), 4)
        self.assertEquals(len(c), 4)

        self.assertRaises (ValueError, c.set_length, 5)
        self.assertRaises (ValueError, c.set_length, -1)
        self.assertRaises (ValueError, c.set_length, 0)
        self.assertRaises (ValueError, c.set_length, pow(2,long_(33)))
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_color (self):
        c = pygame.Color (10, 20, 30, 40)
        self.assertEquals (c.r, 10)
        self.assertEquals (c.g, 20)
        self.assertEquals (c.b, 30)
        self.assertEquals (c.a, 40)

        c = pygame.Color ("indianred3")
        self.assertEquals (c.r, 205)
        self.assertEquals (c.g, 85)
        self.assertEquals (c.b, 85)
        self.assertEquals (c.a, 255)

        c = pygame.Color (0xAABBCCDD)
        self.assertEquals (c.r, 0xAA)
        self.assertEquals (c.g, 0xBB)
        self.assertEquals (c.b, 0xCC)
        self.assertEquals (c.a, 0xDD)

        self.assertRaises (ValueError, pygame.Color, 257, 10, 105, 44)
        self.assertRaises (ValueError, pygame.Color, 10, 257, 105, 44)
        self.assertRaises (ValueError, pygame.Color, 10, 105, 257, 44)
        self.assertRaises (ValueError, pygame.Color, 10, 105, 44, 257)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_int (self):
        # This will be a long
        c = pygame.Color (0xCC00CC00)
        self.assertEquals (c.r, 204)
        self.assertEquals (c.g, 0)
        self.assertEquals (c.b, 204)
        self.assertEquals (c.a, 0)
        self.assertEquals (int (c), int (0xCC00CC00))

        # This will be an int
        c = pygame.Color (0x33727592)
        self.assertEquals (c.r, 51)
        self.assertEquals (c.g, 114)
        self.assertEquals (c.b, 117)
        self.assertEquals (c.a, 146)
        self.assertEquals (int (c), int (0x33727592))
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_long (self):
        # This will be a long
        c = pygame.Color (0xCC00CC00)
        self.assertEquals (c.r, 204)
        self.assertEquals (c.g, 0)
        self.assertEquals (c.b, 204)
        self.assertEquals (c.a, 0)
        self.assertEquals (long_ (c), long_ (0xCC00CC00))

        # This will be an int
        c = pygame.Color (0x33727592)
        self.assertEquals (c.r, 51)
        self.assertEquals (c.g, 114)
        self.assertEquals (c.b, 117)
        self.assertEquals (c.a, 146)
        self.assertEquals (long_ (c), long_ (0x33727592))
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_issue_269 (self):
        """PyColor OverflowError on HSVA with hue value of 360

           >>> c = pygame.Color(0)
           >>> c.hsva = (360,0,0,0)
           Traceback (most recent call last):
             File "<stdin>", line 1, in <module>
           OverflowError: this is not allowed to happen ever
           >>> pygame.ver
           '1.9.1release'
           >>>

        """

        c = pygame.Color(0)
        c.hsva = 360, 0, 0, 0
        self.assertEqual(c.hsva, (0, 0, 0, 0))
        c.hsva = 360, 100, 100, 100
        self.assertEqual(c.hsva, (0, 100, 100, 100))
        self.assertEqual(c, (255, 0, 0, 255))

####################### COLORSPACE PROPERTY SANITY TESTS #######################
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def colorspaces_converted_should_not_raise (self, prop):
        fails = 0

        x = 0
        for c in rgba_combos_Color_generator():
            x += 1

            other = pygame.Color(0)

            try:
                setattr(other, prop, getattr(c, prop))
                #eg other.hsla = c.hsla

            except ValueError:
                fails += 1

        self.assert_(x > 0, "x is combination counter, 0 means no tests!")
        self.assert_((fails, x) == (0, x))
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def colorspaces_converted_should_equate_bar_rounding (self, prop):
        for c in rgba_combos_Color_generator():
            other = pygame.Color(0)

            try:
                setattr(other, prop, getattr(c, prop))
                #eg other.hsla = c.hsla

                self.assert_(abs(other.r - c.r) <= 1)
                self.assert_(abs(other.b - c.b) <= 1)
                self.assert_(abs(other.g - c.g) <= 1)
                # CMY and I1I2I3 do not care about the alpha
                if not prop in ("cmy", "i1i2i3"):
                    self.assert_(abs(other.a - c.a) <= 1)

            except ValueError:
                pass        # other tests will notify, this tests equation
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_correct_gamma__verified_against_python_implementation(self):
        "|tags:slow|"
        # gamma_correct defined at top of page

        gammas = [i / 10.0 for i in range(1, 31)]  # [0.1 ... 3.0]
        gammas_len = len(gammas)

        for i, c in enumerate(rgba_combos_Color_generator()):
            gamma = gammas[i % gammas_len]

            corrected = pygame.Color(*[gamma_correct(x, gamma)
                                                 for x in tuple(c)])
            lib_corrected = c.correct_gamma(gamma)

            self.assert_(corrected.r == lib_corrected.r)
            self.assert_(corrected.g == lib_corrected.g)
            self.assert_(corrected.b == lib_corrected.b)
            self.assert_(corrected.a == lib_corrected.a)

        # TODO: test against statically defined verified _correct_ values
        # assert corrected.r == 125 etc.
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_arraystruct(self):
        import pygame.tests.test_utils.arrinter as ai
        import ctypes as ct

        c_byte_p = ct.POINTER(ct.c_byte)
        c = pygame.Color(5, 7, 13, 23)
        flags = (ai.PAI_CONTIGUOUS | ai.PAI_FORTRAN |
                 ai.PAI_ALIGNED | ai.PAI_NOTSWAPPED)
        for i in range(1, 5):
            c.set_length(i)
            inter = ai.ArrayInterface(c)
            self.assertEqual(inter.two, 2)
            self.assertEqual(inter.nd, 1)
            self.assertEqual(inter.typekind, 'u')
            self.assertEqual(inter.itemsize, 1)
            self.assertEqual(inter.flags, flags)
            self.assertEqual(inter.shape[0], i)
            self.assertEqual(inter.strides[0], 1)
            data = ct.cast(inter.data, c_byte_p)
            for j in range(i):
                self.assertEqual(data[j], c[j])
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_set_colorkey(self):

        # __doc__ (as of 2008-06-25) for pygame.surface.Surface.set_colorkey:

          # Surface.set_colorkey(Color, flags=0): return None
          # Surface.set_colorkey(None): return None
          # Set the transparent colorkey

        s = pygame.Surface((16,16), pygame.SRCALPHA, 32)

        colorkeys = ((20,189,20, 255),(128,50,50,255), (23, 21, 255,255))

        for colorkey in colorkeys:
            s.set_colorkey(colorkey)
            for t in range(4): s.set_colorkey(s.get_colorkey())
            self.assertEquals(s.get_colorkey(), colorkey)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_get_at(self):
        surf = pygame.Surface((2, 2), 0, 24)
        c00 = pygame.Color(1, 2, 3)
        c01 = pygame.Color(5, 10, 15)
        c10 = pygame.Color(100, 50, 0)
        c11 = pygame.Color(4, 5, 6)
        surf.set_at((0, 0), c00)
        surf.set_at((0, 1), c01)
        surf.set_at((1, 0), c10)
        surf.set_at((1, 1), c11)
        c = surf.get_at((0, 0))
        self.failUnless(isinstance(c, pygame.Color))
        self.failUnlessEqual(c, c00)
        self.failUnlessEqual(surf.get_at((0, 1)), c01)
        self.failUnlessEqual(surf.get_at((1, 0)), c10)
        self.failUnlessEqual(surf.get_at((1, 1)), c11)
        for p in [(-1, 0), (0, -1), (2, 0), (0, 2)]:
            self.failUnlessRaises(IndexError, surf.get_at, p)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_get_palette(self):
        pygame.init()
        try:
            palette = [Color(i, i, i) for i in range(256)]
            pygame.display.set_mode((100, 50))
            surf = pygame.Surface((2, 2), 0, 8)
            surf.set_palette(palette)
            palette2 = surf.get_palette()
            r,g,b = palette2[0]

            self.failUnlessEqual(len(palette2), len(palette))
            for c2, c in zip(palette2, palette):
                self.failUnlessEqual(c2, c)
            for c in palette2:
                self.failUnless(isinstance(c, pygame.Color))
        finally:
            pygame.quit()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_set_palette_at(self):
        pygame.init()
        try:
            pygame.display.set_mode((100, 50))
            surf = pygame.Surface((2, 2), 0, 8)
            original = surf.get_palette_at(10)
            replacement = Color(1, 1, 1, 255)
            if replacement == original:
                replacement = Color(2, 2, 2, 255)
            surf.set_palette_at(10, replacement)
            self.failUnlessEqual(surf.get_palette_at(10), replacement)
            next = tuple(original)
            surf.set_palette_at(10, next)
            self.failUnlessEqual(surf.get_palette_at(10), next)
            next = tuple(original)[0:3]
            surf.set_palette_at(10, next)
            self.failUnlessEqual(surf.get_palette_at(10), next)
            self.failUnlessRaises(IndexError,
                                  surf.set_palette_at,
                                  256, replacement)
            self.failUnlessRaises(IndexError,
                                  surf.set_palette_at,
                                  -1, replacement)
        finally:
            pygame.quit()
项目:CC3501-2017-1    作者:ppizarror    | 项目源码 | 文件源码
def __init__(self, points, center, color=None, width=0,
                 pygame_surface=None):
        """
        Create centered figure from point list with center (x,y).

        :param points: Vertices tuple list (ex. [(10,10), (10,5)...])
        :type points: list
        :param center: Center list (ex [10, 10])
        :type center: list
        :param color: Pygame color
        :type color: pygame.Color
        :param width: Border width (px)
        :param pygame_surface: Pygame surface object
        :type pygame_surface: pygame.display
        """
        self._points = points
        self._center = center
        self._color = color
        self._width = width
        self._surface = pygame_surface
项目:RPG    作者:LugosFingite    | 项目源码 | 文件源码
def chargerpage(fichier: str):
    global histoire
    data = json.load(open("Aventures/" + histoire + "/" + fichier + ".json"))

    d = (data["desc"], pygame.Color(data["color"]))

    act = []
    for a in data["actions"]:
        act.append(Action((a["desc"], pygame.Color(a["color"])),
                          (a["cible"], a.get("histoire", histoire))))

    try:
        i = pygame.image.load_extended("Aventures/" + histoire + "/" + data["image"])
    except:
        i = None

    try:
        s = st.loadsound(data["son"], data["loop_music"])
    except:
        s = None

    return Page(d, act, i, s)
项目:spygame    作者:sven1977    | 项目源码 | 文件源码
def render_stages(display, refresh_after_render=False):
        """
        Loops through all Stages and renders all of them.

        :param Display display: Display object on which to render
        :param bool refresh_after_render: do we refresh the pygame.display after all Stages have been called with `render`?
        """
        # black out display (really necessary? I think so)
        display.surface.fill(pygame.Color("#000000"))
        # call render on all Stages
        for i, stage in enumerate(Stage.stages):
            Stage.active_stage = i
            if stage:
                stage.render(display)
        # for debugging purposes
        if refresh_after_render:
            pygame.display.flip()
项目:spygame    作者:sven1977    | 项目源码 | 文件源码
def screen_func(stage: Stage):
        """
        Defines this screen's Stage setup.
        Stage functions are used to setup a Stage (before playing it).

        :param Stage stage: the Stage to be setup
        """
        # get the Screen object (instance) from the options
        screen = stage.options["screen_obj"]

        # insert labels to screen
        for label_def in screen.labels:
            # generate new Font object
            font = pygame.font.Font(None, label_def["size"])
            surf = font.render(label_def["text"], 1, pygame.Color(label_def["color"]))
            sprite = Sprite(label_def["x"], label_def["y"], surf)
            stage.add_sprite(sprite, "labels")

        # insert objects to screen
        for game_obj in screen.game_objects:
            stage.add_sprite(game_obj, "sprites")
项目:Pygame_Functions    作者:StevePaget    | 项目源码 | 文件源码
def __init__(self, text, xpos, ypos, width, case, maxLength, fontSize):
        pygame.sprite.Sprite.__init__(self)
        self.text = ""
        self.width = width
        self.initialText = text
        self.case = case
        self.maxLength = maxLength
        self.boxSize = int(fontSize * 1.7)
        self.image = pygame.Surface((width, self.boxSize))
        self.image.fill((255, 255, 255))
        pygame.draw.rect(self.image, (0, 0, 0), [0, 0, width - 1, self.boxSize - 1], 2)
        self.rect = self.image.get_rect()
        self.fontFace = pygame.font.match_font("Arial")
        self.fontColour = pygame.Color("black")
        self.initialColour = (180, 180, 180)
        self.font = pygame.font.Font(self.fontFace, fontSize)
        self.rect.topleft = [xpos, ypos]
        newSurface = self.font.render(self.initialText, True, self.initialColour)
        self.image.blit(newSurface, [10, 5])
项目:Pygame_Functions    作者:StevePaget    | 项目源码 | 文件源码
def __init__(self, text, fontSize, font, fontColour, xpos, ypos, background):
        pygame.sprite.Sprite.__init__(self)
        self.fontColour = pygame.Color(fontColour)
        self.fontFace = pygame.font.match_font(font)
        self.fontSize = fontSize
        self.background = background
        self.font = pygame.font.Font(self.fontFace, self.fontSize)
        newSurface = self.font.render(text, True, self.fontColour)
        self.rect = newSurface.get_rect()
        if self.background != "clear":
            self.image = pygame.Surface((self.rect.width, self.rect.height))
            self.image.fill(pygame.Color(background))
            self.image.blit(newSurface, [0, 0])
        else:
            self.image = newSurface
        self.rect.topleft = [xpos, ypos]
项目:Pygame_Functions    作者:StevePaget    | 项目源码 | 文件源码
def __init__(self, text, xpos, ypos, width, case, maxLength, fontSize):
        pygame.sprite.Sprite.__init__(self)
        self.text = ""
        self.width = width
        self.initialText = text
        self.case = case
        self.maxLength = maxLength
        self.boxSize = int(fontSize * 1.7)
        self.image = pygame.Surface((width, self.boxSize))
        self.image.fill((255, 255, 255))
        pygame.draw.rect(self.image, (0, 0, 0), [0, 0, width - 1, self.boxSize - 1], 2)
        self.rect = self.image.get_rect()
        self.fontFace = pygame.font.match_font("Arial")
        self.fontColour = pygame.Color("black")
        self.initialColour = (180, 180, 180)
        self.font = pygame.font.Font(self.fontFace, fontSize)
        self.rect.topleft = [xpos, ypos]
        newSurface = self.font.render(self.initialText, True, self.initialColour)
        self.image.blit(newSurface, [10, 5])
项目:Pygame_Functions    作者:StevePaget    | 项目源码 | 文件源码
def __init__(self, text, fontSize, font, fontColour, xpos, ypos, background):
        pygame.sprite.Sprite.__init__(self)
        self.fontColour = pygame.Color(fontColour)
        self.fontFace = pygame.font.match_font(font)
        self.fontSize = fontSize
        self.background = background
        self.font = pygame.font.Font(self.fontFace, self.fontSize)
        newSurface = self.font.render(text, True, self.fontColour)
        self.rect = newSurface.get_rect()
        if self.background != "clear":
            self.image = pygame.Surface((self.rect.width, self.rect.height))
            self.image.fill(pygame.Color(background))
            self.image.blit(newSurface, [0, 0])
        else:
            self.image = newSurface
        self.rect.topleft = [xpos, ypos]
项目:MVP2    作者:critterandguitari    | 项目源码 | 文件源码
def draw(screen, mvp):

    global count
    if True: #mvp.note_on:

        #count += 1  
        #if count > mvp.knob3:
        #    count = 0
        #    screen.fill((0,0,0))

        #if count > mvp.knob3 //
        x=random.randrange(0,1300)
        y=random.randrange(0,800)
        pierad=random.randrange(10,100) #radius
        arcstart=random.randrange(0,360)
        arcend=random.randrange(0, 360-arcstart)
        size = int(mvp.knob2*1000)

        color = pygame.Color(random.randrange(0,255), random.randrange(0,255), random.randrange(0,255), 10)
        color.hsva = (int(mvp.knob4 * 359), 100, 100, 10)


        fillrange=int(mvp.knob1*100)
        for i in range(fillrange):
            pygame.gfxdraw.pie(screen, x, y, size, arcstart + i*2, arcend - i*2, color)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_slice(self):
        #"""|tags: python3_ignore|"""

        # slicing a color gives you back a tuple.
        # do all sorts of slice combinations.
        c = pygame.Color(1,2,3,4)

        self.assertEquals((1,2,3,4), c[:])
        self.assertEquals((1,2,3), c[:-1])

        self.assertEquals((), c[:-5])

        self.assertEquals((1,2,3,4), c[:4])
        self.assertEquals((1,2,3,4), c[:5])
        self.assertEquals((1,2), c[:2])
        self.assertEquals((1,), c[:1])
        self.assertEquals((), c[:0])


        self.assertEquals((2,), c[1:-2])
        self.assertEquals((3, 4), c[-2:])
        self.assertEquals((4,), c[-1:])


        # NOTE: assigning to a slice is currently unsupported.
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_length(self):
        # should be able to unpack to r,g,b,a and r,g,b
        c = pygame.Color(1,2,3,4)
        self.assertEquals(len(c), 4)

        c.set_length(3)
        self.assertEquals(len(c), 3)

        # it keeps the old alpha anyway...
        self.assertEquals(c.a, 4)

        # however you can't get the alpha in this way:
        self.assertRaises (IndexError, lambda x:c[x], 4)



        c.set_length(4)
        self.assertEquals(len(c), 4)
        self.assertEquals(len(c), 4)

        self.assertRaises (ValueError, c.set_length, 5)
        self.assertRaises (ValueError, c.set_length, -1)
        self.assertRaises (ValueError, c.set_length, 0)
        self.assertRaises (ValueError, c.set_length, pow(2,long_(33)))
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_color (self):
        c = pygame.Color (10, 20, 30, 40)
        self.assertEquals (c.r, 10)
        self.assertEquals (c.g, 20)
        self.assertEquals (c.b, 30)
        self.assertEquals (c.a, 40)

        c = pygame.Color ("indianred3")
        self.assertEquals (c.r, 205)
        self.assertEquals (c.g, 85)
        self.assertEquals (c.b, 85)
        self.assertEquals (c.a, 255)

        c = pygame.Color (0xAABBCCDD)
        self.assertEquals (c.r, 0xAA)
        self.assertEquals (c.g, 0xBB)
        self.assertEquals (c.b, 0xCC)
        self.assertEquals (c.a, 0xDD)

        self.assertRaises (ValueError, pygame.Color, 257, 10, 105, 44)
        self.assertRaises (ValueError, pygame.Color, 10, 257, 105, 44)
        self.assertRaises (ValueError, pygame.Color, 10, 105, 257, 44)
        self.assertRaises (ValueError, pygame.Color, 10, 105, 44, 257)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_sub (self):
        c1 = pygame.Color (0xFFFFFFFF)
        self.assertEquals (c1.r, 255)
        self.assertEquals (c1.g, 255)
        self.assertEquals (c1.b, 255)
        self.assertEquals (c1.a, 255)

        c2 = pygame.Color (20, 33, 82, 193)
        self.assertEquals (c2.r, 20)
        self.assertEquals (c2.g, 33)
        self.assertEquals (c2.b, 82)
        self.assertEquals (c2.a, 193)

        c3 = c1 - c2
        self.assertEquals (c3.r, 235)
        self.assertEquals (c3.g, 222)
        self.assertEquals (c3.b, 173)
        self.assertEquals (c3.a, 62)

        c3 = c3 - c2
        self.assertEquals (c3.r, 215)
        self.assertEquals (c3.g, 189)
        self.assertEquals (c3.b, 91)
        self.assertEquals (c3.a, 0)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_mul (self):
        c1 = pygame.Color (0x01010101)
        self.assertEquals (c1.r, 1)
        self.assertEquals (c1.g, 1)
        self.assertEquals (c1.b, 1)
        self.assertEquals (c1.a, 1)

        c2 = pygame.Color (2, 5, 3, 22)
        self.assertEquals (c2.r, 2)
        self.assertEquals (c2.g, 5)
        self.assertEquals (c2.b, 3)
        self.assertEquals (c2.a, 22)

        c3 = c1 * c2
        self.assertEquals (c3.r, 2)
        self.assertEquals (c3.g, 5)
        self.assertEquals (c3.b, 3)
        self.assertEquals (c3.a, 22)

        c3 = c3 * c2
        self.assertEquals (c3.r, 4)
        self.assertEquals (c3.g, 25)
        self.assertEquals (c3.b, 9)
        self.assertEquals (c3.a, 255)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_div (self):
        c1 = pygame.Color (0x80808080)
        self.assertEquals (c1.r, 128)
        self.assertEquals (c1.g, 128)
        self.assertEquals (c1.b, 128)
        self.assertEquals (c1.a, 128)

        c2 = pygame.Color (2, 4, 8, 16)
        self.assertEquals (c2.r, 2)
        self.assertEquals (c2.g, 4)
        self.assertEquals (c2.b, 8)
        self.assertEquals (c2.a, 16)

        c3 = c1 // c2
        self.assertEquals (c3.r, 64)
        self.assertEquals (c3.g, 32)
        self.assertEquals (c3.b, 16)
        self.assertEquals (c3.a, 8)

        c3 = c3 // c2
        self.assertEquals (c3.r, 32)
        self.assertEquals (c3.g, 8)
        self.assertEquals (c3.b, 2)
        self.assertEquals (c3.a, 0)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_mod (self):
        c1 = pygame.Color (0xFFFFFFFF)
        self.assertEquals (c1.r, 255)
        self.assertEquals (c1.g, 255)
        self.assertEquals (c1.b, 255)
        self.assertEquals (c1.a, 255)

        c2 = pygame.Color (2, 4, 8, 16)
        self.assertEquals (c2.r, 2)
        self.assertEquals (c2.g, 4)
        self.assertEquals (c2.b, 8)
        self.assertEquals (c2.a, 16)

        c3 = c1 % c2
        self.assertEquals (c3.r, 1)
        self.assertEquals (c3.g, 3)
        self.assertEquals (c3.b, 7)
        self.assertEquals (c3.a, 15)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_int (self):
        # This will be a long
        c = pygame.Color (0xCC00CC00)
        self.assertEquals (c.r, 204)
        self.assertEquals (c.g, 0)
        self.assertEquals (c.b, 204)
        self.assertEquals (c.a, 0)
        self.assertEquals (int (c), int (0xCC00CC00))

        # This will be an int
        c = pygame.Color (0x33727592)
        self.assertEquals (c.r, 51)
        self.assertEquals (c.g, 114)
        self.assertEquals (c.b, 117)
        self.assertEquals (c.a, 146)
        self.assertEquals (int (c), int (0x33727592))
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_long (self):
        # This will be a long
        c = pygame.Color (0xCC00CC00)
        self.assertEquals (c.r, 204)
        self.assertEquals (c.g, 0)
        self.assertEquals (c.b, 204)
        self.assertEquals (c.a, 0)
        self.assertEquals (long_ (c), long_ (0xCC00CC00))

        # This will be an int
        c = pygame.Color (0x33727592)
        self.assertEquals (c.r, 51)
        self.assertEquals (c.g, 114)
        self.assertEquals (c.b, 117)
        self.assertEquals (c.a, 146)
        self.assertEquals (long_ (c), long_ (0x33727592))
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_set_item (self):
        c = pygame.Color (204, 38, 194, 55)
        self.assertEquals (c[0], 204)
        self.assertEquals (c[1], 38)
        self.assertEquals (c[2], 194)
        self.assertEquals (c[3], 55)

        c[0] = 33
        self.assertEquals (c[0], 33)
        c[1] = 48
        self.assertEquals (c[1], 48)
        c[2] = 173
        self.assertEquals (c[2], 173)
        c[3] = 213
        self.assertEquals (c[3], 213)

        # Now try some 'invalid' ones
        self.assertRaises (ValueError, _assign_item, c, 0, 95.485)
        self.assertEquals (c[0], 33)
        self.assertRaises (ValueError, _assign_item, c, 1, -83)
        self.assertEquals (c[1], 48)
        self.assertRaises (ValueError, _assign_item, c, 2, "Hello")
        self.assertEquals (c[2], 173)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def colorspaces_converted_should_not_raise (self, prop):
        fails = 0

        x = 0
        for c in rgba_combos_Color_generator():
            x += 1

            other = pygame.Color(0)

            try:
                setattr(other, prop, getattr(c, prop))
                #eg other.hsla = c.hsla

            except ValueError:
                fails += 1

        self.assert_(x > 0, "x is combination counter, 0 means no tests!")
        self.assert_((fails, x) == (0, x))
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def colorspaces_converted_should_equate_bar_rounding (self, prop):
        for c in rgba_combos_Color_generator():
            other = pygame.Color(0)

            try:
                setattr(other, prop, getattr(c, prop))
                #eg other.hsla = c.hsla

                self.assert_(abs(other.r - c.r) <= 1)
                self.assert_(abs(other.b - c.b) <= 1)
                self.assert_(abs(other.g - c.g) <= 1)
                # CMY and I1I2I3 do not care about the alpha
                if not prop in ("cmy", "i1i2i3"):
                    self.assert_(abs(other.a - c.a) <= 1)

            except ValueError:
                pass        # other tests will notify, this tests equation
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_set_at(self):

        #24bit surfaces 
        s = pygame.Surface( (100, 100), 0, 24)
        s.fill((0,0,0))

        # set it with a tuple.
        s.set_at((0,0), (10,10,10, 255))
        r = s.get_at((0,0))
        self.failUnless(isinstance(r, pygame.Color))
        self.assertEqual(r, (10,10,10, 255))

        # try setting a color with a single integer.
        s.fill((0,0,0,255))
        s.set_at ((10, 1), 0x0000FF)
        r = s.get_at((10,1))
        self.assertEqual(r, (0,0,255, 255))
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_set_colorkey(self):

        # __doc__ (as of 2008-06-25) for pygame.surface.Surface.set_colorkey:

          # Surface.set_colorkey(Color, flags=0): return None
          # Surface.set_colorkey(None): return None
          # Set the transparent colorkey

        s = pygame.Surface((16,16), pygame.SRCALPHA, 32)

        colorkeys = ((20,189,20, 255),(128,50,50,255), (23, 21, 255,255))

        for colorkey in colorkeys:
            s.set_colorkey(colorkey)
            for t in range(4): s.set_colorkey(s.get_colorkey())
            self.assertEquals(s.get_colorkey(), colorkey)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def todo_test_get_at(self):
        surf = pygame.Surface((2, 2), 0, 24)
        c00 = pygame.Color((1, 2, 3))
        c01 = pygame.Color((5, 10, 15))
        c10 = pygame.Color((100, 50, 0))
        c11 = pygame.Color((4, 5, 6))
        surf.set_at((0, 0), c00)
        surf.set_at((0, 1), c01)
        surf.set_at((1, 0), c10)
        surf.set_at((1, 1), c11)
        c = surf.get_at((0, 0))
        self.failUnless(isinstance(c, pygame.Color))
        self.failUnlessEqual(c, c00)
        self.failUnlessEqual(surf.get_at((0, 1)), c01)
        self.failUnlessEqual(surf.get_at((1, 0)), c10)
        self.failUnlessEqual(surf.get_at((1, 1)), c11)
        for p in [(-1, 0), (0, -1), (2, 0), (0, 2)]:
            self.failUnlessRaises(IndexError, surf.get_at, p, "%s" % (p,))
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_set_palette_at(self):
        pygame.init()
        try:
            pygame.display.set_mode((100, 50))
            surf = pygame.Surface((2, 2), 0, 8)
            original = surf.get_palette_at(10)
            replacement = Color(1, 1, 1, 255)
            if replacement == original:
                replacement = Color(2, 2, 2, 255)
            surf.set_palette_at(10, replacement)
            self.failUnlessEqual(surf.get_palette_at(10), replacement)
            next = tuple(original)
            surf.set_palette_at(10, next)
            self.failUnlessEqual(surf.get_palette_at(10), next)
            next = tuple(original)[0:3]
            surf.set_palette_at(10, next)
            self.failUnlessEqual(surf.get_palette_at(10), next)
            self.failUnlessRaises(IndexError,
                                  surf.set_palette_at,
                                  256, replacement)
            self.failUnlessRaises(IndexError,
                                  surf.set_palette_at,
                                  -1, replacement)
        finally:
            pygame.quit()
项目:Boardgame    作者:RensMo    | 项目源码 | 文件源码
def __init__(self, x, y, sx, sy):
        self.x = x
        self.y = y
        self.rect = pygame.Rect((x, y), (sx, sy))
        self.click = False
        self.rcolor = ["Red", "Green", "Blue", "White", "Yellow", "Black"]
        self.color = pygame.Color("White")
        self.ccolor = random.choice(self.rcolor)

        self.vxy = 0
        self.vx = 0
        self.vy = 0
        self.rvx = 0
        self.rvy = 0
        self.vc = 0
        self.rc = 0
        self.rcc = 0
        self.vcc = 0
        self.vcc2 = 0
项目:Boardgame    作者:RensMo    | 项目源码 | 文件源码
def update(self, screen_rect):
        self.vcc2 = abs(self.rvx) + abs(self.rvy)
        if self.click:
            self.rect.move_ip(pygame.mouse.get_rel())
            self.rect.clamp_ip(screen_rect)
        if self.rc == 3:
            if self.rvx > 0:
                self.rvx -= 1
            if self.rvx < 0:
                self.rvx += 1
            if self.rvy > 0:
                self.rvy -= 1
            if self.rvy < 0:
                self.rvy += 1
        if self.vcc >= 30:
            self.color = pygame.Color(random.choice(self.rcolor))
        if self.rc == 3 and self.vcc2 < 30:
            self.color = pygame.Color(self.ccolor)
        self.rect.move_ip(self.rvx, self.rvy)
        self.rect.clamp_ip(screen_rect)
项目:Boardgame    作者:RensMo    | 项目源码 | 文件源码
def draw(self):
        if self.S0[0] == 1:
            self.M1.draw(self.screen)
        if self.S0[1] == 1:
            self.screen.fill((pygame.Color("Light Green")))
            self.B1.draw(self.screen)
            # Draw grid
            self.entry_tile.Draw(self.screen, self.width * 0.028, self.height * 0.05)

            # Update Player
            self.P1.Update()
            self.P1.Draw(self.screen, self.width * 0.028, self.height * 0.05)
            self.D1.update(self.screen_rect)
            self.D1.draw(self.screen)
            self.D1.vel(self.width, self.height)
        if self.S0[2] == 1:
            self.screen.fill((pygame.Color("Light Blue")))
            self.B2.draw(self.screen)
            self.H1.draw(self.screen)
            self.H2.draw(self.screen)
        if self.S0[3] == 1:
            self.screen.fill((pygame.Color("Yellow")))
            self.B3.draw(self.screen)

        pygame.display.update()
项目:Boardgame    作者:RensMo    | 项目源码 | 文件源码
def __init__(self, x, y, sx, sy):
        self.x = x
        self.y = y
        self.rect = pygame.Rect((x, y), (sx, sy))
        self.click = False
        self.rcolor = ["Red", "Green", "Blue", "White", "Yellow", "Black"]
        self.color = pygame.Color("White")
        self.ccolor = random.choice(self.rcolor)

        self.vxy = 0
        self.vx = 0
        self.vy = 0
        self.rvx = 0
        self.rvy = 0
        self.vc = 0
        self.rc = 0
        self.rcc = 0
        self.vcc = 0
        self.vcc2 = 0
项目:Boardgame    作者:RensMo    | 项目源码 | 文件源码
def update(self, screen_rect):
        self.vcc2 = abs(self.rvx) + abs(self.rvy)
        if self.click:
            self.rect.move_ip(pygame.mouse.get_rel())
            self.rect.clamp_ip(screen_rect)
        if self.rc == 3:
            if self.rvx > 0:
                self.rvx -= 1
            if self.rvx < 0:
                self.rvx += 1
            if self.rvy > 0:
                self.rvy -= 1
            if self.rvy < 0:
                self.rvy += 1
        if self.vcc >= 30:
            self.color = pygame.Color(random.choice(self.rcolor))
        if self.rc == 3 and self.vcc2 < 30:
            self.color = pygame.Color(self.ccolor)
        self.rect.move_ip(self.rvx, self.rvy)
        self.rect.clamp_ip(screen_rect)
        print(self.rc, self.vcc)
项目:Boardgame    作者:RensMo    | 项目源码 | 文件源码
def __init__(self):
        self.width = 800
        self.height = 600
        self.size = (self.width, self.height)
        self.caption = "Button Test"
        self.color = pygame.Color("Grey")

        self.M0 = 1
        self.M1 = 0

        pygame.init()

        self.b1 = Button(self.width * 0.85, self.height * 0.05, self.width * 0.1, self.height * 0.05, "Menu")
        self.Menu1 = MainMenu(self.width, self.height)

        self.screen = pygame.display.set_mode(self.size)
        pygame.display.set_caption(self.caption)
项目:Boardgame    作者:RensMo    | 项目源码 | 文件源码
def draw(self, surface):
        mouse = pygame.mouse.get_pressed()
        self.sound = Sound1

        if not self.rect.collidepoint(pygame.mouse.get_pos()):
            surface.blit(self.I, (self.rect))
        elif self.rect.collidepoint(pygame.mouse.get_pos()):
            if mouse[0]:
                self.sound.play()
            self.I = pygame.transform.scale(self.I, (int(self.sx * 1.02), int(self.sy * 1.02)))
            self.rect = pygame.Rect((int(self.x - (self.sx * 1.02 - self.sx)), int(self.y - (self.sy * 1.02 - self.sy))), (int(self.sx), int(self.sy)))
            self.srect = pygame.Surface((int(self.sx * 1.02), int(self.sy * 1.04)))
            self.srect.fill(pygame.Color("Black"))
            self.srect.set_alpha(68)
            surface.blit(self.srect, (int(self.x), int(self.y)))
            surface.blit(self.I, (self.rect))
项目:Boardgame    作者:RensMo    | 项目源码 | 文件源码
def __init__(self, x, y, btext, size, width, rI, color=pygame.Color("black"), underline=None):
        self.x = x
        self.y = y
        self.size = size
        self.width = width
        self.font = pygame.font.Font("Assets/Berlin Sans FB.ttf", self.size)
        self.underline = underline
        if self.underline == True:
            print("underline = true")
            self.font.set_underline(True)
        elif self.underline == False:
            print("underline = true")
            self.font.set_underline(False)
        self.color = color
        self.btext = btext
        self.atext = ""
        self.etext = self.font.render(self.btext + self.atext, 1, (self.color))
        self.shifted = False
        self.maxlength = 60
        self.focus = 0
        self.rect = pygame.Rect((self.x, self.y), (self.width, self.size))
        self.srect = pygame.Surface((int(self.width), int(self.size)))
        self.rI = rI
项目:Boardgame    作者:RensMo    | 项目源码 | 文件源码
def __init__(self, x, y, btext, size, width, rI, color=pygame.Color("black"), underline=None):
        self.x = x
        self.y = y
        self.size = size
        self.width = width
        self.font = pygame.font.Font("Assets/Berlin Sans FB.ttf", self.size)
        self.underline = underline
        if self.underline == True:
            print("underline = true")
            self.font.set_underline(True)
        elif self.underline == False:
            print("underline = true")
            self.font.set_underline(False)
        self.color = color
        self.btext = btext
        self.atext = ""
        self.etext = self.font.render(self.btext + self.atext, 1, (self.color))
        self.shifted = False
        self.maxlength = 26
        self.focus = 0
        self.rect = pygame.Rect((self.x, self.y), (self.width, self.size))
        self.srect = pygame.Surface((int(self.width), int(self.size)))
        self.rI = rI
项目:CoolesSpiel    作者:AlinaGri    | 项目源码 | 文件源码
def __init__(self, x, y, width, height, editable = False, font = textwidget.defaultFont, selectioncolor = selectiontextwidget.defaultSelection):
        """
        Initialisation of an Listbox

        parameters:     int x-coordinate of the Listbox (left)
                        int y-coordinate of the Listbox (top)
                        int width of the Listbox
                        int height of the Listbox
                        boolean if the Listbox should be editable
                        pygame.font.Font font of the Listbox
                        tuple of format pygame.Color representing the Listbox's selection-color
        return values:  -
        """
        super(Listbox, self).__init__(x, y, width, height, "", font, selectioncolor = selectiontextwidget.defaultSelection)
        self._list      = []
        self._editable  = editable