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.
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:
Mixing red and green gives yellow:
Color component values lie between 0 and 1.
When all of the color components are 0, you get black:
When all of the color components are 1, you get white:
Mixing different amounts of each component gives different colors:
Make a color sphere. Try other colors:
This draws a sphere:
This colors the sphere red:
Make a 5×5×5 array of spheres (each of radius 1/2). Try other sizes of arrays, and other radii:
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):
Change the coordinate to draw the sphere somewhere else:
Table makes arrays of things. Use Table to draw a whole array of spheres.
This makes an array of 3 numbers:
With two “indices”, you get a two-dimensional array (an array of arrays):
This uses Table to make a one-dimensional array of spheres:
Add an index to get a two-dimensional array of spheres:
Add a third index to get a three-dimensional array of spheres:
You can remove the PlotRange; without it, the drawing area is automatically made just large enough to contain the spheres:
Make the spheres different colors. Try reordering the color components—for example, {j,i,k}:
Note: rotate the cube to see other orientations.
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):
This gives a two-dimensional array of colors:
Use the same strategy to color the spheres in an array:
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.
Manipulate puts an interactive interface onto a piece of code.
This draws a sphere with radius 1/2:
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:
Do the same thing with the array of spheres:
Share It—make an interactive color cube website:
Deploy the Manipulate to the Wolfram Cloud, where anyone with a browser can use it:
Click the link in the output to visit the site.
Tell the world about your creation by sharing the link via email, tweet or other message.