您的位置:首页 > 移动开发 > IOS开发

iOS 图像之生成多彩颜色

2016-02-22 22:49 507 查看
得到随机25种颜色,省了四处设置颜色问题,一个函数解决。

![这里写图片描述]

颜色样式

(http://img.blog.csdn.net/20160222224218285)

float r ,g ,b;

for (int i = 0; i<25; i++) {

r = [self getRGBColor:i Index:0];

g = [self getRGBColor:i Index:1];

b = [self getRGBColor:i Index:2];

UIColor *color = [UIColor colorWithRed:r green:g blue:b alpha:1];

}

-(float)getRGBColor:(float)h Index:(int)index;

{

h = h/15.0;

float temp1,

temp2;

float temp[3];

int i;

float s = 1.0;

float l= 0.75;

if(l < 0.5)

temp2 = l * (1.0 + s);

else

temp2 = l + s - l * s;

temp1 = 2.0 * l - temp2;

// Compute intermediate values based on hue
temp[0] = h + 1.0 / 3.0;
temp[1] = h;
temp[2] = h - 1.0 / 3.0;

for(i = 0; i < 3; ++i) {

// Adjust the range
if(temp[i] < 0.0)
temp[i] += 1.0;
if(temp[i] > 1.0)
temp[i] -= 1.0;

if(6.0 * temp[i] < 1.0)
temp[i] = temp1 + (temp2 - temp1) * 6.0 * temp[i];
else {
if(2.0 * temp[i] < 1.0)
temp[i] = temp2;
else {
if(3.0 * temp[i] < 2.0)
temp[i] = temp1 + (temp2 - temp1) * ((2.0 / 3.0) - temp[i]) * 6.0;
else
temp[i] = temp1;
}
}
}
return temp[index];


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: