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)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.