How can I make a method that takes in a float from 0-50, and gives out a green color with uniform intensity?
So if the input value is 0, the color is black:
[UIColor colorWithRed:0 green:0 blue:0];
and if the input value is 50, the color is the max green color:
[UIColor colorWithRed:0 green:255.0/255.0 blue:0];
And so if the input factor is somewhere in the middle, then the color should be somewhere in the middle. So going from 0-50, it should go from the darkest green to the lightest green. Should be simple but I’m not sure what I’m missing:
//factor is a float from 0-50
UIColor *greenColor = [UIColor colorWithRed:0 green:factor/255.0 blue:0 alpha:1.0];
This code generates a green color, but doesn’t fluctuate much, so you only see about one shade of green.
You need to scale the RGB max value (255) against your own max value (50). And all you need is fairly simple math:
where
xis the intesity on the scale from 0 to 50. So: