Files
diffvg/gradientmesh/util.py
2023-05-17 16:27:52 +02:00

26 lines
511 B
Python

#!/usr/bin/env ipython
from types import FunctionType
def clamp(val, low, high):
return min(high, max(low, val))
def rgb2hex(r, g, b, a=None):
hex_value = "#{:02x}{:02x}{:02x}".format(
int(r * 255),
int(g * 255),
int(b * 255)
)
return hex_value
def any_map(f: FunctionType, lst: list):
result = []
for itm in lst:
if isinstance(itm, list):
result.append(any_map(f, itm))
else:
result.append(f(itm))
return result