def clamp(x, min_value, max_value): return max(min(x, max_value), min_value) def mix(a, b, mix): return a * (1 - mix) + b * mix