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;
}
![这里写图片描述]
颜色样式
(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];
}
相关文章推荐
- iOS(学习5) 布局
- iOS 手势(下)
- iOS / OXS LeanCloud云存储方案简单测试记录
- iOS(学习7) 模态推送
- IOS基础之 (十) 内存管理
- iOS 数据存储的常用方式
- ios-基础用法之【6】-self. 与 下划线的区别
- iOS 手势(上)
- iOS下86版五笔输入法练习程序(作为备忘,最基本功能的演示demo,版本:0.99版)
- iOS开发中 [[NSBundle mainBundle] pathForResource: ofType:]路径为空的问题
- iOS 加密(MD5 ,AES,BASE64)
- ios-基础用法之【5】-define和const
- iOS 分类和继承
- iOS:KVO/KVC 的概述与使用
- iOS开发常用基础框架(你了解的ios只是冰山一角)
- iOS程序启动原理
- ios开发计算缓存的大小以及清除
- 关于c++浮点数的数字个数setprecision(n)与setiosflags(ios::fixed)
- iOS的23种设计模式简介
- iOS(学习8) 触摸