0
$\begingroup$

I'm trying to write an algorithm to convert RGB to RGBW, and a problem I'm running in is that my white value should, depending on the luminance, go from:

255-------------------->0

and it's currently doing

255-------------------->120

How would I divide by 120, but proportionally to how close I am to 120, in the simplest way possible?

P.S. I didn't learn maths in English, so sorry if I haven't used the correct terms :/

$\endgroup$
0
$\begingroup$

So you have $255\geq x\geq 120$. Subtract $120$ and you'll get: $$135\geq x-120\geq 0$$ multiply with $\frac{255}{135}$ to obtain: $$255\geq\frac{255}{135}(x-120)\geq 0$$ Now it's in the range that you want.

So to get the number between $255$ and $0$, subtract $120$ and then multiply by $\dfrac{255}{135}$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.