colors - Python: colorsys.hls_to_rgb returning odd values -
i trying complimentary colors in rgb format. following guidance here, performing following steps:
- generate random hsl color
- create complimentary hsl doing
1-h
of previous color, keepings
,l
same. - 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
Post a Comment