For a few days now, I have been trying to find a way in which I can calculate the intensity of each component of an RGB color based on two lengths. To exemplify:

Let us say I am trying to measure the Red component of a color. The minimum length is 0 (which represents 255); the maximum length is 10 (which represents 0); the length I wish to measure is 10.

In so far, I have attempted to use the inverse proportion formula, but apparently it does not work well with zeros:

5/10 = 127.5/x (=) 10/5 = 127.5/x <- Inverse (=) x = 5 * 127.5/10 (=) x = 637.5/10 (=) x = 63.75 The, logically, correct answer is 0.

I have been looking for an alternative, but so far I have found nothing. I would be very thankful if someone could point out a formula I could use to calculate the color intensity.