Function Repository Resource:

ColorSearch

Source Notebook

Search for colors containing a given string

Contributed by: Renan Soares Germano

ResourceFunction["ColorSearch"][str]

returns a list with the colors that contain the string str in their names.

ResourceFunction["ColorSearch"][str,rtype]

gives the result type specified by rtype.

Details and Options

This function uses the "Name" property of each Wolfram Language color Entity to perform the search.
The option IgnoreCase controls whether to make the search case sensitive. The default is False.
Possible values for rtype are the following:
"Entity"color Entity for each color in the search result
"RGB"RGBColor for each color in the search result
"Name"string with the name of each color in the search result
{rtype1,rtype2,}list with each value type in the specified order
AllAssociation of all rtype values for each color in the search result
ResourceFunction["ColorSearch"][str] is equivalent to ResourceFunction["ColorSearch"][str,"RGB"].

Examples

Basic Examples (9) 

Find all the colors related to the word "sun":

In[1]:=
ResourceFunction["ColorSearch"]["sun"]
Out[1]=

Find all the colors related to the word "nature":

In[2]:=
ResourceFunction["ColorSearch"]["nature"]
Out[2]=

See the names that matched the search term:

In[3]:=
ResourceFunction["ColorSearch"]["nature", "Name"]
Out[3]=

Find all the colors related to the word "love":

In[4]:=
ResourceFunction["ColorSearch"]["love"]
Out[4]=

Find all the colors related to the words "red" and "blue":

In[5]:=
ResourceFunction["ColorSearch"] /@ {"red", "blue"}
Out[5]=

Use the second argument to get an RGBColor for each color:

In[6]:=
ResourceFunction["ColorSearch"]["air", "RGB"]
Out[6]=

Get an Entity for each color:

In[7]:=
ResourceFunction["ColorSearch"]["sky", "Entity"]
Out[7]=

Get a String with the name of each color:

In[8]:=
ResourceFunction["ColorSearch"]["water", "Name"]
Out[8]=

Get a list of associations with all the values for each color:

In[9]:=
worldColors = ResourceFunction["ColorSearch"]["world", All]
Out[9]=
In[10]:=
DeleteDuplicates[Head /@ # & /@ worldColors]
Out[10]=

Get an RGBColor and a String with the name of each color:

In[11]:=
ResourceFunction["ColorSearch"]["bird", {"RGB", "Name"}]
Out[11]=

Scope (1) 

Use this function to find all the colors related to the nouns in a sentence:

In[12]:=
text = StringTake[ExampleData[{"Text", "DeclarationOfIndependence"}], 400]
Out[12]=
In[13]:=
nouns = TextCases[TextWords[text // ToLowerCase], "Noun"] // Flatten //
   DeleteDuplicates
Out[13]=
In[14]:=
MapThread[#1 -> #2 &, {nouns, ResourceFunction["ColorSearch"] /@ nouns}] // TableForm
Out[14]=

Options (2) 

IgnoreCase (2) 

By default, the IgnoreCase option is False:

In[15]:=
"IgnoreCase" /. Options[
ResourceFunction["ColorSearch"]]
Out[15]=

Setting IgnoreCase to True gives more results:

In[16]:=
ResourceFunction["ColorSearch"]["Green", IgnoreCase -> False]
Out[16]=
In[17]:=
ResourceFunction["ColorSearch"]["Green", IgnoreCase -> True]
Out[17]=

Possible Issues (1) 

Because of the great number of colors in the Wolfram Language, the function can take some time to perform the search:

In[18]:=
EntityValue["Color", "Entities"] // Length
Out[18]=

Neat Examples (1) 

Use the function to sort, in ascending order, a set of colors related to the words "orange", "purple" and "pink" according to their brightness:

In[19]:=
Block[
 {words, search, entities, rgbs, brightness, map},
 words = {"Orange", "Pink", "Purple"};
 search = (ResourceFunction["ColorSearch"][#, {"Entity", "RGB"}, IgnoreCase -> True] & /@ words) // Flatten[#, 1] &;
 entities = search[[All, 1]];
 rgbs = search[[All, 2]];
 brightness = EntityValue[entities, "Brightness"];
 map = MapThread[{#1, #2} &, {rgbs, brightness}];
 Sort[map, Last@#1 < Last@#2 &]
 ]
Out[19]=

Publisher

Wolfram Summer School

Version History

  • 1.0.0 – 16 September 2020

Source Metadata

Related Resources

License Information