iOS 图像之生成多彩颜色

得到随机25种颜色,省了四处设置颜色问题,一个函数解决。
![这里写图片描述]
颜色样式
(https://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];

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值