lib_degrade.py

Created by ilyas-r

Created on November 17, 2023

817 Bytes

degrade() function allows to create a color degradation effect.
params of degrade()
x: x-coordinate of the starting point, int
y: y-coordinate of the starting point, int
width: width of the degradation area, int
height: height of the degradation area, int
color: initial color, tuple
target: target color, tuple
axis: degradation direction (0 for horizontal, 1 for vertical), bool

By Ilyas R.


from kandinsky import set_pixel

# By Ilyas R. November 2023

"""
params of degrade function
x: x-coordinate of the starting point, int
y: y-coordinate of the starting point, int
width: width of the degradation area, int
height: height of the degradation area, int
color: initial color, tuple
target: target color, tuple
axis: degradation direction (0 for horizontal, 1 for vertical), bool
"""


def degrade(x, y, width, height, color, target, axis=0):
    a = width if not axis else height
    t = [-(color[i] - target[i]) if color[i] - target[i] else target[i] for i in range(3)]
    for i in range(a):
        c = [abs(color[j]+round((i/(a/t[j])))) for j in range(3)]
        for k in range(width if axis else height):
            set_pixel(x + (i if not axis else k), y + (i if axis else k), c)