Code Duplication    Length = 28-28 lines in 2 locations

tcod/libtcodpy.py 2 locations

@@ 1105-1132 (lines=28) @@
1102
    lib.TCOD_console_fill_foreground(con.console_c if con else ffi.NULL,
1103
                                     cr, cg, cb)
1104
1105
def console_fill_background(con, r, g, b):
1106
    """Fill the backgound of a console with r,g,b.
1107
1108
    Args:
1109
        con (Console): Any Console instance.
1110
        r (Sequence[int]): An array of integers with a length of width*height.
1111
        g (Sequence[int]): An array of integers with a length of width*height.
1112
        b (Sequence[int]): An array of integers with a length of width*height.
1113
    """
1114
    if len(r) != len(g) or len(r) != len(b):
1115
        raise TypeError('R, G and B must all have the same size.')
1116
    if (_numpy_available() and isinstance(r, _numpy.ndarray) and
1117
        isinstance(g, _numpy.ndarray) and isinstance(b, _numpy.ndarray)):
1118
        #numpy arrays, use numpy's ctypes functions
1119
        r = _numpy.ascontiguousarray(r, dtype=_numpy.intc)
1120
        g = _numpy.ascontiguousarray(g, dtype=_numpy.intc)
1121
        b = _numpy.ascontiguousarray(b, dtype=_numpy.intc)
1122
        cr = ffi.cast('int *', r.ctypes.data)
1123
        cg = ffi.cast('int *', g.ctypes.data)
1124
        cb = ffi.cast('int *', b.ctypes.data)
1125
    else:
1126
        # otherwise convert using ffi arrays
1127
        cr = ffi.new('int[]', r)
1128
        cg = ffi.new('int[]', g)
1129
        cb = ffi.new('int[]', b)
1130
1131
    lib.TCOD_console_fill_background(con.console_c if con else ffi.NULL,
1132
                                     cr, cg, cb)
1133
1134
def console_fill_char(con,arr):
1135
    """Fill the character tiles of a console with an array.
@@ 1076-1103 (lines=28) @@
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 (_numpy_available() and isinstance(r, _numpy.ndarray) and
1088
        isinstance(g, _numpy.ndarray) and isinstance(b, _numpy.ndarray)):
1089
        #numpy arrays, use numpy's ctypes functions
1090
        r = _numpy.ascontiguousarray(r, dtype=_numpy.intc)
1091
        g = _numpy.ascontiguousarray(g, dtype=_numpy.intc)
1092
        b = _numpy.ascontiguousarray(b, dtype=_numpy.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
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(con.console_c if con else ffi.NULL,
1103
                                     cr, cg, cb)
1104
1105
def console_fill_background(con, r, g, b):
1106
    """Fill the backgound of a console with r,g,b.