I want to generate a list of color specifications in the form of (r, g, b) tuples, that span the entire color spectrum with as many entries as I want. So for 5 entries I would want something like:
Of course, if there are more entries than combination of 0 and 1 it should turn to use fractions, etc. What would be the best way to do this?
Using random() function to generate random colors To begin, import the random function in Python to obtain a random color. The variable r stands for red, g stands for green, and b stands for blue. We already know that the RGB format contains an integer value ranging from 0 to 255.
color() function draws a color on the image using current fill color, starting at specified position & method.
Use the HSV/HSB/HSL color space (three names for more or less the same thing). Generate N tuples equally spread in hue space, then just convert them to RGB.
Sample code:
import colorsys N = 5 HSV_tuples = [(x*1.0/N, 0.5, 0.5) for x in range(N)] RGB_tuples = map(lambda x: colorsys.hsv_to_rgb(*x), HSV_tuples)
Color palettes are interesting. Did you know that the same brightness of, say, green, is perceived more intensely than, say, red? Have a look at http://poynton.ca/PDFs/ColorFAQ.pdf. If you would like to use preconfigured palettes, have a look at seaborn's palettes:
import seaborn as sns
palette = sns.color_palette(None, 3)
Generates 3 colors from the current palette.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With