IonicWind Software

IWBasic => General Questions => Topic started by: Brian on June 05, 2023, 09:34:33 AM

Title: Shades of Hex colours
Post by: Brian on June 05, 2023, 09:34:33 AM
I wanted to get a 20% shade of a Hex colour - 0x0018A8 - and found this useful site: https://www.hexcolortool.com/#ed1d23

Just set your base Hex colour, and then press Lighten or Darken by whatever percentage you require. Pretty nifty!

Although, if anyone knows an algorithm to do just the same, I would be happy to see it. Using the website means I have to calculate the percentages for my known colours. It would be easier to do it on the fly, which would mean I could alter my base colour, and have the percentage automatically calculated in my program

Brian
Title: Re: Shades of Hex colours
Post by: Egil on June 05, 2023, 02:16:30 PM
You always come up with tricky problems Brian! How do you do it? ;D  ;D

This page has example code in C# and Phyton. Browse far down the page.
Never done it myself, but it should be possible to convert to IWB.


Good Luck!

Egil
Title: Re: Shades of Hex colours
Post by: Egil on June 05, 2023, 02:18:17 PM
Forgot the link:

https://stackoverflow.com/questions/9280902/what-algorithm-is-behind-the-gimps-color-to-alpha-feature/14915403#14915403 (https://stackoverflow.com/questions/9280902/what-algorithm-is-behind-the-gimps-color-to-alpha-feature/14915403#14915403)
Title: Re: Shades of Hex colours
Post by: billhsln on June 05, 2023, 10:48:20 PM
I think this might kind of do what you are looking for it to do.  Not exactly, but close and the code is fairly simple.  You will just need to convert the hex to Red, Green, Blue and then do the calculation.

Bill
Title: Re: Shades of Hex colours
Post by: Brian on June 06, 2023, 05:50:07 AM
Bill,

That is pretty much spot on with the calculations. I have taken the liberty of modifying your program to show the Hex values from the RGB calculations, if that is ok?

Brian
Title: Re: Shades of Hex colours
Post by: billhsln on June 07, 2023, 09:04:51 PM
Glad you can use it.

Bill
Title: Re: Shades of Hex colours
Post by: Brian on June 08, 2023, 10:50:02 AM
Right, after some modifications, I've now re-posted Bill's Darker or Lighter Colours program. Swapped the whole lot over to a Dialog window, which makes it easier to tab between the RGB edit boxes, and have added some features, so the user can copy any of the hex values

Program deleted from previous post

Edit: Added an icon, and some very minor tweaks

Brian
Title: Re: Shades of Hex colours
Post by: Brian on June 09, 2023, 05:47:19 AM
Updated - download from previous post. Added an icon, neater interface, few minor tweaks

Brian

Edit: Updated again!
Title: Re: Shades of Hex colours
Post by: Brian on June 12, 2023, 04:40:10 AM
Okay,

This is definitely the last update of this program! Main addition is the ability to swap the RGB values of the 10 shaded boxes to HEX, and vice-versa. Also added the percentage that a box is lighter or darker

Much better, I think, and thanks to Bill Haesslein for his swap code

Brian

Edit: Couldn't resist a couple of tweaks! Updated again . . .