测试HSL颜色,理想情况下避免红色与绿色相邻(常见的色盲类型) [英] Testing HSL colours, ideally avoiding Red adjacent to Green (common colour-blindness type)

查看:192
本文介绍了测试HSL颜色,理想情况下避免红色与绿色相邻(常见的色盲类型)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

受到此页面上的最佳答案的启发,我写了一篇python程序生成N种不同的十六进制颜色.不同之处在于,原始作者将使用math.random()生成饱和度和亮度,而我使用的是三角函数,我可以保证始终提供唯一的色相,饱和度和亮度.亮度,同时还提供了我可以可以将黄色编程为比蓝色更暗的优点,从而可以更好地与白色背景形成对比.黑色文字(我需要它做什么).
我实际使用的代码还会通过RGB将HSL代码转换为HEX代码,以便我可以创建Web颜色代码.
我的问题是:-

Inspired by the top answer on this page I wrote a python program to generate N distinct HEX colours. The difference is that the original author would generate saturation and luminance by using math.random(), whereas I use a trigonometric function which I can guarantee will always give a unique hue, saturation & luminance, whilst also providing the advantage that I could program yellow to appear darker than blue, allowing better contrast against white background & black text (what I need it for).
The code I actually use also converts HSL to HEX codes, via RGB, so that I can create web colour codes.
My questions are:-

  1. 使用此模型,我如何保证红色不会出现在绿色旁边?
  2. 生成颜色代码很容易,但是我如何轻松看到它们呢?目前,我必须将相当大的文件上传到生成pdf/png/eps的服务器上,然后才能再次下载.
  3. 我可以通过测试来做到这一点,但是有没有人有使用HSL模型生成颜色的经验,该颜色在白色背景上具有最大的对比度,而白色背景上是黑色文本?蓝色可能会使黑色文本变得很难看清,而黄色有时会很难与白色相对.
  1. Using this model, how can I guarantee that red won't appear next to green??
  2. Generating the colour codes is easy enough, but how can I easily see them? I currently have to upload quite a large file to a server which generates pdf / png / eps before downloading it again.
  3. I can do this with testing, but does anyone have experience with using the HSL model to generate colours whose contrast is maximised against a white background with black text on top of the colours? The blues can make the black text really hard to see and the yellows sometimes hard to see against the white...

ps.这实际上不是我使用的代码,但这一切都从这里开始.完整的python脚本可在此处获得.
干杯,
亚历克斯

ps. This isn't actually the code I use, but it all starts here. The full python script is available here.
Cheers,
Alex

>>> class generate_HSL_colours():
...    def __init__( self, N, shift=0, degrees=360 ):
...        dict.__init__(self)
...        self.N = N
...        hues = [ angle for angle in xrange( shift, shift+degrees , degrees / N ) ] # Default hues from 0 --> 360
...        self.colours = generate_HSL_colours()
...    def generate_HSL_colours(self,angles):
...        colours = []
...        colour = HSLColour()
...        for angle in angles:
...            cos_value = math.cos( angle * math.pi / 360 ) ## <== in radians. Degrees == cos( angle/2 ) ; so cos_value goes from 1 to -1, and 0 <= angle < 180.
...            ## Could use sin_value too...
...            saturation = 90 - (cos_value * 10)  ## Saturation from 80 --> 100
...            luminance = 50 + (cos_value * 10)   ## Lightness from 60 --> 40
...            HSLColour.hue = hue
...            HSLColour.saturation = saturation
...            HSLColour.luminance = luminance
...            colours.append( HSLColour )
...        return colours
...
...    def __iter__(self):  ## I put this in to answer a different question (see below).
...      for colour in self.colours:
...          yield repr(colour.hue, colour.saturation, colour.lightness)
... 

__iter__函数编写为问题的答案此处

__iter__ function written as an answer for question here

推荐答案

  1. 嗯?测试,如果您得到的红色接近绿色,您会得到另一种颜色吗?我不确定这里的问题是什么.

  1. Eh? Test, and if you get red close to green you get another color? I'm not sure what the question is here.

您可以生成一个PNG并在本地将其打开.那可能是最简单的. PIL是一个很好的库. http://pypi.python.org/pypi/Pillow/

You could generate a PNG and open it locally. Thats' probably the easiest. PIL is a good library for that. http://pypi.python.org/pypi/Pillow/

不,对不起,我对此一无所知.

Nope, sorry, I don't know anything about that.

这篇关于测试HSL颜色,理想情况下避免红色与绿色相邻(常见的色盲类型)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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