• ### How to convert Pd's color numbers for data structures to RGB

I could not find this on the web so i figured it out myself.

Here is how you can convert the numbers used in data structures to represent colors to RGB values and vice versa:

pdcolor2rgb.pd

The numbers 0 - 888 represent RGB values where every digit stands for one color. So 870 would be 8 for red, 7 for green and 0 for blue. This is equivalent to RGB (255, 223, 0). A digit 9 is the same as digit 8, so 858 = 959. The exact calculation is in the patch:

• Posts 5 | Views 2777
• @ingox This is great, thanks alot!

• Haha, in hindsight it looks so simple, but it took hours for me to figure it out, so i thought i'd better share it.

The conversion from RGB to Pd number is obviously not always exact, because the Pd numbers represent far less values, so the conversion only finds somewhat near colors.

From this thread about canvas RGB values i learned that PD calculates numbers internally with double-precision but saves them only in single-precision, which is the reason that the RGB values can actually be calculated, but the result can not be saved.

For everyone working with colors in data structures i highly recommend the jmmmp library which contains some very nice vanilla abstractions, including a color picker. You can find it at https://puredata.info/downloads/jmmmp and in Deken/Find externals. The objects are [ds-color-sel], [pd-colors] and [rgb-color].

• @ingox It's a shame Extended is so denigrated. It is dripping with patches that do the same....... but well done though....... it is far from an obvious how to resolve colours in Pd.....!
David.

• With the `[draw]` command in Purr Data there are methods to set colors:

``````[struct demo float x float y symbol foo float v1 float v2 float v3]

[fill blue(
|
[draw rect 40 40]

[demo]
``````

You can use English words to set a static color as above.
You can also do

``````[fill v1 v2 v3( <- rgb colors

[fill hsl v1 v2 v3( <- hsl colorspace

[fill hcl v1 v2 v3( <- hcl colorspace

[fill lab v1 v2 v3( <- lab colorspace

[fill symbol foo( <- variable color name
``````

The fields can also be constants, like `[fill rgb 0 255 0(`

Posts 5 | Views 2777
Internal error.

Oops! Looks like something went wrong!