Code Duplication    Length = 27-27 lines in 2 locations

tcod/libtcodpy.py 2 locations

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