Explore the latest version of An Elementary Introduction to the Wolfram Language »
7Colors and Styles
The Wolfram Language doesnt just handle things like numbers. It also for example handles things like colors. It lets you refer to common colors by their names.
Red represents the color red:
In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
You can do operations on colors. ColorNegate negates a color, giving the complementary color. Blend blends a list of colors together.
Negating the color yellow gives blue:
In[3]:=
Click for copyable input
Out[3]=
In[4]:=
Click for copyable input
Out[4]=
This gives maximum red, with no green or blue:
In[5]:=
Click for copyable input
Out[5]=
Maximum red and green gives yellow:
In[6]:=
Click for copyable input
Out[6]=
This gives a table of colors with maximum red and varying levels of green:
In[7]:=
Click for copyable input
Out[7]=
A hue of 0.5 corresponds to cyan:
In[8]:=
Click for copyable input
Out[8]=
In[9]:=
Click for copyable input
Out[9]=
Sometimes you may want to just pick a random color. RandomColor lets you do this. When you say RandomInteger[10], youre asking to generate a random integer up to 10. But for a random color you dont have to specify a range, so you can just write RandomColor[]not giving any explicit input to the function.
Generate a random color:
In[10]:=
Click for copyable input
Out[10]=
Make a table of 30 random colors:
In[11]:=
Click for copyable input
Out[11]=
Blending together lots of random colors usually gives something muddy:
In[12]:=
Click for copyable input
Out[12]=
This gives the number 1000, styled in red:
In[13]:=
Click for copyable input
Out[13]=
Here are 30 random integers, styled in random colors:
In[14]:=
Click for copyable input
Out[14]=
Show x styled in 30-point type:
In[15]:=
Click for copyable input
Out[15]=
This styles the number 100 in a sequence of different sizes:
In[16]:=
Click for copyable input
Out[16]=
You can combine color and size styling; heres x in 25 random colors and sizes:
In[17]:=
Click for copyable input
Out[17]=
Red, Green, Blue, Yellow, Orange, Pink, Purple, ... colors
RGBColor[0.4,0.7,0.3] red, green, blue color
Hue[0.8] color specified by hue
RandomColor[ ] randomly chosen color
ColorNegate[Red] negate a color (complement)
Blend[{Red,Blue}] blend a list of colors
Style[x,Red] style with a color
Style[x,20] style with a size
Style[x,20,Red] style with a size and color
7.1Make a list of red, yellow and green. »
Expected output:
Out[]=
Expected output:
Out[]=
7.3Compute the negation of the color orange. »
Expected output:
Out[]=
7.4Make a list of colors with hues varying from 0 to 1 in steps of 0.02. »
Expected output:
Out[]=
7.5Make a list of colors with maximum red and blue, but with green varying from 0 to 1 in steps of 0.05. »
Expected output:
Out[]=
7.6Blend the colors pink and yellow. »
Expected output:
Out[]=
Expected output:
Out[]=
7.8Make a list of numbers from 0 to 1 in steps of 0.1, each with a hue equal to its value. »
Expected output:
Out[]=
7.9Make a purple color swatch of size 100. »
Expected output:
Out[]=
7.10Make a list of red swatches with sizes from 10 to 100 in steps of 10. »
Expected output:
Out[]=
7.11Display the number 999 in red at size 100. »
Expected output:
Out[]=
7.12Make a list of the first 10 squares, in which each value is styled at its size. »
Expected output:
Out[]=
7.13Use Part and RandomInteger to make a length-100 list in which each element is randomly Red, Yellow or Green»
Sample expected output:
Out[]=
7.14Use Part to make a list of the first 50 digits of 2^1000, in which each digit has a size equal to 3 times its value. »
Expected output:
Out[]=
+7.1Create a column of colors with hues varying from 0 to 1 in steps of 0.05. »
Expected output:
Out[]=
+7.2Make a list of colors varying from red to green with green components x varying from 0 to 1 in steps of 0.05 and with red components 1-x.  »
Expected output:
Out[]=
+7.3Create a list of colors with no red or blue, and with green varying from 0 to 1 and back down to 0 in increments of 0.1 (the 1 should not be repeated). »
Expected output:
Out[]=
+7.4Blend the color red and its negation. »
Expected output:
Out[]=
+7.5Blend a list of colors with hues from 0 to 1 in increments of 0.1. »
Expected output:
Out[]=
+7.6Blend the color red with white, then blend it again with white.  »
Expected output:
Out[]=
+7.7Make a list of 100 random colors. »
Sample expected output:
Out[]=
+7.8Make a column for each number 1 through 10, with the number rendered first in red then in green. »
Expected output:
Out[]=
+7.9Make columns of the numbers 1 through 10, rendered as plain, bold and italic in each column. »
Expected output:
Out[]=
What named colors does the Wolfram Language have?
Red, Green, Blue, Black, White, Gray, Yellow, Brown, Orange, Pink, Purple, LightRed, etc. In Section 16 well see how to use ctrl+= to enter any color name in plain English.
Basically because thats how we humans perceive colors: there are three kinds of cells in our eyes that are roughly sensitive respectively to red, green and blue components of light. (Some other organisms work differently.)
What does color negation do?
What is hue?
Yes. A common one (implemented by Hue) is to use the combination of hue, saturation and brightness. LABColor and XYZColor are other examples. GrayLevel represents shades of gray, with GrayLevel[0] being black and GrayLevel[1] being white.
 
Download Notebook Version
es