Old 01-06-2017, 06:30 PM   #1
Lawrence
Human being with feelings
 
Join Date: Mar 2007
Posts: 20,921
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?
__________________
"I, Bozo The Clown, do solemly swear to uphold the Consti.. consti... uh, how do you pronounce that again?".
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: 19,694
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.
__________________
Choosing to play the simpler part instead of the fancier one, takes a lot of courage
karbomusic is online now   Reply With Quote
Old 01-06-2017, 06:50 PM   #3
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: The vast, frozen wasteland of western Canadia.
Posts: 4,239
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
__________________
Currently working away from home; don't expect timely responses from me.
Default 5.0 Nitpicky Edition / GUI tutorial for Lua / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate / ReaPack
Lokasenna is offline   Reply With Quote
Old 01-07-2017, 02:56 AM   #4
Lawrence
Human being with feelings
 
Join Date: Mar 2007
Posts: 20,921
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.
__________________
"I, Bozo The Clown, do solemly swear to uphold the Consti.. consti... uh, how do you pronounce that again?".
Lawrence is offline   Reply With Quote
Old 01-07-2017, 03:09 AM   #5
Lawrence
Human being with feelings
 
Join Date: Mar 2007
Posts: 20,921
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.
__________________
"I, Bozo The Clown, do solemly swear to uphold the Consti.. consti... uh, how do you pronounce that again?".
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: The vast, frozen wasteland of western Canadia.
Posts: 4,239
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.
__________________
Currently working away from home; don't expect timely responses from me.
Default 5.0 Nitpicky Edition / GUI tutorial for Lua / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate / ReaPack
Lokasenna is offline   Reply With Quote
Old 01-08-2017, 06:07 AM   #7
Lawrence
Human being with feelings
 
Join Date: Mar 2007
Posts: 20,921
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;
    }
__________________
"I, Bozo The Clown, do solemly swear to uphold the Consti.. consti... uh, how do you pronounce that again?".

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: 918
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
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:12 PM.


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