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,269
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-07-2017, 02:56 AM   #3
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   #4
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   #5
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   #6
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 05-23-2021, 12:11 PM   #7
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
Old 01-06-2017, 06:50 PM   #8
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
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 09:05 PM.


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