colors - Python: colorsys.hls_to_rgb returning odd values -


i trying complimentary colors in rgb format. following guidance here, performing following steps:

  1. generate random hsl color
  2. create complimentary hsl doing 1-h of previous color, keeping s , l same.
  3. convert both colors rgb

my code follows:

bg_color_hls = (random.random(), random.random(), random.random()) fg_color_hls = (1-bg_color_hls[0], bg_color_hls[1], bg_color_hls[2]) print bg_color_hls print fg_color_hls print colorsys.hls_to_rgb(*bg_color_hls) print colorsys.hls_to_rgb(*fg_color_hls) 

however, printing following:

(0.5536645842193463, 0.489454360526385, 0.47696160643815266) (0.4463354157806537, 0.489454360526385, 0.47696160643815266) (0.2560034224515616, 0.5725687282723873, 0.7229052986012084) (0.2560034224515616, 0.7229052986012084, 0.5725687282723875) 

note how r value same, , switches g , b.

this not how complimentary colors work. problem?

that's not how generate complimentary hue.

you need add 0.5, take range [0, 1).

fg_color_hls = ((bg_color_hls[0] + 0.5) % 1.0, bg_color_hls[1], bg_color_hls[2]) 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -