Generating all possible rgb colors

后端 未结 2 1681
情歌与酒
情歌与酒 2020-12-22 04:38

It seems like it\'d be much simpler than it is, but what can be done to generate all 16,777,255 rgb colors with python?

相关标签:
2条回答
  • 2020-12-22 05:00

    8-bit RGB values are 3-tuples of numbers 0..255. You can generate them all conveniently using the cartesian product function from itertools.

    itertools.product(xrange(256), repeat=3)
    
    0 讨论(0)
  • 2020-12-22 05:06

    Colors are usually represented as hexadecimal numbers which are actually just integers. So a simple loop from 0 to 16,777,215 (0xFFFFFF) would be enough to generate all 24 bit RGB colors.

    In python 2.x, you can do:

    allcolors = range(0xFFFFFF+1):
    
    0 讨论(0)
提交回复
热议问题