Exemplo n.º 1
0
def random_colour_cmyk(c=None, m=None, y=None, k=None):
    if c is None:
        c = randomrandint(0, 100)
    elif isinstance(c, int):
        if c > 100 or c < 0:
            raise GraphicsError(
                f"\n\nGraphicsError: The c value must be between 0 & 100 inclusive, not {c}"
            )
    else:
        raise GraphicsError(
            f"\n\nGraphicsError: The c value must be an integer or None, not {c}"
        )

    if m is None:
        m = randomrandint(0, 100)
    elif isinstance(m, int):
        if m > 100 or m < 0:
            raise GraphicsError(
                f"\n\nGraphicsError: The m value must be between 0 & 100 inclusive, not {m}"
            )
    else:
        raise GraphicsError(
            f"\n\nGraphicsError: The m value must be an integer or None, not {m}"
        )

    if y is None:
        y = randomrandint(0, 100)
    elif isinstance(y, int):
        if y > 100 or y < 0:
            raise GraphicsError(
                f"\n\nGraphicsError: The y value must be between 0 & 100 inclusive, not {y}"
            )
    else:
        raise GraphicsError(
            f"\n\nGraphicsError: he y value must be an integer or None, not {y}"
        )

    if k is None:
        k = randomrandint(0, 100)
    elif isinstance(k, int):
        if k > 100 or k < 0:
            raise GraphicsError(
                f"\n\nGraphicsError: The k value must be between 0 & 100 inclusive, not {k}"
            )
    else:
        raise GraphicsError(
            f"\n\nGraphicsError: The k value must be an integer or None, not {k}"
        )

    return ColourCMYK(c, m, y, k)
Exemplo n.º 2
0
def random_colour_hsl(h=None, s=None, l=None):
    if h is None:
        h = randomrandint(0, 359)
    elif isinstance(h, int):
        if h > 359 or h < 0:
            raise GraphicsError(
                f"\n\nGraphicsError: The h value must be between 0 & 100 inclusive, not {h}"
            )
    else:
        raise GraphicsError(
            f"\n\nGraphicsError: The h value must be an integer or None, not {h}"
        )

    if s is None:
        s = randomrandint(0, 100) / 100
    elif isinstance(s, (float, int)):
        if s > 1 or s < 0:
            raise GraphicsError(
                f"\n\nGraphicsError: The s value must be between 0 & 1 inclusive, not {s}"
            )
    else:
        raise GraphicsError(
            f"\n\nGraphicsError: The s value must be an integer or float or None, not {s}"
        )

    if l is None:
        l = randomrandint(0, 100) / 100
    elif isinstance(l, (float, int)):
        if l > 1 or l < 0:
            raise GraphicsError(
                f"\n\nGraphicsError: The l value must be between 0 & 1 inclusive, not {l}"
            )
    else:
        raise GraphicsError(
            f"\n\nGraphicsError: The l value must be an integer or float or None, not {l}"
        )

    return ColourHSL(h, s, l)
Exemplo n.º 3
0
def random_colour_hsv(h=None, s=None, v=None):
    if h is None:
        h = randomrandint(0, 359)
    elif isinstance(h, int):
        if h > 359 or h < 0:
            raise GraphicsError(
                f"\n\nGraphicsError: The h value must be between 0 & 100 inclusive, not {h}"
            )
    else:
        raise GraphicsError(
            f"\n\nGraphicsError: The h value must be an integer or None, not {h}"
        )

    if s is None:
        s = randomrandint(0, 100) / 100
    elif isinstance(s, (float, int)):
        if s > 1 or s < 0:
            raise GraphicsError(
                f"\n\nGraphicsError: The s value must be between 0 & 1 inclusive, not {s}"
            )
    else:
        raise GraphicsError(
            f"\n\nGraphicsError: The s value must be an integer or float or None, not {s}"
        )

    if v is None:
        v = randomrandint(0, 100) / 100
    elif isinstance(v, (float, int)):
        if v > 1 or v < 0:
            raise GraphicsError(
                f"\n\nGraphicsError: The v value must be between 0 & 1 inclusive, not {v}"
            )
    else:
        raise GraphicsError(
            f"\n\nGraphicsError: The v value must be an integer or float or None, not {v}"
        )

    return ColourHSV(h, s, v)
Exemplo n.º 4
0
def random_colour_rgb(red=None, green=None, blue=None):
    if red is None:
        red = randomrandint(0, 255)
    elif isinstance(red, int):
        if red > 255 or red < 0:
            raise GraphicsError(
                f"\n\nThe red value must be between 0 & 255 inclusive, not {red}"
            )
    else:
        raise GraphicsError(
            f"\n\nGraphicsError: The red value must be an integer or None, not {red}"
        )

    if green is None:
        green = randomrandint(0, 255)
    elif isinstance(green, int):
        if green > 255 or green < 0:
            raise GraphicsError(
                f"\n\nThe green value must be between 0 & 255 inclusive, not {green}"
            )
    else:
        raise GraphicsError(
            f"\n\nGraphicsError: The green value must be an integer or None, not {green}"
        )

    if blue is None:
        blue = randomrandint(0, 255)
    elif isinstance(blue, int):
        if blue > 255 or blue < 0:
            raise GraphicsError(
                f"\n\nGraphicsError: The blue value must be between 0 & 255 inclusive, not {blue}"
            )
    else:
        raise GraphicsError(
            f"\n\nGraphicsError: The blue value must be an integer or None, not {blue}"
        )

    return ColourRGB(red, green, blue)
