Convert a Single HEX Coloration Code right into a Monochrome Coloration Palette with Python | by Dario Radečić | Sep, 2024

Spoiler: It’s more durable than you suppose.

Article thumbnail (picture by writer)

Colours are laborious, particularly in the event you don’t have a watch for design.

Most of us tech professionals don’t. The upside is that Python can do a lot of the heavy lifting for you. It could actually generate a complete monochromatic colour palette that’ll look beautiful on any stacked chart.

The draw back is that getting there requires a good bit of coding. You need to write customized capabilities to transform a colour from HEX to HSL and vice versa, and determine if the beginning colour is just too vivid, in addition to how a lot lighter every subsequent colour ought to be.

Including insult to harm, I haven’t discovered a single totally working Python library able to engaging in this process.

That’s the place this text chimes in.

Should you’re a subscriber to my Substack, you may skip the studying and obtain the pocket book as an alternative.

Let’s shortly cowl three colour codecs you’ll want to know:

  • HEX — A six-digit code usually utilized in net growth and graphic design. The colour code begins with a #, adopted by six hexadecimal digits. Pairs…