# Autocad RGB Color Cube The bit is the fundamental unit of computer information. 1 bit can be either on or off, represented as 1 or 0, it has two states.
2 bits can represent 4 states, $2^2$
00 01 10 11
This is the binary number system.

3 bits -> $2^3$ = 8 states
4 bits -> $2^4$ = 16 states
5 bits -> $2^5$ = 32 states
6 bits -> $2^6$ = 64 states
7 bits -> $2^7$ = 128 states
8 bits -> $2^8$ = 256 states

8 bits is called a Byte.
There are 16 states in a 4 bit unit.
0123456789ABCDEF
This is the hexadecimal system.
F = 15 decimal = 1111 binary

The RGB color model creates millions of colors by mixing Red, Green, and Blue in proportions from 0 to 255 each. each value is an 8 bit number, in decimal from 0 to 255, in hex from 0 to FF. Each of the 3 colors can have 256 different values, the total possible is $256^3=16,772,216$.
Since 8 bits are required for each of the 3 registers, the system is called 24 bit color.

When computers had less capacity, a 256 color system was normal. Standards were created for the web using 216 colors. Instead of using all 256 colors for each red, green and blue, only 6 are used evenly spaced. 255 divided by 5 (spaces) is 51. RGB numbers used are 0 51 102 153 204 and 255. The total possible is $6^3=216$. the code is pretty simple.

```
Sub draw_color_cube()
Call connect_acad

Dim x As Integer, y As Integer, z As Integer
Dim color As AcadAcCmColor
Set color = AcadApplication.GetInterfaceObject(&quot;AutoCAD.AcCmColor.20&quot;)
Dim i_r As Integer, i_g As Integer, i_b As Integer
Dim pt(0 To 2) As Double
Dim objent As Acad3DSolid

For z = 1 To 6
For y = 1 To 6
For x = 1 To 6

'to explode the cube multiply each xyz by a small integer below
pt(0) = x: pt(1) = y: pt(2) = z

Set objent = acadDoc.ModelSpace.AddBox(pt, 1, 1, 1)

Select Case x 'red
Case 1
i_r = 0
Case 2
i_r = 51
Case 3
i_r = 102
Case 4
i_r = 153
Case 5
i_r = 204
Case 6
i_r = 255
End Select

Select Case y 'green
Case 1
i_g = 0
Case 2
i_g = 51
Case 3
i_g = 102
Case 4
i_g = 153
Case 5
i_g = 204
Case 6
i_g = 255
End Select

Select Case z 'blue
Case 1
i_b = 0
Case 2
i_b = 51
Case 3
i_b = 102
Case 4
i_b = 153
Case 5
i_b = 204
Case 6
i_b = 255
End Select

Call color.SetRGB(i_r, i_g, i_b)
objent.TrueColor = color

Next x
Next y
Next z

End Sub
```

Here is a nice link for rgb values. The table of 216 web safe colors at the bottom of the page were used in this program.

http://www.w3schools.com/cssref/css_colors.asp

you can slice the cube by adding a multiplier on just one position xyz, as noted above. this was run 3 separate times moving the multiplier to the next variable x y or z. the fully exploded version was made by putting a multiplier on all. you can do spheres too   Advertisements

## One thought on “Autocad RGB Color Cube”

1. zafferd says:

Hi frfly,
I too made a virtual color cube.

http://bitsong.com/Unity3D.html
This is a link to my recently completed project, a 3D interactive RGB color cube. I used Unity3D game creation software and Blender 3D modeling software to build the cube, create the interface and code the movements.

With my cube, using the mouse, keyboard arrow keys and buttons on the interface, you can glide into the cube, look around and move in any direction.

I also created a palette of 216 colors. Using it, you can click on any two colors and the viewpoint will line up with those two colors. You can then use the arrow keys to glide into the cube and see what colors occur in between.

I thought you might be interested Thanks.
Barbara Parkman

Liked by 1 person

This site uses Akismet to reduce spam. Learn how your comment data is processed.