webkit-linear-gradient :: Setting Relative Colors With Javascript

My goal is to retain the same distance between the colors by any given color.

So in that specific case I want to set the end color to:

#bb0303

and get

#e13c3b

without the need to set it statically off-course 🙂

(or vice versa)

so iow…

I need the mathematical equation to set one color and get the other one RELATIVELY to that color.

So the start given color #bb0303 would set #e13c3b at the end color.

(OR vice versa)

the end given color #e13c3b would set #bb0303 at the the start color.

Here is my code:

function setRelativeColor(myElement,refColor)
{
    myElement.style.background='-webkit-linear-gradient(270deg,#e13c3b 0%,#'+refColor+' 100%)';
}


const myDiv=document.createElement('div');

myDiv.style.width='300px';
myDiv.style.height='80px';

setRelativeColor(myDiv,'bb0303');

document.body.appendChild(myDiv);