[PD-dev] 'cnv' colors

Claude Heiland-Allen claudiusmaximus at goto10.org
Mon Jul 7 20:06:49 CEST 2008


Mike McGonagle wrote:
> Hello all,
> 
> I have a program that I have written that creates lots of small 'cnv'
> objects, where I am changing the colors of the backgrounds and the text in
> the object. I was noticing that when I create these cnv objects, I have to
> use a different 'color number' to get the same color when I change it with
> the cnv 'color' message (which changes both the background and text colors
> in the same message).
> 
> Is this documented anywhere as to the relation between these two different
> color definitions?

Not as far as I'm aware, but here's my implementations that work for me:

/* colour */
float r, g, b; /* 0<={r,g,b}<=1 */

/* RGB -> Pd file */
int c = ((((int) (r * 63.0)) << 12)
       | (((int) (g * 63.0)) << 6)
       | ((int) (b * 63.0))) ^ (-1);

/* RGB -> Pd message */
int c = ((((int) (r * 255.0)) << 16)
       | (((int) (g * 255.0)) << 8)
       | ((int) (b * 255.0))) ^ (-1);


Claude
-- 
http://claudiusmaximus.goto10.org





More information about the Pd-dev mailing list