Testing HSL colours, ideally avoiding Red adjacent to Green (common colour-blindness type)

自古美人都是妖i 提交于 2019-12-24 08:37:11

问题


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. 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. 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__ 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.

  2. 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/

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



来源:https://stackoverflow.com/questions/4642219/testing-hsl-colours-ideally-avoiding-red-adjacent-to-green-common-colour-blind

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!