I am trying to use 4 UISliders to change the values of the CMYK and then display the color in a view but I have tried with different formulas and still I don't get the right values, So I found this answer in stack overflow but is for android (Java), but I don't get the code, this is what I have written:
let cyan = Float( 1 - (cyanSlider.value / 255))
let magenta = Float(1 - (magentaSlider.value / 255))
let yellow = Float(1 - (yellowSlider.value / 255))
cyanValue.text = String(stringInterpolationSegment: cyan)
magentaValue.text = String(stringInterpolationSegment: magenta)
yellowValue.text = String(stringInterpolationSegment: yellow)
And in the answer is:
int r,g,b,c,m,y,k;
int computedC,computedM,computedY;
int minCMY;
if(r==0 && g==0 && b==0) return {0,0,0,1}
computedC = 1 - (r/255);
computedM = 1 - (g/255);
computedY = 1 - (b/255);
minCMY = Math.min(computedC,Math.min(computedM,computedY));
computedC = (computedC - minCMY) / (1 - minCMY) ;
computedM = (computedM - minCMY) / (1 - minCMY) ;
computedY = (computedY - minCMY) / (1 - minCMY) ;
return {computedC,computedM,computedY,minCMY};
I don't get this part of the code:
minCMY = Math.min(computedC,Math.min(computedM,computedY));
How would I write this on swift? or maybe objective -c and I will try to understand the objective-c code, but preferably swift please.
Thanks, I am very new to swift :(