Try now in the
Open Cloud »
(no sign-in required)

Color Cube

Visualize red-green-blue color space.

Run the code to make a swatch of color by specifying RGB components. Try other color components:

Note: use color component values between 0 and 1.

SHOW/HIDE DETAILS

Use RGBColor to specify a color from its red, green, and blue components.

This gives pure red because the green and blue components are zero:

In[1]:=
X
Out[1]=

Mixing red and green gives yellow:

In[2]:=
X
Out[2]=

Color component values lie between 0 and 1.

When all of the color components are 0, you get black:

In[3]:=
X
Out[3]=

When all of the color components are 1, you get white:

In[4]:=
X
Out[4]=

Mixing different amounts of each component gives different colors:

In[5]:=
X
Out[5]=
In[6]:=
X
Out[6]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Make a color sphere. Try other colors:

SHOW/HIDE DETAILS

This draws a sphere:

In[1]:=
X
Out[1]=

This colors the sphere red:

In[2]:=
X
Out[2]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Make a 5×5×5 array of spheres (each of radius 1/2). Try other sizes of arrays, and other radii:

SHOW/HIDE DETAILS

This draws a sphere at coordinate {1,1,1} with a radius of 1/2 (PlotRange specifies the extent of the drawing area; you can ignore it for now):

In[1]:=
X
Out[1]=

Change the coordinate to draw the sphere somewhere else:

In[2]:=
X
Out[2]=

Table makes arrays of things. Use Table to draw a whole array of spheres.

This makes an array of 3 numbers:

In[3]:=
X
Out[3]=

With two indices, you get a two-dimensional array (an array of arrays):

In[4]:=
X
Out[4]=

This uses Table to make a one-dimensional array of spheres:

In[5]:=
X
Out[5]=

Add an index to get a two-dimensional array of spheres:

In[6]:=
X
Out[6]=

Add a third index to get a three-dimensional array of spheres:

In[7]:=
X
Out[7]=

You can remove the PlotRange; without it, the drawing area is automatically made just large enough to contain the spheres:

In[8]:=
X
Out[8]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Make the spheres different colors. Try reordering the color componentsfor example, {j,i,k}:

Note: rotate the cube to see other orientations.

SHOW/HIDE DETAILS

This gives a one-dimensional array of colors that vary from almost black to red (dividing by 5 keeps the color components between 0 and 1):

In[1]:=
X
Out[1]=

This gives a two-dimensional array of colors:

In[2]:=
X
Out[2]=

Use the same strategy to color the spheres in an array:

In[3]:=
X
Out[3]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Manipulate the radius of each sphere. Drag the slider to change the sizes of the spheres:

Note: rotate the color cube to see it from a different angle.

SHOW/HIDE DETAILS

Manipulate puts an interactive interface onto a piece of code.

This draws a sphere with radius 1/2:

In[1]:=
X
Out[1]=

Make the radius interactive by wrapping the code with Manipulate, replacing 1/2 with the variable r, and specifying that r goes from 0 to 1. Drag the slider to change the radius of the sphere:

In[2]:=
X
Out[2]=

Do the same thing with the array of spheres:

In[3]:=
X
Out[3]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Share ItMake an interactive color cube website:

SHOW/HIDE DETAILS

Deploy the Manipulate to the Wolfram Cloud where anyone with a browser can use it:

In[1]:=
X
Out[1]=

Click the link in the output to visit the site.

Share the link by right-clicking it and choosing Copy Address. Paste the link into an email, tweet, or other message.

HIDE DETAILS
In[1]:=
X
Out[1]=