Solved Adjust Luminosity via VBA of any color value to it's lightest shade (1 Viewer)

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 02:48
Joined
Feb 28, 2001
Messages
19,633

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 08:48
Joined
Sep 12, 2006
Messages
14,465

Hmm. I sort of get the impression that HSL IS "the same" as RGB - ie - you get there in a different way, but you end up with the same decimal representation under both mechanisms.


[edit - What I originally meant was "do you still get to the same decimal colour number" - ie do the values of RGB component always correspond to a particular HSL value, and I am sure they do. However, there must be an extra hidden (negative?) component to derive the HSL values, since eg, Black Hex000000 is HSL 160,0,0, and white is HSL 160,0,240. I note that 160 and 240 are both multiples of 16.

[edit - incidentally, the links on the URL you posted weren't working, but I just realised I could watch the embedded video, and that actually helped a lot, seeing how one colour was on the same "horizontal" row as another, while the other colour was on the same "vertical" column, so that each colour was "identical" to the other, within the individual palette. (which is probably confusing terminologies - I will consult wiki when I get a moment!)
 
Last edited:

isladogs

CID VIP
Local time
Today, 08:48
Joined
Jan 14, 2017
Messages
14,739
Still not clear what the V is in HSV.
 

Mike Krailo

Active member
Local time
Today, 03:48
Joined
Mar 28, 2020
Messages
245
That was an eye opening explanation on how to harmonize colors Doc_Man.
 

Mike Krailo

Active member
Local time
Today, 03:48
Joined
Mar 28, 2020
Messages
245
Still not clear what the V is in HSV.
H is Hue, S is Saturation, and V is the Value of Brightness. Why they didn't pick B or L? I have no idea, but it's essentially the same key thing that I would like to manipulate keeping the value for H & S constant.

For now, I'm going back to using a table of values to link to and do it that way. The issue now is I cannot import the csv file of color pallets. I keep getting the following error.

1616986885057.png
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 08:48
Joined
Sep 12, 2006
Messages
14,465
H is Hue, S is Saturation, and V is the Value of Brightness. Why they didn't pick B or L? I have no idea, but it's essentially the same key thing that I would like to manipulate keeping the value for H & S constant.

For now, I'm going back to using a table of values to link to and do it that way. The issue now is I cannot import the csv file of color pallets. I keep getting the following error.

View attachment 90371

On the link that @The_Doc_Man posted it says HSL and HSB are the same L=Luminosity, and B=Brightness. Your V is the same. I imagine it's specifically not B for colour handling, because we already have B in RGB, and you don't want another B (in the same way as n is minutes in date formats)
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 02:48
Joined
Feb 28, 2001
Messages
19,633
CMYK is specifically used for printing because colors on a video screen are additive but colors of ink are subtractive.

Red + Green on video = Yellow

Cyan + Yellow on print = Green
 

Mike Krailo

Active member
Local time
Today, 03:48
Joined
Mar 28, 2020
Messages
245
OK, I have a few formula's now that seem to be working when I step through the code but I'm not used to working with Type's so I'm a little confused how these are used or how to get the values after running the functions. I getting the Oops messages again when trying to post code so instead I just have it in a text file. What a pain.
 

Attachments

  • ColorFormulas.zip
    1.4 KB · Views: 15

arnelgp

error reading drive A:
Local time
Today, 15:48
Joined
May 7, 2009
Messages
12,315
you declare a variable As ColorProperties/Variant
then you call RGBtoHSL with your RGB value, it will be converted to HSL.

dim varHSL As Variant
varSHL = RGBtoHSL(theLongRGBValue)

if it is in Hex:

varSHL = RGBtoHSL(HexToDec(theHexString))


Note that you cannot call HSLtoRGB() function when your local ColorProperties has
no value as you will have division by zero error there.


Edit: add error handler.
 

Mike Krailo

Active member
Local time
Today, 03:48
Joined
Mar 28, 2020
Messages
245
Arnelgp, I did that and now I have a variable varHSL, but there is nothing in it! That's what I don't understand. If I do something like this it just gives me 0, 0, 0. Nevermind, I used the wrong elements in the code. I was expecting all six elements to be present. It does work for Hue, Sat & Lum just like I wanted. Thanks for your help.

Code:
Public Sub colortest()
   Dim varHSL As ColorProperties
   varHSL = RGBtoHSL(9902253)
   Debug.Print varHSL.red & ", " & varHSL.green & ", " & varHSL.blue
End Sub
 

Users who are viewing this thread

Top Bottom