Old 01-06-2017, 06:30 PM   #1
Lawrence
Human being with feelings
 
Join Date: Mar 2007
Posts: 21,551
Default Color Codes

I'm stumped on this one. I'm trying to parse a color code that is a 6-digit number, like light green returns 303364 as a color value.

I tried Hex, it's not that. Any ideas?
Lawrence is offline   Reply With Quote
Old 01-06-2017, 06:44 PM   #2
karbomusic
Human being with feelings
 
karbomusic's Avatar
 
Join Date: May 2009
Posts: 29,260
Default

Quote:
Originally Posted by Lawrence View Post
I'm stumped on this one. I'm trying to parse a color code that is a 6-digit number, like light green returns 303364 as a color value.

I tried Hex, it's not that. Any ideas?
Where are you getting it from? I thought it might be HSL but that is coming up more of tan color.
__________________
Music is what feelings sound like.
karbomusic is offline   Reply With Quote
Old 01-06-2017, 06:50 PM   #3
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

It is hex, but represented as a decimal. I'm not sure why that form gets used, but gfx.clear in the Reaper API does so I had to figure it out. Just convert it back to hex with a leading 0 and you're good. i.e. 303364 --> 04A104 --> RGB 4, 161, B

Going the other way you can skip the hex conversion: (Lua example)
Code:
function rgb2num(red, green, blue)

	green = green * 256
	blue = blue * 256 * 256
	
	return red + green + blue

end
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 01-07-2017, 02:56 AM   #4
Lawrence
Human being with feelings
 
Join Date: Mar 2007
Posts: 21,551
Default

Quote:
Originally Posted by karbomusic View Post
Where are you getting it from? I thought it might be HSL but that is coming up more of tan color.
It's a value coming back from the same object model the other JS code was addressing. No idea why they used that instead of plain hex.

Quote:
Originally Posted by Lokasenna View Post
It is hex, but represented as a decimal. I'm not sure why that form gets used, but gfx.clear in the Reaper API does so I had to figure it out. Just convert it back to hex with a leading 0 and you're good. i.e. 303364 --> 04A104 --> RGB 4, 161,
Bingo... thanks. I actually figured it out late last night but your help is still greatly appreciated. I have to say, Reaper has some of the smartest forum members most anywhere I've bother to read. I suppose Justin being a geek himself attracts good minds.

Thanks L.
Lawrence is offline   Reply With Quote
Old 01-07-2017, 03:09 AM   #5
Lawrence
Human being with feelings
 
Join Date: Mar 2007
Posts: 21,551
Default

One other question for you two who are better coders than me as relates to efficiency.

Say I have 10 things that need to be cross-referenced against an unknown number of other things. I know I can check each of the ten things one at a time against a loop iteration of all of the other things, but that sounds slow before I even try it, making multiple iterations.

Generally speaking, what's the best way to approach something like that planning wise, that would be more efficient? Should I throw the larger array into a string and then maybe do a RegEx compare or something against the target to speed that up?

Thanks.
Lawrence is offline   Reply With Quote
Old 01-07-2017, 08:02 AM   #6
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

I'm just a Lua noob who happened to have run across the same problem before. Definitely not a great coder.

As for the efficiency question:

- Putting them into a string and using string functions seems like it would help, yeah. You could always write the function multiple ways and have it spit out a timestamp before and after, so you can actually see which approach is fastest.

- Do all ten things need to be cross-referenced against everything, or is it a case of "look until you find a match, and then move on to the next item"? Being able to break the loop early for any reason would definitely help you out.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 01-08-2017, 06:07 AM   #7
Lawrence
Human being with feelings
 
Join Date: Mar 2007
Posts: 21,551
Default

Yeah, that was slow as molasses my first code so I did what you suggested...

- Unknown number of things to cross reference.
- 10 lists of things to check against the unknown number.

I put the lists into arrays before the loop and check each thing against the arrays as it loops and on any hit escape, which seems to work fast enough.

This is all coloring clips by name and the clips are the unknown number. As I tested my first code with a real world project it crawled to a halt doing the referencing. The second code seems to work faster. This is one of those cases where Javascript is clearly not as fast as C++ or similar, so you have to be very aware of coding efficiency or methods.

Your other function below was perfect, thanks. It's puzzling that JS has no inherent routine for that. In VB/C# RGB() color objects auto-resolve to their integer / decimal counterparts with no additional math. You can just debug print or quick watch rgb(23,355,67) or similar and get that number.

Code:
    this.getColorCode = function (red, green, blue) {
        var blue = blue * 256 * 256;
        var green = green * 256;
        return red + green + blue;
    }

Last edited by Lawrence; 01-08-2017 at 06:14 AM.
Lawrence is offline   Reply With Quote
Old 06-09-2017, 04:46 AM   #8
Pet
Human being with feelings
 
