# Generating a 3D array of hued spheres

Graphics3D[
Table[
Style[
Sphere[{x, y, z}, 0.5], Hue[c]], {c, 0, 1, 0.1}, {x, 5}, {y,
5}, {z, 5}]]


I need to generate a 10x10x10 array of spheres with RGB components ranging from 0 to 1. The spheres should be centered at integer coordinates, and should just touch each other.

The expected output is shown in the image below. Currently, I'm getting spheres with one color only. Please help.

Using Tuples:

Graphics3D[{{RGBColor[#/10], Sphere[#, 0.5]} & /@
Tuples[Range[10], 3]}]


Using Array:

Graphics3D[{Array[{RGBColor[{#1/10, #2/10, #3/10}],
Sphere[{#1, #2, #3}, 0.5]} &, {10, 10, 10}]}]


ColorConvert from RGBColor to Hue

Graphics3D[{Array[{ColorConvert[{#1/10, #2/10, #3/10}, "HSB"],
Sphere[{#1, #2, #3}, 0.5]} &, {10, 10, 10}]}]


Graphics3D[
Table[Style[Sphere[{x, y, z}, 0.5], RGBColor[x/10, y/10, z/10]],
{x, 10}, {y, 10}, {z, 10}]]


You must use the coordinates for the Hue. Note that Hue values must be between 0 and 1 (if you do not use ColorFunctionScaling). Here is an example:

Graphics3D[
Table[Style[Sphere[{x, y, z}, 0.5], Hue[(x + y + z)/15]], {x, 5}, {y,
5}, {z, 5}]]


If you want to use RGBColor:

Graphics3D[
Table[Style[Sphere[{x, y, z}, 0.5], RGBColor[x/5, y/5, z/5]], {x,
5}, {y, 5}, {z, 5}]]


• Your posted code does not produce the desired figure. Oct 5 at 19:30
• @David Thank you, I copied the wrong code. Fixed it. Oct 5 at 19:33
• Your code still does not produce what the OP requests because you are working with Hue but you must instead use RGB. Oct 5 at 19:35
• Ummm.... how does your second solution differ from my earlier one? Oct 6 at 13:32

Using CoordinateBoundsArray.

Graphics3D[{RGBColor @ #, Sphere[#, .1/2]} & /@
Flatten[CoordinateBoundsArray[{{0, 1}, {0, 1}, {0,
1}}, {.1, .1, .1}], 2]]