In the RGB color model, any color is represented as a combination of three basic colors: R – red, B – blue, and G – green. Basic colors are specified by a number in the range from 0 to 255. Therefore, any color in this model will be represented by a combination of three such numbers. For example, light orange will be represented by a set of numbers (255, 153, 51). The RGB model can be visualized by imagining it as a cube with a side equal to 255, all of whose internal points are vectors, the position of which is determined by a triple of numbers that determines the color itself.
We can create such a cube in Blender using the Python API.
We can loop through all the values from 0 to 255 for each coordinate and place any object, for example – a sphere, in each resulting point in the scene.
|
1 2 3 4 5 6 7 |
for x in range(0, 255): for y in range(0, 255): for z in range(0, 255): bpy.ops.mesh.primitive_ico_sphere_add( radius=0.001, location=(x, y, z) ) |
However, let’s simplify the example a little, and we will not create a sphere in the scene for every possible point, but take only 6 points per side of the cube. And we will reduce the color cube itself by 255 times, so that in the scene coordinates it occupies a space in the range from 0 to 1.
To get 6 points from the range 0-255, we need to increase the coordinate by 51 at each iteration of the loop. And to get all 6 points, we will use a list compressive, in addition to the range() function.
The loop over three coordinates will look like the following:
|
1 2 3 4 5 6 7 |
for x in [int(_c * (255/5)) for _c in range(0, 6)]: for y in [int(_c * (255/5)) for _c in range(0, 6)]: for z in [int(_c * (255/5)) for _c in range(0, 6)]: bpy.ops.mesh.primitive_ico_sphere_add( radius=0.1, location=(x/255, y/255, z/255) ) |
After executing this code, we get a cube filled with spheres. However, we do not see any color information in it.
Let’s assign a viewport color to each sphere, one that corresponds to the coordinates of its center. Additionally, we will also set the name of each sphere as a digital value of the color it corresponds to.
Now, our code will look like this:
|
1 2 3 4 5 6 7 8 9 10 |
for x in [int(_c * (255/5)) for _c in range(0, 6)]: for y in [int(_c * (255/5)) for _c in range(0, 6)]: for z in [int(_c * (255/5)) for _c in range(0, 6)]: bpy.ops.mesh.primitive_ico_sphere_add( radius=0.1, location=(x/255, y/255, z/255) ) active_object = bpy.context.object active_object.color = (x/255, y/255, z/255, 1) active_object.name = '(' + str(x) + ', ' + str(y) + ', ' + str(z) + ')' |
Let’s execute it, and for the colors to be visible immediately in the 3D viewport area, in its properties switch the Lighting parameter to “Flat”, Object Color – to “Object”. Optionally, you can on the Shadow and Outline checkboxes.
If you look closely at the cube, the colors seem to be distributed a little incorrectly. This happened because in the RGB color model we operate with numbers in the range from 0 to 255, and we set the color of our spheres in the viewport in the range from 0 to 1. By converting one range to another, we simply divided the values by 255, which is wrong for converting the colors.
To convert a color value from the RGB range to the linear range, we need to use a special formula.
Let’s wrap it to a function, which receives a number from the RGB color range from 0 to 255 as input, and outputs a value in the linear range from 0 to 1.
|
1 2 3 4 5 6 |
def rgb2l(color_value: int) -> float: color_value /= 255.99 if color_value <= 0.04045: return color_value / 12.92 else: return ((color_value + 0.055) / 1.055) ** 2.4 |
Now all that’s left is to slightly change our color cube construction code by adding the correct color conversion.
The final code:
|
1 2 3 4 5 6 7 8 9 10 |
for x in [int(_c * (255/5)) for _c in range(0, 6)]: for y in [int(_c * (255/5)) for _c in range(0, 6)]: for z in [int(_c * (255/5)) for _c in range(0, 6)]: bpy.ops.mesh.primitive_ico_sphere_add( radius=0.1, location=(x/255, y/255, z/255) ) active_object = bpy.context.object active_object.color = (rgb2l(x), rgb2l(y), rgb2l(z), 1) active_object.name = '(' + str(x) + ', ' + str(y) + ', ' + str(z) + ')' |
Now the color cube we have built looks correct, and we can conveniently study the distribution of colors in its space.
The number of points can be increased to improve the accuracy of visualization up to 255.

.blend file on Patreon