import clr
clr.AddReference('Soti.IoT.SemanticEngine.Conversions')

from Soti.IoT.SemanticEngine.Conversions import Converter

print "Loading HSVtoRGB converter"

class HSVtoRGB(Converter):

	def Execute(self, myList = [], *args):
		results = map(float, myList)
		h = results[0]
		s = results[1]
		v = 1.0		
		
		rgb = (0,0,0)
		if s == 0.0: rgb = (v, v, v)
		
		i = int(h*6.) # XXX assume int() truncates!
		f = (h*6.)-i; p,q,t = v*(1.-s), v*(1.-s*f), v*(1.-s*(1.-f)); i%=6
        
		if i == 0: rgb = (v, t, p)
		if i == 1: rgb = (q, v, p)
		if i == 2: rgb = (p, v, t)
		if i == 3: rgb = (p, q, v)
		if i == 4: rgb = (t, p, v)
		if i == 5: rgb = (v, p, q)
		return '#%02x%02x%02x' % rgb
		
plugin = HSVtoRGB("HSVtoRGB")

store.AddConverter(plugin)