Autocad RGB Color Cube

screenshot_4-3-2016_5

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.

screenshot_4-3-2016_7

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("AutoCAD.AcCmColor.20")
  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.

screenshot_4-4-2016_9

you can do spheres too

screenshot_4-4-2016_10

screenshot_4-4-2016_13

screenshot_4-3-2016_5

Advertisements

One thought on “Autocad RGB Color Cube

  1. 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

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s