March 28, 2024, 11:08:50 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Shades of Hex colours

Started by Brian, June 05, 2023, 09:34:33 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brian

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

Egil

June 05, 2023, 02:16:30 PM #1 Last Edit: June 05, 2023, 02:20:57 PM by Egil
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
Support Amateur Radio  -  Have a ham  for dinner!

Egil

Support Amateur Radio  -  Have a ham  for dinner!

billhsln

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
When all else fails, get a bigger hammer.

Brian

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

billhsln

When all else fails, get a bigger hammer.

Brian

June 08, 2023, 10:50:02 AM #6 Last Edit: June 10, 2023, 05:16:24 AM by Brian
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

Brian

June 09, 2023, 05:47:19 AM #7 Last Edit: June 10, 2023, 05:17:05 AM by Brian
Updated - download from previous post. Added an icon, neater interface, few minor tweaks

Brian

Edit: Updated again!

Brian

June 12, 2023, 04:40:10 AM #8 Last Edit: June 13, 2023, 05:01:18 AM by Brian
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 . . .