summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/include_lua/color.lua
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lua/include_lua/color.lua')
-rw-r--r--apps/plugins/lua/include_lua/color.lua31
1 files changed, 10 insertions, 21 deletions
diff --git a/apps/plugins/lua/include_lua/color.lua b/apps/plugins/lua/include_lua/color.lua
index ed2e4f865e..fd321edd9d 100644
--- a/apps/plugins/lua/include_lua/color.lua
+++ b/apps/plugins/lua/include_lua/color.lua
@@ -49,17 +49,9 @@ local _clr = {} do
49 maxstate = (bit.lshift(1, 24) - 1) 49 maxstate = (bit.lshift(1, 24) - 1)
50 end 50 end
51 51
52 local function init(v)
53 return v or 0
54 end
55
56 -- clamps value to >= min and <= max rolls over to opposite 52 -- clamps value to >= min and <= max rolls over to opposite
57 local function clamp_roll(val, min, max) 53 local function clamp_roll(val, min, max)
58 if min > max then 54 -- Warning doesn't check if min < max
59 local swap = min
60 min, max = max, swap
61 end
62
63 if val < min then 55 if val < min then
64 val = max 56 val = max
65 elseif val > max then 57 elseif val > max then
@@ -72,12 +64,12 @@ local _clr = {} do
72 -- sets color -- monochrome / greyscale use 'set' -- color targets 'r,b,g' 64 -- sets color -- monochrome / greyscale use 'set' -- color targets 'r,b,g'
73 -- on monochrome/ greyscale targets: 65 -- on monochrome/ greyscale targets:
74 -- '-1' sets the highest 'color' state & 0 is the minimum 'color' state 66 -- '-1' sets the highest 'color' state & 0 is the minimum 'color' state
75 local function clrset(set, r, g, b) 67 _clr.set = function(set, r, g, b)
76 local color = set or 0 68 local color = set or 0
77 69
78 if IS_COLOR_TARGET then 70 if IS_COLOR_TARGET then
79 if (r ~= _NIL or g ~= _NIL or b ~= _NIL) then 71 if (r or g or b) then
80 r, g, b = init(r), init(g), init(b) 72 r, g, b = (r or 0), (g or 0), (b or 0)
81 color = rb.lcd_rgbpack(r, g, b) 73 color = rb.lcd_rgbpack(r, g, b)
82 end 74 end
83 end 75 end
@@ -86,21 +78,21 @@ local _clr = {} do
86 end -- clrset 78 end -- clrset
87 79
88 -- de/increments current color by 'inc' -- optionally color targets by 'r,g,b' 80 -- de/increments current color by 'inc' -- optionally color targets by 'r,g,b'
89 local function clrinc(current, inc, r, g, b) 81 _clr.inc = function(current, inc, r, g, b)
90 local color = 0 82 local color = 0
91 current = current or color 83 current = current or color
92 inc = inc or 1 84 inc = inc or 1
93 85
94 if IS_COLOR_TARGET then 86 if IS_COLOR_TARGET then
95 local ru, gu, bu = rb.lcd_rgbunpack(current); 87 local ru, gu, bu = rb.lcd_rgbunpack(current);
96 if (r ~= _NIL or g ~= _NIL or b ~= _NIL) then 88 if (r or g or b) then
97 r, g, b = init(r), init(g), init(b) 89 r, g, b = (r or 0), (g or 0), (b or 0)
98 ru = ru + r; gu = gu + g; bu = bu + b 90 ru = ru + r; gu = gu + g; bu = bu + b
99 color = rb.lcd_rgbpack(ru, gu, bu)
100 else 91 else
101 ru = ru + inc; gu = gu + inc; bu = bu + inc 92 ru = ru + inc; gu = gu + inc; bu = bu + inc
102 color = rb.lcd_rgbpack(ru, gu, bu)
103 end 93 end
94
95 color = rb.lcd_rgbpack(ru, gu, bu)
104 else 96 else
105 color = current + inc 97 color = current + inc
106 end 98 end
@@ -108,9 +100,6 @@ local _clr = {} do
108 return clamp_roll(color, 0, maxstate) 100 return clamp_roll(color, 0, maxstate)
109 end -- clrinc 101 end -- clrinc
110 102
111 -- expose functions to the outside through _clr table
112 _clr.set = clrset
113 _clr.inc = clrinc
114end -- color functions 103end -- color functions
115 104
116return _clr 105return _clr