按颜色排序 [英] Sorting by Color

查看:258
本文介绍了按颜色排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个长列表(1000+)的十六进制颜色分为一般的颜色类别(红色,橙色,蓝色等)。当我显示每个类别中的颜色列表,我需要按照阴影的顺序显示它们。即最初是浅红色,最后是深红色。

I have a long list (1000+) of hex colors broken up in general color categories (Red, Orange, Blue, etc). When I show the list of colors in each category I need to show them in order of shade. i.e. light red first and dark red last.

算法是什么? (Google搜寻失败了)

What would the algorithm be to do this? (googling has failed me)

推荐答案

将RGB颜色转换为 HSV或HSL 缩放,然后按Value或Lightness排序。亮度可能更好,因为它会捕获褪色的颜色更好,如粉红色 - >红 - >深红色。

Convert the colors from RGB to a HSV or HSL scale and then sort them by Value or Lightness. Lightness might work better as it would capture the "faded" colors better, such as pink->red->dark red.

RGB到HSV色彩空间转换

这篇关于按颜色排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