Lowering a decimal RGB (hex) value


    Nov 03 2015 | 9:28 pm
    Hi guys,
    I have a decimal number which represents an RGB value and I want to lower the value in order to darken the color. To that end I convert the decimal value to hex, I split it up in 3 parts which I then individually convert back to a decimal value, I subtract the number I need and then I convert them back to their hex counterpart.
    My problem starts when I try to join all 3 parts back together (using 'join 3') in order to recreate the complete hex value again: I end up with "BC BC BC" instead of "BCBCBC" which is what I need so that I can create the right decimal value.
    I read about 'tosymbol' and how it should be able to remove the spaces from a list if you use the message separator without arguments (so 'tosymbol @') but that doesn't work for me, the spaces in my symbol remain.
    Is there a better or maybe easier way to accomplish this? I already tried checking up on jitter because I assume that it might have something to perform RGB type calculations but so far I've found nothing.
    This is the patch I'm working on, and thanks in advance for any comments!

    • Nov 03 2015 | 9:38 pm
      almost there-- just needed to simplify it a little:
      (but there may be a better approach without filling up the symbol table)
    • Nov 03 2015 | 9:50 pm
      Thanks a bunch, that's even better! I /really/ need to study that sprintf object some more, that's for sure!
      In the mean time I also came up with an alternative solution with 'regexp' but I don't really like it because it gets bloated: "regexp ^([A-Z0-9]{2})\\s([A-Z0-9]{2})\\s([A-Z0-9]{2})$ @substitute %1%2%3".
    • Nov 04 2015 | 4:34 am
      make it a list:
      [fromsymbol] [sprintf %s%s%s]
    • Nov 04 2015 | 4:46 am
      You can convert directly from decimal integer to a list of 3 ints (0-255) or a list of 6 ints (0-15). That way you can tweak the channels without messing with symbols and it makes it easier to convert to a symbol format when you need it. Just iter the base 16 list into a coll that translates 0-16 to 0-F and remove spaces with regexp.
    • Nov 04 2015 | 10:27 am
      Bit-shift / modulo would be more efficient.