Code Duplication    Length = 27-27 lines in 2 locations

tcod/libtcodpy.py 2 locations

@@ 943-969 (lines=27) @@
940
        # otherwise convert using ffi arrays
941
        cr = ffi.new('int[]', r)
942
        cg = ffi.new('int[]', g)
943
        cb = ffi.new('int[]', b)
944
945
    lib.TCOD_console_fill_foreground(_cdata(con), cr, cg, cb)
946
947
def console_fill_background(con, r, g, b):
948
    """Fill the backgound of a console with r,g,b.
949
950
    Args:
951
        con (Console): Any Console instance.
952
        r (Sequence[int]): An array of integers with a length of width*height.
953
        g (Sequence[int]): An array of integers with a length of width*height.
954
        b (Sequence[int]): An array of integers with a length of width*height.
955
    """
956
    if len(r) != len(g) or len(r) != len(b):
957
        raise TypeError('R, G and B must all have the same size.')
958
    if (_numpy_available() and isinstance(r, _numpy.ndarray) and
959
        isinstance(g, _numpy.ndarray) and isinstance(b, _numpy.ndarray)):
960
        #numpy arrays, use numpy's ctypes functions
961
        r = _numpy.ascontiguousarray(r, dtype=_numpy.intc)
962
        g = _numpy.ascontiguousarray(g, dtype=_numpy.intc)
963
        b = _numpy.ascontiguousarray(b, dtype=_numpy.intc)
964
        cr = ffi.cast('int *', r.ctypes.data)
965
        cg = ffi.cast('int *', g.ctypes.data)
966
        cb = ffi.cast('int *', b.ctypes.data)
967
    else:
968
        # otherwise convert using ffi arrays
969
        cr = ffi.new('int[]', r)
970
        cg = ffi.new('int[]', g)
971
        cb = ffi.new('int[]', b)
972
@@ 915-941 (lines=27) @@
912
913
def console_delete(con):
914
    con = _cdata(con)
915
    if con == ffi.NULL:
916
        lib.TCOD_console_delete(con)
917
918
# fast color filling
919
def console_fill_foreground(con, r, g, b):
920
    """Fill the foregound of a console with r,g,b.
921
922
    Args:
923
        con (Console): Any Console instance.
924
        r (Sequence[int]): An array of integers with a length of width*height.
925
        g (Sequence[int]): An array of integers with a length of width*height.
926
        b (Sequence[int]): An array of integers with a length of width*height.
927
    """
928
    if len(r) != len(g) or len(r) != len(b):
929
        raise TypeError('R, G and B must all have the same size.')
930
    if (_numpy_available() and isinstance(r, _numpy.ndarray) and
931
        isinstance(g, _numpy.ndarray) and isinstance(b, _numpy.ndarray)):
932
        #numpy arrays, use numpy's ctypes functions
933
        r = _numpy.ascontiguousarray(r, dtype=_numpy.intc)
934
        g = _numpy.ascontiguousarray(g, dtype=_numpy.intc)
935
        b = _numpy.ascontiguousarray(b, dtype=_numpy.intc)
936
        cr = ffi.cast('int *', r.ctypes.data)
937
        cg = ffi.cast('int *', g.ctypes.data)
938
        cb = ffi.cast('int *', b.ctypes.data)
939
    else:
940
        # otherwise convert using ffi arrays
941
        cr = ffi.new('int[]', r)
942
        cg = ffi.new('int[]', g)
943
        cb = ffi.new('int[]', b)
944