Code Duplication    Length = 27-27 lines in 2 locations

tcod/libtcodpy.py 2 locations

@@ 1096-1122 (lines=27) @@
1093
        cr = ffi.cast('int *', r.ctypes.data)
1094
        cg = ffi.cast('int *', g.ctypes.data)
1095
        cb = ffi.cast('int *', b.ctypes.data)
1096
    else:
1097
        # otherwise convert using ffi arrays
1098
        cr = ffi.new('int[]', r)
1099
        cg = ffi.new('int[]', g)
1100
        cb = ffi.new('int[]', b)
1101
1102
    lib.TCOD_console_fill_foreground(_console(con), cr, cg, cb)
1103
1104
def console_fill_background(con, r, g, b):
1105
    """Fill the backgound of a console with r,g,b.
1106
1107
    Args:
1108
        con (Console): Any Console instance.
1109
        r (Sequence[int]): An array of integers with a length of width*height.
1110
        g (Sequence[int]): An array of integers with a length of width*height.
1111
        b (Sequence[int]): An array of integers with a length of width*height.
1112
    """
1113
    if len(r) != len(g) or len(r) != len(b):
1114
        raise TypeError('R, G and B must all have the same size.')
1115
    if (isinstance(r, _np.ndarray) and isinstance(g, _np.ndarray) and
1116
            isinstance(b, _np.ndarray)):
1117
        #numpy arrays, use numpy's ctypes functions
1118
        r = _np.ascontiguousarray(r, dtype=_np.intc)
1119
        g = _np.ascontiguousarray(g, dtype=_np.intc)
1120
        b = _np.ascontiguousarray(b, dtype=_np.intc)
1121
        cr = ffi.cast('int *', r.ctypes.data)
1122
        cg = ffi.cast('int *', g.ctypes.data)
1123
        cb = ffi.cast('int *', b.ctypes.data)
1124
    else:
1125
        # otherwise convert using ffi arrays
@@ 1068-1094 (lines=27) @@
1065
    """Set a consoles blit transparent color."""
1066
    lib.TCOD_console_set_key_color(_console(con), col)
1067
    if hasattr(con, 'set_key_color'):
1068
        con.set_key_color(col)
1069
1070
def console_delete(con):
1071
    con = _console(con)
1072
    if con == ffi.NULL:
1073
        lib.TCOD_console_delete(con)
1074
1075
# fast color filling
1076
def console_fill_foreground(con, r, g, b):
1077
    """Fill the foregound of a console with r,g,b.
1078
1079
    Args:
1080
        con (Console): Any Console instance.
1081
        r (Sequence[int]): An array of integers with a length of width*height.
1082
        g (Sequence[int]): An array of integers with a length of width*height.
1083
        b (Sequence[int]): An array of integers with a length of width*height.
1084
    """
1085
    if len(r) != len(g) or len(r) != len(b):
1086
        raise TypeError('R, G and B must all have the same size.')
1087
    if (isinstance(r, _np.ndarray) and isinstance(g, _np.ndarray) and
1088
            isinstance(b, _np.ndarray)):
1089
        #numpy arrays, use numpy's ctypes functions
1090
        r = _np.ascontiguousarray(r, dtype=_np.intc)
1091
        g = _np.ascontiguousarray(g, dtype=_np.intc)
1092
        b = _np.ascontiguousarray(b, dtype=_np.intc)
1093
        cr = ffi.cast('int *', r.ctypes.data)
1094
        cg = ffi.cast('int *', g.ctypes.data)
1095
        cb = ffi.cast('int *', b.ctypes.data)
1096
    else:
1097
        # otherwise convert using ffi arrays