-- hsv2rgb class: almost copied from the markex object hsv2rgb -- fbar 2007 -- Pd class: local function FLOAT_CLAMP(f) if f > 1 then return 1 elseif f < 0 then return 0 else return f end end local M = pd.Class:new():register("lhsv2rgb") function M:initialize(name, atoms) self.inlets = 1 self.outlets = 1 return true end function M:doit(h, s, v) local r=0 local g=0 local b=0 h = FLOAT_CLAMP(h) s = FLOAT_CLAMP(s) v = FLOAT_CLAMP(v) -- convert hue to degrees h = h * 360 if s == 0.0 then -- black and white r = v g = v b = v else if (h == 360) then h = 0 end -- 360 == 0 degrees h = h / 60 -- hue is now [0, 6] local i = math.floor(h) local f = h - i -- f is the fractional part of h local p = v * (1 - s) local q = v * (1 - s * f) local t = v * (1 - s * (1 - f)) if i == 0 then r = v g = t b = p elseif i == 1 then r = q g = v b = p elseif i == 2 then r = p g = v b = t elseif i == 3 then r = p g = q b = v elseif i == 4 then r = t g = p b = v elseif i == 5 then r = v g = p b = q end end -- Claude: Why can't I do this here:: -- self:outlet(1, "list", {r,g,b}) return {r,g,b} end function M:in_1_list(args) if #args >= 3 then self:outlet(1, "list", M:doit(unpack(args))) end end