8
$\begingroup$

When manipulating colors, the output is shown as a textual expression like Hue[1/5], RGBColor[2/3, 1, 1/3], GrayLevel[3/5]. It can be hard to visualize what color these represent.

How can you quickly display the color itself on screen?

$\endgroup$
11
$\begingroup$

A simple way is to use a ColorSetter.

Where color is the color you want to display, run

DynamicSetting@ColorSetter@color

You can also copy the result and use it as input in a notebook.

Illustration:

Illustration

$\endgroup$
8
$\begingroup$

Evaluate (Shift+Enter) your code for color. In Mathematica 9 the suggestion bar will appear under the output with suggestion "swatch". Just click it and you'll get a square with that color.

enter image description here

$\endgroup$
5
$\begingroup$

If you just want to know what a particular color looks like and don't have M9 you can set it up with Graphics in many ways. Here is one. I've added the Listable attribute so you can see many colors at once.

SetAttributes[swatch, Listable];
swatch[col_] := Graphics[{col, Disk[]}, ImageSize -> 50]

swatch[{Hue[1/5], RGBColor[2/3, 1, 1/3], GrayLevel[3/5]}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.