Exemplo n.º 5
0
def bgg(l,
        surf,
        MAX_X=1800,
        MAX_Y=1800,
        plat_img=None,
        plat_small=None,
        plat_big=None):
    """ background generator function
	takes a surface, and blits onto a copied surface some platforms."""
    height = 40
    width = 200
    gap = width + randomrandint(50, width // 4)
    if randomrandint(0, 1):
        gap += width // 2
    speed = max(10, width // 20)

    if plat_img is None:
        #Compute platform image
        plat_img = create_plat(width, height, 10)

    if plat_big is None:
        plat_big = plat_img
    if plat_small is None:
        plat_small = plat_img

    def blit_list(l, surf):
        for (x, y, z) in l:
            if z == 0:
                surf.blit(plat_img, (x, y))
            elif z == -1:
                surf.blit(plat_small, (x, y))
            elif z == 1:
                surf.blit(plat_big, (x, y))

    L = []
    for i in range(len(l)):  #suppression of leftmost platforms
        if l[i][0] > -10 - width:
            L.append((l[i][0] - speed, l[i][1], 0))

    #adding platforms to the right
    if L == []:
        size = randomrandint(-1, 1)
        L.append((randomrandint(MAX_X - 200, MAX_X - 150), MAX_Y // 2, size))
    elif L[-1][0] < MAX_X:
        size = randomrandint(-1, 1)
        L.append(((L[-1][0] + gap + ((gap // 2) * size)),
                  L[-1][1] + randomrandint(-height, height), size))
    #print(L)
    surfa = surf.copy()  #copies the surface

    #blitting platforms
    blit_list(L, surfa)
    return surfa, L
Exemplo n.º 6
0
def newGameBoard():
    from random import randint as randomrandint
    board = []
    for i in range(CELLNUMS):
        board.append(i)
    blackCell = CELLNUMS - 1
    board[blackCell] = -1

    for i in range(MAXRANDTIME):
        direction = randomrandint(0, 3)
        if (direction == 0):
            blackCell = moveLeft(board, blackCell)
        elif (direction == 1):
            blackCell = moveRight(board, blackCell)
        elif (direction == 2):
            blackCell = moveUp(board, blackCell)
        elif (direction == 3):
            blackCell = moveDown(board, blackCell)
    return board, blackCell
Exemplo n.º 7
0
def random_greyscale(start=0, end=255):
    if isinstance(start, int):
        if isinstance(end, int):
            if start < 0 or start > end:
                raise GraphicsError(
                    "\n\nGraphicsError: The start value must be between 0 & end, 0 <= start <="
                    f" {end}, not {start}")
            if end > 255 or end < start:
                raise GraphicsError(
                    "\n\nGraphicsError: The end value must be between start & 255, "
                    f"{start} <= end <= 255, not {end}")

            grey = randomrandint(start, end)
            return ColourRGB(grey, grey, grey)
        else:
            raise GraphicsError(
                f"\n\nGraphicsError: The end value must be an integer, not {end}"
            )
    else:
        raise GraphicsError(
            f"\n\nGraphicsError: The start value must be an integer, not {start}"
        )
Exemplo n.º 8
0
def random_colour_hex(red=None, green=None, blue=None):
    if red is None:
        red = randomrandint(0, 255)
    else:
        if not isinstance(red, str):
            raise GraphicsError(
                f"\n\nGraphicsError: The red value must be an string, not {red}"
            )
        if len(red) != 2:
            raise GraphicsError(
                f"\n\nGraphicsError: The red value must have a length of 2 #rr, not {red}"
            )
        try:
            red = int(red, 16)
        except ValueError:
            raise GraphicsError(
                f"\n\nGraphicsError: The red value must be a base 16 value, not {red}"
            )

    if green is None:
        green = randomrandint(0, 255)
    else:
        if isinstance(green, str):
            if len(green) == 2:
                try:
                    green = int(green, 16)
                except ValueError:
                    raise GraphicsError(
                        f"\n\nGraphicsError: The green value must be a base 16 value, not {green}"
                    )
            else:
                raise GraphicsError(
                    f"\n\nGraphicsError: The green value must have a length of 2 #gg, not {green}"
                )
        else:
            raise GraphicsError(
                f"\n\nGraphicsError: The green value must be an string, not {green}"
            )

    if blue is None:
        blue = randomrandint(0, 255)
    else:
        if isinstance(blue, str):
            if len(blue) == 2:
                try:
                    blue = int(blue, 16)
                except ValueError:
                    raise GraphicsError(
                        f"\n\nGraphicsError: The blue value must be a base 16 value, not {blue}"
                    )
            else:
                raise GraphicsError(
                    f"\n\nGraphicsError: The blue value must have a length of 2 #bb, not {blue}"
                )
        else:
            raise GraphicsError(
                f"\n\nGraphicsError: The blue value must be an string, not {blue}"
            )

    if red > 255 or red < 0:
        raise GraphicsError(
            f"\n\nGraphicsError: The red value must be between 0 & 255 inclusive, not {red}"
        )
    if green > 255 or green < 0:
        raise GraphicsError(
            f"\n\nGraphicsError: The green value must be between 0 & 255 inclusive, not {green}"
        )
    if blue > 255 or blue < 0:
        raise GraphicsError(
            f"\n\nGraphicsError: The blue value must be between 0 & 255 inclusive, not {blue}"
        )

    return ColourHex("#%02x%02x%02x" % (red, green, blue))