Scientific Arts

Copyright © 1999 by David Reiss (except where indicated), all rights reserved.  Use of this code is granted for all noncommercial purposes: acknowledgment of the source is requested.

http://www.scientificarts.com/

dreiss@scientificarts.com

Web Safe Colors Palette

There are 216 "web safe" colors built from the six hexadecimal values,

webHexValues = {16^^00, 16^^33, 16^^66, 16^^99, 16^^CC, 
        16^^FF}

For use in RGBColor one needs to rescale them.

scaledWebColorValues = 
      N[(FromDigits[{#}, 10] & /@ webHexValues)/255]

This is a table of lists of web safe R, G, and B values (of course there may be a much more compact way to do this, but the straightforward approach is fine here).

webColors = 
        Flatten[Table[{scaledWebColorValues[[i]], 
              scaledWebColorValues[[j]], 
              scaledWebColorValues[[k]]}, {i, 6}, {j, 6}, {k, 6}], 
          2];

It is indeed of length (6^3)=216.

Length[webColors]

Make a square array by padding this with "black" RGB values.

webColorArray = 
        Apply[RGBColor, PadLeft[webColors,  225, {{0, 0, 0}}], 
          1];

This displays the grid of colors.

GridBox[
        Partition[(ButtonBox[" ", Background -> #] & /@ 
              webColorArray), 15], ColumnSpacings -> 0, 
        RowSpacings -> 0] // DisplayForm

The function WebColorsPalette creates a palette that, when clicked on,  pastes the desired RGBColor directive into a notebook.

ClearAll[
        WebColorsPalette];

WebColorsPalette::usage = "WebColorsPalette[] create the a palette \
that, when clicked on,pastes the desired RGBColor directive into a \
notebook.";

\(\(WebColorsPalette[] := 
Module[{webHexValues, 
            scaledWebColorValues, webColors, 
            webColorArray}, 

webHexValues = {16^^00, 16^^33, 16^^66, 
              16^^99, 16^^CC, 16^^FF}; \ 
          scaledWebColorValues = \((FromDigits[{#1}, 10] &)\) /@ webHexValues/
              255; \ webColors = 
            Flatten[Table[{scaledWebColorValues[\([i]\)], 
                  scaledWebColorValues[\([j]\)], 
                  scaledWebColorValues[\([k]\)]}, {i, 6}, {j, 6}, {k, 6}], 
              2]; \ webColorArray = 
            Apply[RGBColor, PadLeft[N[webColors], 225, {{0, 0, 0}}], 
              1]; 

NotebookPut@
            Notebook[{Cell[\ 
                  BoxData[
                    GridBox[
                      Partition[\((ButtonBox[" ", 
                                ButtonData :> 
                                  Evaluate[ToString[#]], 
                                Background -> #] &)\) /@ webColorArray, 
                        15], ColumnSpacings -> 0, 
                      RowSpacings -> 
                        0]]
]
}, 
Editable -> False, WindowToolbars -> {}, 
              PageWidth -> 447, WindowSize -> {Fit, Fit}, 
              WindowMargins -> {{Automatic, 90}, {Automatic, 19}}, 
              WindowFrame -> "Palette", WindowElements -> {}, 
              WindowFrameElements -> "CloseBox", 
              WindowClickSelect -> False, 
              ScrollingOptions -> {"PagewiseScrolling" -> 
                    True}, ShowCellBracket -> False, 
              CellMargins -> {{0, 0}, {Inherited, 0}}, 
              Active -> True, CellOpen -> True, 
              ShowCellLabel -> False, ShowCellTags -> False, 
              ImageMargins -> {{0, Inherited}, {Inherited, 0}}, 
              Magnification -> 1, 
              WindowTitle -> "Web Safe Colors Palette"
]
];\)\)

The palette is created by executing,

WebColorsPalette[];

The function WebColoringPalette creates a palette that, when clicked on, will color your selection with the desired web safe color.

ClearAll[
        WebColoringPalette];

WebColoringPalette::usage = "WebColoringPalette[] create the a \
palette that, when clicked on, will color your selection with the desired web \
safe color.";

\(\(WebColoringPalette[] := 
Module[{webHexValues, 
            scaledWebColorValues, webColors, 
            webColorArray}, 

webHexValues = {16^^00, 16^^33, 16^^66, 
              16^^99, 16^^CC, 16^^FF}; \ 
          scaledWebColorValues = \((FromDigits[{#1}, 10] &)\) /@ webHexValues/
              255; \ webColors = 
            Flatten[Table[{scaledWebColorValues[\([i]\)], 
                  scaledWebColorValues[\([j]\)], 
                  scaledWebColorValues[\([k]\)]}, {i, 6}, {j, 6}, {k, 6}], 
              2]; \ webColorArray = 
            Apply[RGBColor, PadLeft[N[webColors], 225, {{0, 0, 0}}], 
              1]; 

NotebookPut@
            Notebook[{Cell[\ 
                  BoxData[
                    GridBox[
                      Partition[\((ButtonBox[" ", 
                                ButtonFunction :> 
                                  SetOptions[
                                    NotebookSelection[InputNotebook[]], 
                                    FontColor -> #], 
                                ButtonEvaluator -> Automatic, 
                                Background -> #] &)\) /@ webColorArray, 
                        15], ColumnSpacings -> 0, 
                      RowSpacings -> 
                        0]]
]
}, 
Editable -> False, WindowToolbars -> {}, 
              PageWidth -> 447, WindowSize -> {Fit, Fit}, 
              WindowMargins -> {{Automatic, 90}, {Automatic, 19}}, 
              WindowFrame -> "Palette", WindowElements -> {}, 
              WindowFrameElements -> "CloseBox", 
              WindowClickSelect -> False, 
              ScrollingOptions -> {"PagewiseScrolling" -> 
                    True}, ShowCellBracket -> False, 
              CellMargins -> {{0, 0}, {Inherited, 0}}, 
              Active -> True, CellOpen -> True, 
              ShowCellLabel -> False, ShowCellTags -> False, 
              ImageMargins -> {{0, Inherited}, {Inherited, 0}}, 
              Magnification -> 1, 
              
              WindowTitle -> "Web Safe Coloring Palette"
]
];\)\)

This palette is created by executing,

WebColoringPalette[];