|
|
|
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-06-2017, 06:50 PM
|
#3
|
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
|
|
|
01-07-2017, 02:56 AM
|
#4
|
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
|
#5
|
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
|
#6
|
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
|
#7
|
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.
|
|
|
06-09-2017, 04:46 AM
|
#8
|
Human being with feelings
Join Date: Nov 2015
Location: Germany
Posts: 1,016
|
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.
|
|
|
|
05-22-2021, 04:43 PM
|
#9
|
Human being with feelings
Join Date: Nov 2015
Location: earth
Posts: 472
|
Quote:
Originally Posted by Pet
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)?
|
|
|
05-22-2021, 06:00 PM
|
#10
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,968
|
Quote:
Originally Posted by earhax
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.
|
|
|
05-22-2021, 07:51 PM
|
#11
|
Human being with feelings
Join Date: Nov 2015
Location: earth
Posts: 472
|
Quote:
Originally Posted by cfillion
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.
|
|
|
05-23-2021, 07:15 AM
|
#12
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,968
|
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)".
|
|
|
05-23-2021, 08:41 AM
|
#13
|
Human being with feelings
Join Date: Nov 2015
Location: earth
Posts: 472
|
Quote:
Originally Posted by cfillion
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!
|
|
|
05-23-2021, 12:11 PM
|
#14
|
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...
|
|
|
Thread Tools |
|
Display Modes |
Linear 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 12:56 AM.
|