|
|
|
01-06-2017, 06:30 PM
|
#1
|
Human being with feelings
Join Date: Mar 2007
Posts: 21,551
|
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?
|
|
|
01-06-2017, 06:44 PM
|
#2
|
Human being with feelings
Join Date: May 2009
Posts: 29,269
|
Quote:
Originally Posted by Lawrence
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.
|
|
|
01-07-2017, 02:56 AM
|
#3
|
Human being with feelings
Join Date: Mar 2007
Posts: 21,551
|
Quote:
Originally Posted by karbomusic
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
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.
|
|
|
01-07-2017, 03:09 AM
|
#4
|
Human being with feelings
Join Date: Mar 2007
Posts: 21,551
|
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.
|
|
|
01-07-2017, 08:02 AM
|
#5
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
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.
|
|
|
01-08-2017, 06:07 AM
|
#6
|
Human being with feelings
Join Date: Mar 2007
Posts: 21,551
|
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.
|
|
|
05-23-2021, 12:11 PM
|
#7
|
Human being with feelings
Join Date: Aug 2015
Posts: 2,969
|
Quote:
Originally Posted by Lawrence
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...
|
|
|
01-06-2017, 06:50 PM
|
#8
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
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
|
|
|
Thread Tools |
|
Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 09:05 PM.
|