Component to display Colour

How about posting your solution?

This may be overkill but I found a list of “web safe” colors here:

Then parsed the JSON format in Python. As noted on the page, there are duplicate color names in this list so I used only the first 16 colors and ignored the rest. There must be CSV or JSON formats with unique color names but I was too impatient to search further.


colors_2021Jan16a.gh (20.2 KB)
colors.json.txt (30.0 KB)

The Python could be ignored by internalizing the Color Name/Values data param.

The teal group uses a PVL component posted recently by @AndersDeleuran to initialize two Value List components:

  • ‘Colors’ in purple group has both names and color values.
  • ‘Color Names’ in white group has only names and does a lookup of the color value associated with the color name passed to the ‘M’ input of MIndex (Member Index).

Here is the Python code:

import json

json_colors = json.loads(JSON)

colors_A = []
for aColor in json_colors:
    rgb_A = []
    for rgb in aColor['rgb']:
        rgb_A.append(str(aColor['rgb'][rgb]))
    colors_A.append(aColor["name"]+'|'+','.join(rgb_A))

colors = colors_A
3 Likes