From 541aff4d135d69debf0284d9629b2179e2bb9b44 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Sat, 4 Nov 2017 17:17:35 +0100 Subject: [PATCH] interpolate_rgb can now handle alpha channels well. --- colors.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/colors.lua b/colors.lua index 5eca7a1..0faeb43 100644 --- a/colors.lua +++ b/colors.lua @@ -83,7 +83,13 @@ end -- Interpolation colors.interpolate_rgb = function (c1, c2, t) - return { c1[1]+(c2[1]-c1[1])*t, c1[2]+(c2[2]-c1[2])*t, c1[3]+(c2[3]-c1[3])*t } + assert(type(c1) == 'table' and type(c1[1]) == 'number' and type(c1[2]) == 'number' and type(c1[3]) == 'number' and (type(c1[4]) == 'number' or c1[4] == nil)) + assert(type(c2) == 'table' and type(c2[1]) == 'number' and type(c2[2]) == 'number' and type(c2[3]) == 'number' and (type(c2[4]) == 'number' or c2[4] == nil)) + assert(type(t) == 'number') + -- + local alpha = nil + if c1[4] or c2[4] then alpha = (c1[4] or 255) + ((c2[4] or 255)-(c1[4] or 255))*t end + return { c1[1]+(c2[1]-c1[1])*t, c1[2]+(c2[2]-c1[2])*t, c1[3]+(c2[3]-c1[3])*t, alpha } end local function angle_delta (a1, a2)