From 96aec93fc546860cf009796bc2dddd8022c8e3c2 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Mon, 22 Oct 2018 13:14:00 +0200 Subject: [PATCH 1/2] Fixed bug --- colors.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/colors.lua b/colors.lua index 0faeb43..f12b545 100644 --- a/colors.lua +++ b/colors.lua @@ -22,10 +22,9 @@ colors.rgb_to_hsl = function (color) local b = (color[3] == 255 and 1 or color[3]/256) local max, min = math.max(r, g, b), math.min(r, g, b) + if min == max then return { 0, 0, (max+min)/2 } end + local h, s, l = (max+min)/2, (max+min)/2, (max+min)/2 - if min == max then - return {0, 0, l} - end local d = max - min s = l > 0.5 and d / (2 - max - min) or d / (max + min) @@ -86,7 +85,7 @@ colors.interpolate_rgb = function (c1, c2, 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 } @@ -151,3 +150,4 @@ end -------------------------------------------------------------------------------- return colors + From 8241e060994090767c791253b84ddc2af95a9607 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Mon, 22 Oct 2018 13:16:41 +0200 Subject: [PATCH 2/2] HSL to RGB1. --- colors.lua | 11 ++++++++++- init.lua | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/colors.lua b/colors.lua index 0faeb43..bcd28ae 100644 --- a/colors.lua +++ b/colors.lua @@ -12,6 +12,10 @@ local colors = {} -------------------------------------------------------------------------------- -- Conversion +colors.rgb255_to_rgb1 = function (color) + return { color[1]/255, color[2]/255, color[3]/255, (color[4] or 255)/255 } +end + colors.rgb_to_hsl = function (color) -- Error check assert(type(color) == 'table' and type(color[1]) == 'number' and type(color[2]) == 'number' and type(color[3]) == 'number') @@ -79,6 +83,10 @@ colors.hsl_to_rgb = function (color) return { r, g, b } end +colors.hsl_to_rgb1 = function (...) + return colors.rgb255_to_rgb1(colors.hsl_to_rgb(...)) +end + -------------------------------------------------------------------------------- -- Interpolation @@ -86,7 +94,7 @@ colors.interpolate_rgb = function (c1, c2, 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 } @@ -151,3 +159,4 @@ end -------------------------------------------------------------------------------- return colors + diff --git a/init.lua b/init.lua index 86fc208..4a6216b 100644 --- a/init.lua +++ b/init.lua @@ -1 +1,2 @@ -return require 'colors.colors' + +return require ((...) .. '.colors')