The origin for these logic came from this repository: https://github.com/material-foundation/material-color-utilities.
This library contains algorithm to generate HCT(Hue, Chroma, Tone) colors. We can use this library to generate colors of different tone for a given color.