python类Color()的实例源码

util.py 文件源码 项目:sc8pr 作者: dmaccarthy 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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()
color_test.py 文件源码 项目:Projects 作者: it2school 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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.
color_test.py 文件源码 项目:Projects 作者: it2school 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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)))
color_test.py 文件源码 项目:Projects 作者: it2school 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
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)
color_test.py 文件源码 项目:Projects 作者: it2school 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
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))
color_test.py 文件源码 项目:Projects 作者: it2school 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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))
color_test.py 文件源码 项目:Projects 作者: it2school 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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 #######################
color_test.py 文件源码 项目:Projects 作者: it2school 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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))
color_test.py 文件源码 项目:Projects 作者: it2school 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
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
color_test.py 文件源码 项目:Projects 作者: it2school 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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.
color_test.py 文件源码 项目:Projects 作者: it2school 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
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])
surface_test.py 文件源码 项目:Projects 作者: it2school 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
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)
surface_test.py 文件源码 项目:Projects 作者: it2school 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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)
surface_test.py 文件源码 项目:Projects 作者: it2school 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
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()
surface_test.py 文件源码 项目:Projects 作者: it2school 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
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()
centered_figure.py 文件源码 项目:CC3501-2017-1 作者: ppizarror 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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
Histoire.py 文件源码 项目:RPG 作者: LugosFingite 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
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)
__init__.py 文件源码 项目:spygame 作者: sven1977 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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()
__init__.py 文件源码 项目:spygame 作者: sven1977 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
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.py 文件源码 项目:Pygame_Functions 作者: StevePaget 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
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.py 文件源码 项目:Pygame_Functions 作者: StevePaget 项目源码 文件源码 阅读 61 收藏 0 点赞 0 评论 0
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.py 文件源码 项目:Pygame_Functions 作者: StevePaget 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
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.py 文件源码 项目:Pygame_Functions 作者: StevePaget 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
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]
trig-fullpies.py 文件源码 项目:MVP2 作者: critterandguitari 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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)
color_test.py 文件源码 项目:AIFun 作者: Plottel 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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.
color_test.py 文件源码 项目:AIFun 作者: Plottel 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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)))
color_test.py 文件源码 项目:AIFun 作者: Plottel 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
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)
color_test.py 文件源码 项目:AIFun 作者: Plottel 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
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)
color_test.py 文件源码 项目:AIFun 作者: Plottel 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
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)
color_test.py 文件源码 项目:AIFun 作者: Plottel 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
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)


问题


面经


文章

微信
公众号

扫码关注公众号