Page 1 of 1

Recreate specific colour

Posted: Sat May 26, 2018 2:16 am
by Tlyman
I have an SVG image containing a specific colour which I would like to use. I looked up the HSL values of it in an SVG editor (Inkscape).

Now when I try to recreate that colour to use it in a primitive shape by mapping from the SVG ranges to the CFDG ones, the hue is correct, but the S and L values are lower. An example:

Code: Select all

startshape colour_test

shape colour_test {
    svg_h = 128
    svg_s = 172
    svg_l = 128
    CIRCLE [ hue (svg_h / 255 * 359) saturation (svg_s / 255) brightness (svg_l / 255) ]
}
When generating SVG from that with the cfdg command, the resulting colour is HSL (128, 129, 85).

The documentation says that the saturation and brightness adjustments change the existing values by the given percentage towards 1. But as the initial values are 0, in my understanding the result should be the provided target values.

What am I missing?

Re: Recreate specific colour

Posted: Sat May 26, 2018 6:23 am
by Tlyman
Never mind, I solved it :)

I extracted the HSBColor constructor and hacked it into a small command-line tool which reads RGBA values and outputs the corresponding HSBA values used by cfdg.

When I use these for my shape, it's coloured as expected (once I figured out that the input RGBA values must have a range from 0 to 1 instead of from 0 to 255 ;) ).

Still, this issue might be worth mentioning in the documentation because the behaviour is rather not obvious.

Re: Recreate specific colour

Posted: Sun May 27, 2018 2:33 pm
by MtnViewJohn
There are actually two functions: hsb2rgb() and rgb2hsb() that convert between HSB and RGB. But I forgot to document them. Context Free uses HSB/HSV, which is similar to HSL but not exactly the same. Also, there is a utility dialog called the Color Calculator that can be used to manually convert between RGB and HSB. It is under the Window menu on Mac and a different menu on Windows (edit menu maybe).

Re: Recreate specific colour

Posted: Fri Jun 22, 2018 1:50 pm
by Tlyman
Good to know for next time, thanks! Maybe you'll find the time to update the documentation :) I didn't even know that there's a difference between HSB and HSL.

As I'm on Linux and didn't want to bother with compiling, I just used the command line tool from the package manager and couldn't try that Color Calculator :)