1 -- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
4 module("luci.statistics.rrdtool.colors", package.seeall)
9 Instance = luci.util.class()
11 function Instance.from_string( self, s )
13 tonumber(s:sub(1,2), 16),
14 tonumber(s:sub(3,4), 16),
15 tonumber(s:sub(5,6), 16)
19 function Instance.to_string( self, c )
28 function Instance.random( self )
29 local r = math.random(255)
30 local g = math.random(255)
34 if ( r + g ) < 255 then
40 local b = min + math.floor( math.random() * ( max - min ) )
45 function Instance.faded( self, fg, opts )
47 opts.background = opts.background or { 255, 255, 255 }
48 opts.alpha = opts.alpha or 0.25
50 if type(opts.background) == "string" then
51 opts.background = _string_to_color(opts.background)
54 local bg = opts.background
57 ( opts.alpha * fg[1] ) + ( ( 1.0 - opts.alpha ) * bg[1] ),
58 ( opts.alpha * fg[2] ) + ( ( 1.0 - opts.alpha ) * bg[2] ),
59 ( opts.alpha * fg[3] ) + ( ( 1.0 - opts.alpha ) * bg[3] )