What number is red?

josha's icon

Hi,

I'm trying to design a patch where the colour swatch position assigns a number. I've attached the patch, and would love some help with it please.

cheers,

Max Patch
Copy patch and select New From Clipboard in Max.

J

josha's icon

bump :)

Floating Point's icon

have a look at jit.colorspace, after doing the conversion from rgb to hls, you'll need to unpack and then scale the h value to the range you want

josha's icon

could I get an example please? Finding it complex to get head 'round.

Floating Point's icon

examples are in the relevant help files:
jit.colorspace
unpack
scale

josha's icon

Hi,

Thanks for pointing me to the helpfiles. Though. having trouble adapting them to my patch idea.. its a little beyond my grasp. Any examples or tweaks of my original patch would be really appreciated.

metamax's icon

The number of red? That depends on the flavor of Thursday and the time of corduroy. But if you're just looking for the broad stroke, red primary is the first value of RGB of which the purest expression is 255 0 0, normalized as 1 0 0. But if you want just a number, then it would be 16,711,680 or 111111110000000000000000 binary. Unless you stick with hue, in which case it's 0.

Here is the simplest way I know to get your patching going...

Max Patch
Copy patch and select New From Clipboard in Max.

metamax's icon

If you have to use the actual output of swatch, you can convert RGB to hue and scale it to your index range. But the standard color conversion objects in max kinda suck (with the glorious exception of rgb2hsl and hsl2rgb in jit.pix). Here's an rgb to hue patch that uses standard max objects and outputs accurate values.

Max Patch
Copy patch and select New From Clipboard in Max.

josha's icon

Cool thanks for the examples metamix- Really useful!