From 5db43e674dfa2ea739d9513f02e01d7c31851bee Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 1 Oct 2025 14:11:32 +0200 Subject: [PATCH] Color: afegit metode LERP() --- source/color.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/source/color.h b/source/color.h index 413af34..7b6822d 100644 --- a/source/color.h +++ b/source/color.h @@ -95,6 +95,29 @@ struct Color { return Color(new_r, new_g, new_b, new_a); } + // Interpolación lineal hacia otro color (t=0.0: this, t=1.0: target) + [[nodiscard]] constexpr auto LERP(const Color &target, float t) const -> Color { + // Asegurar que t esté en el rango [0.0, 1.0] + t = std::clamp(t, 0.0f, 1.0f); + + // Interpolación lineal para cada componente + auto lerp_component = [t](Uint8 start, Uint8 end) -> Uint8 { + return static_cast(start + (end - start) * t); + }; + + return Color( + lerp_component(r, target.r), + lerp_component(g, target.g), + lerp_component(b, target.b), + lerp_component(a, target.a) + ); + } + + // Sobrecarga para aceptar componentes RGBA directamente + [[nodiscard]] constexpr auto LERP(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha, float t) const -> Color { + return LERP(Color(red, green, blue, alpha), t); + } + // Convierte el color a un entero de 32 bits en formato RGBA [[nodiscard]] constexpr auto TO_UINT32() const -> Uint32 { return (static_cast(r) << 24) |