Skip to content Accesskey=4Skip to sub-navigation Accesskey=3View our Accessibility Options MIT Information Systems Home About IS&T Contact IS&T Site Map Search Advanced Search
Getting StartedGetting Services by Topic or Alphabetically Getting Help

On This Page

[Help]

  

Quick Links

Top Level

Related Links

Ask OLC a question

Athena Consulting Homepage

Helpdesk Stock Answers (for Mac/PC questions)


How to use COLOR in applications

You can find a list of all the pre-named colors available, by typing the
following command at the main prompt:

	more /usr/lib/X11/rgb.txt

On the Suns use: 

	more /usr/openwin/lib/rgb.txt 

This lists the names of available colors and their corresponding rgb
values.  Here's an excerpt from the X man page, explaining how rgb works:

		 ----------------------------------------

   COLOR NAMES
     Most applications provide ways of tailoring (usually through resources
     or command line arguments) the colors of various elements in the text
     and graphics they display.  Although black and white displays don't pro-
     vide much of a choice, color displays frequently allow anywhere between
     16 and 16 million different colors.

     Colors are usually specified by their commonly-used names (for example,
     red, white, or medium slate blue).  The server translates these names
     into appropriate screen colors using a color database that can usually
     be found in /usr/lib/X11/rgb.txt.  Color names are case-insensitive,
     meaning that red, Red, and RED all refer to the same color.

     Many applications also accept color specifications of the following
     form:

                                       #rgb
                                     #rrggbb
                                    #rrrgggbbb
                                  #rrrrggggbbbb

     where r, g, and b are hexadecimal numbers indicating how much red,
     green, and blue should be displayed (zero being none and ffff being on
     full).  Each field in the specification must have the same number of
     digits (e.g., #rrgb or #gbb are not allowed).  Fields that have fewer
     than four digits (e.g. #rgb) are padded out with zero's following each
     digit (e.g. #r000g000b000).  The eight primary colors can be represented
     as:

             black       #000000000000 (no color at all)
             red         #ffff00000000
             green       #0000ffff0000
             blue        #00000000ffff
             yellow      #ffffffff0000 (full red and green, no blue)
             magenta     #ffff0000ffff
             cyan        #0000ffffffff
             white       #ffffffffffff (full red, green, and blue)

		 ----------------------------------------

Colors produced by rgb values may vary across monitors.  There are,
however, ways of quickly playing around with rgb values and seeing their
affect.  One way is to type this at the main prompt:

	add graphics
	xv /usr/athena/lib/X11/bitmaps/mensetmanus &

(you can specify any bitmap there instead of the mensetmanus one)

When the picture comes up, hit 'e' in the window.  A big window with lots
of buttons will come up, including three dials of particular importance,
labelled Red, Green, and Blue.  You can adjust these values by clicking on
the dial, and the change will be reflected in the background of the bitmap
shown.  To change the color of other regions (such as the foreground),
just click on the region you wish to edit in the picture with the left
mouse button.

To specify colors for X applications, you can usually do:

	program -fg "foreground color"  -bg "background color"

Some examples of programs you can do this with are xterm, emacs, ez, and
matlab.  If the name of the color has spaces in it, you should surround it
with double quotes like above.  You can also use an rgb specification
instead of a color name.  For example, the same thing happens if you type
either of these two commands:

	emacs -fg yellow -bg magenta
or
	emacs -fg "#ffffffff0000" -bg "#ffff0000ffff"


(Last updated Aug 12, 1997)

MIT Home | Getting Started | Getting Services | Getting Help | About IS&T | Accessibility
Ask a technology question or send a comment about this web page.