Pet's Avatar
 
Join Date: Nov 2015
Location: Germany
Posts: 1,015
Default

Maybe this one is useful (FREE as in free beer ): pkColorPicker.

This gives you the values of colors by clicking on the color you see on your monitor. In decimal (this one is used by SWS color sets), Hexadecimal and RGB decimal. You can for instance type in the RGB values and get the hex result.

I just thought I'd mention it here...

Quote from the homepage http://www.color-picker.de/en/features/color-numbers:
Quote:
COLOR NUMBERS

The three textboxes on bottom left show the color numbers that often are used in various applications.

Color number decimal and Color number hexadecimal is the number, that is assign to a color by 24 bit color depth. It is calculated with the formula for additive color mix: (Color number) = (red intensity) ∙ 2560 + (green intensity) ∙ 2560 + (blue intensity) ∙ 2562. The both representations of color number are often used in programming languages.

RGB hexadecimal for HTML is built of one after the other written hexadecimal values of red, green and blue intensity. It is used in HTML and many graphic programs.
__________________
If the v5 Default Theme is too bright for you take a gander at my mod of it: Default v5 Dark Theme
Pet is offline   Reply With Quote
Old 05-22-2021, 04:43 PM   #9
earhax
Human being with feelings
 
earhax's Avatar
 
Join Date: Nov 2015
Location: earth
Posts: 471
Default

Quote:
Originally Posted by Pet View Post
Maybe this one is useful (FREE as in free beer ): pkColorPicker.

This gives you the values of colors by clicking on the color you see on your monitor. In decimal (this one is used by SWS color sets), Hexadecimal and RGB decimal. You can for instance type in the RGB values and get the hex result.

I just thought I'd mention it here...

Quote from the homepage http://www.color-picker.de/en/features/color-numbers:
Anyone know if there's a version of this type of color picker for macOS (one that will give the decimal value for sampled color or hexadecimal input)?
earhax is offline   Reply With Quote
Old 05-22-2021, 06:00 PM   #10
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Quote:
Originally Posted by earhax View Post
Anyone know if there's a version of this type of color picker for macOS (one that will give the decimal value for sampled color or hexadecimal input)?
Any calculator with a base conversion feature. Or a REPL of common scripting languages (eg. Ruby/Python/Lua). For example, converting the color #c0ffee to decimal from within REAPER using iReaScript:


Last edited by cfillion; 05-22-2021 at 06:11 PM.
cfillion is offline   Reply With Quote
Old 05-22-2021, 07:51 PM   #11
earhax
Human being with feelings
 
earhax's Avatar
 
Join Date: Nov 2015
Location: earth
Posts: 471
Default

Quote:
Originally Posted by cfillion View Post
Any calculator with a base conversion feature. Or a REPL of common scripting languages (eg. Ruby/Python/Lua). For example, converting the color #c0ffee to decimal from within REAPER using iReaScript:

Oh man. I wish I had learned about this A LOT sooner. To think of all the time I could've saved if I had known it existed! lol!

Thank you!

Edit: don't have time to set it up right now to check. do you know if it can also do the conversion the other way (decimal to hex)?

also, too bad that c0ffee turned out to be sort of a seafoam green color haha.

Last edited by earhax; 05-22-2021 at 08:08 PM.
earhax is offline   Reply With Quote
Old 05-23-2021, 07:15 AM   #12
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

I usually use irb (Ruby's REPL shell) for this: "12648430.to_s 16". It should be pre-installed on macOS. In Lua it's a bit more typing: "('%x'):format(12648430)".
cfillion is offline   Reply With Quote
Old 05-23-2021, 08:41 AM   #13
earhax
Human being with feelings
 
earhax's Avatar
 
Join Date: Nov 2015
Location: earth
Posts: 471
Default

Quote:
Originally Posted by cfillion View Post
I usually use irb (Ruby's REPL shell) for this: "12648430.to_s 16". It should be pre-installed on macOS. In Lua it's a bit more typing: "('%x'):format(12648430)".
Once again, something I wish I had learned a long time ago, and that will save me tons of time in the future. Thanks again!
earhax is offline   Reply With Quote
Old 05-23-2021, 12:11 PM   #14
jrk
Human being with feelings
 
Join Date: Aug 2015
Posts: 2,969
Default

Quote:
Originally Posted by Lawrence View Post
Say I have 10 things that need to be cross-referenced against an unknown number of other things. I know I can check each of the ten things one at a time against a loop iteration of all of the other things, but that sounds slow before I even try it, making multiple iterations.

Generally speaking, what's the best way to approach something like that planning wise, that would be more efficient? Should I throw the larger array into a string and then maybe do a RegEx compare or something against the target to speed that up?

If you're having to do this a lot, you'd build a search tree. Perhaps.
__________________
it's meant to sound like that...
jrk is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 12:04 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.