对颜色进行排序 (Objective-C)
我正在做这样的事情:
- (NSArray*)colors {
float divisor = .3333;
NSMutableArray *retVal = [NSMutableArray array];
for (float one=0; one <= 1.0f; one += divisor) {
for (float two = 0; two <= 1.0f; two += divisor) {
for (float three = 0; three <= 1.0f; three += divisor) {
UIColor *color = [UIColor colorWithRed:one green:two blue:three alpha:.5];
// also bad
// UIColor *color = [UIColor colorWithHue:one saturation:two brightness:three alpha:.5];
[retVal addObject:color];
}
}
}
return retVal;
}
正如我所怀疑的,颜色显示得非常混乱(在眼睛看来)。红色不与红色搭配,紫色不与紫色搭配,等等。
是否没有简单的方法来创建不同颜色的列表,并根据人类标准(例如“看起来是蓝色的”)很好地分组?
I'm doing this sort of thing:
- (NSArray*)colors {
float divisor = .3333;
NSMutableArray *retVal = [NSMutableArray array];
for (float one=0; one <= 1.0f; one += divisor) {
for (float two = 0; two <= 1.0f; two += divisor) {
for (float three = 0; three <= 1.0f; three += divisor) {
UIColor *color = [UIColor colorWithRed:one green:two blue:three alpha:.5];
// also bad
// UIColor *color = [UIColor colorWithHue:one saturation:two brightness:three alpha:.5];
[retVal addObject:color];
}
}
}
return retVal;
}
and, as I suspected, the colors come out horribly out of order (to the eye). The reds are not with the reds, purples not with the purples, etc.
Is there no easy way to create a list of diverse colors, nicely grouped according to human criteria like, "that looks blue?"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这非常有效。如果你有很多重复的颜色,这对你没有帮助。请参阅下文:
您可以在 iOS 4.x 中像这样访问组件 (HSBA):
为了避免重复颜色: 您可以将元素放入 NSMutableDictionary 中,并键入某些内容就像它们的色调-饱和度-亮度(每个四舍五入到最接近的0.10)...然后你从中得到数组,然后排序。
This worked quite well. It will NOT help the fact that you have a lot of repeated colors. See below:
You can access the components (HSBA) like this in iOS 4.x:
To avoid repeating colors: you can put the elements in an NSMutableDictionary, keyed on something like their hue-saturation-brightness (each rounded to the nearest .10)... then you get the array from THAT, and then sort.
我认为使用 [UIColor colorWithHue:saturation: Brightness: alpha:] 是最好的选择。如果您固定饱和度、亮度和 Alpha,并仅使用色调,您将按顺序获得所有颜色。
请查看HSB wiki了解更多信息。
I think using [UIColor colorWithHue:saturation: brightness: alpha:] is your best bet. If you fix saturation, brightness and alpha and just use Hue you'll get all the colours in order.
Check out the wiki for HSB for more information.