Skip to content

Color Cube

aleAceves edited this page May 18, 2021 · 39 revisions

This practice shows to the user automatically the color cube in 3D with the possibly of rotation, in order to see all the shades and faces of the cube.

Color cube

To do that: the six different faces of the cube has been defined as vectors with the corresponding coordinates. A vector for each color must be also be defined, to specify the exact color for each vertex of the cube(blue, red, green, white, black, cyan, yellow, magenta) with the use of the function zeros to create a 3D array.

To add the color to the 3D figure, the function fill3 has been used, which created a flat-shaded on polygons, it also enables to fill multiple areas with different colors for each one.

In the design view, there are other buttons; enabling the user several options:

  • A value of c can be added with the slider. The value wrote by the user is acquired, and divided by three, to know the specific value for the red, green and blue channel; since the value is c/3 the one that equivalue on the plane.

To define the new plane on that specific value, a matrix called vertices, has been created, where I put the value of c at the corresponding coordinate for each color channel. As we have 3 values, the new plane forms a triangle inside the color cube. To visualise the polygonal, the function patch has been used. For this function, we need to specify the coordinates of the polygon and the color of it (the matrix, in this case, will be the new color for that plane). To make clearer the visualisation of the plane, it is plotted in a 3D grid.


  • The user can also introduce different values for each color channel (r, g and b), and the resulting color will be shown for that values. The function patch has also been used to visualise the new plane in 3D with the new color resulting from the combination of the red, green and blue channels. The new color, we will be one of the the shades of the color cube since every color on the planar surface is a combination of r+g+b.


DEMOSTRATION OF HOW IT WORKS:

Clone this wiki locally