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)
6 local util = require("luci.util")
9 Instance = 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.defined( self, i )
41 t[(i-1) % #t + 1][1], t[(i-1) % #t +1][2], t[(i-1) % #t + 1][3] )
44 function Instance.random( self )
45 local r = math.random(255)
46 local g = math.random(255)
50 if ( r + g ) < 255 then
56 local b = min + math.floor( math.random() * ( max - min ) )
61 function Instance.faded( self, fg, opts )
63 opts.background = opts.background or { 255, 255, 255 }
64 opts.alpha = opts.alpha or 0.25
66 if type(opts.background) == "string" then
67 opts.background = _string_to_color(opts.background)
70 local bg = opts.background
73 ( opts.alpha * fg[1] ) + ( ( 1.0 - opts.alpha ) * bg[1] ),
74 ( opts.alpha * fg[2] ) + ( ( 1.0 - opts.alpha ) * bg[2] ),
75 ( opts.alpha * fg[3] ) + ( ( 1.0 - opts.alpha ) * bg[3] )