\startcomponent co-colors

\environment contextref-env
\product contextref

\startbuffer[colo-1]
\setupblackrules[width=.25\hsize,height=2ex,depth=0cm]
\setupcombinations[inbetween=]
\startcombination[3*7]
  {\color[red]           {\blackrule}} {\translate[en=red,          nl=rood]}
  {\color[green]         {\blackrule}} {\translate[en=green,        nl=groen]}
  {\color[blue]          {\blackrule}} {\translate[en=blue,         nl=blauw]}
  {\color[middlered]     {\blackrule}} {\translate[en=middlered,    nl=middenrood]}
  {\color[middlegreen]   {\blackrule}} {\translate[en=middlegreen,  nl=middengroen]}
  {\color[middleblue]    {\blackrule}} {\translate[en=middleblue,   nl=middenblauw]}
  {\color[darkred]       {\blackrule}} {\translate[en=darkred,      nl=donkerrood]}
  {\color[darkgreen]     {\blackrule}} {\translate[en=darkgreen,    nl=donkergroen]}
  {\color[darkblue]      {\blackrule}} {\translate[en=darkblue,     nl=donkerblauw]}
  {\color[yellow]        {\blackrule}} {\translate[en=yellow,       nl=geel]}
  {\color[magenta]       {\blackrule}} {\translate[en=magenta,      nl=magenta]}
  {\color[cyan]          {\blackrule}} {\translate[en=cyan,         nl=cyaan]}
  {\color[middleyellow]  {\blackrule}} {\translate[en=middleyellow, nl=middelgeel]}
  {\color[middlemagenta] {\blackrule}} {\translate[en=middlemagenta,nl=middelmagenta]}
  {\color[middlecyan]    {\blackrule}} {\translate[en=middlecyan,   nl=middelcyaan]}
  {\color[darkyellow]    {\blackrule}} {\translate[en=darkyellow,   nl=donkergeel]}
  {\color[darkmagenta]   {\blackrule}} {\translate[en=darkmagenta,  nl=donkermagenta]}
  {\color[darkcyan]      {\blackrule}} {\translate[en=darkcyan,     nl=donkercyaan]}
  {\color[lightgray]     {\blackrule}} {\translate[en=lightgray,    nl=lichtgrijs]}
  {\color[darkgray]      {\blackrule}} {\translate[en=darkergray,   nl=donkergrijs]}
  {\color[black]         {\blackrule}} {\translate[en=black,        nl=zwart]}
\stopcombination
\stopbuffer

\startbuffer[colo-2]
\setupblackrules[width=.25\hsize,height=\ht\strutbox,depth=\dp\strutbox]
\startcombination[3*2]
  {\color    [cyaan:x]{\blackrule}} {\colorvalue{cyaan:x}}
  {\color    [cyaan:y]{\blackrule}} {\colorvalue{cyaan:y}}
  {\color    [cyaan:z]{\blackrule}} {\colorvalue{cyaan:z}}
  {\graycolor[cyaan:x]{\blackrule}} {\grayvalue {cyaan:x}}
  {\graycolor[cyaan:y]{\blackrule}} {\grayvalue {cyaan:y}}
  {\graycolor[cyaan:z]{\blackrule}} {\grayvalue {cyaan:z}}
\stopcombination
\stopbuffer

\startbuffer[colo-3]
\offinterlineskip
\halign
  {\hss#\cr
   \showcolorgroup[red]    [horizontal,name,number]\cr
   \showcolorgroup[green]  [horizontal,name]\cr
   \showcolorgroup[blue]   [horizontal,name]\cr
   \showcolorgroup[yellow] [horizontal,name]\cr
   \showcolorgroup[magenta][horizontal,name]\cr
   \showcolorgroup[cyan]   [horizontal,name]\cr}
\stopbuffer

\startbuffer[colo-4]
\hbox
  {\showcolorgroup[red]     [vertical,name,number]%
   \showcolorgroup[green]   [vertical,name]%
   \showcolorgroup[blue]    [vertical,name]%
   \showcolorgroup[yellow]  [vertical,name]%
   \showcolorgroup[magenta] [vertical,name]%
   \showcolorgroup[cyan]    [vertical,name]}
\stopbuffer

\startbuffer[colo-5]
\vbox
  {\forgetall
   \ttx
   \def\y{screen}
   \def\n{}
   \offinterlineskip
   \def\rijtjenamen#1#2#3#4#5#6#7#8
     {\hbox
        {\framed[width=4em,frame=off]{#1}%
         \hskip.25em
         \framed[background=#3,backgroundscreen=.9]{#2{leftedge}}%
         \hskip.25em
         \framed[background=#4,backgroundscreen=.9]{#2{leftmargin}}%
         \hskip.25em
         \framed[background=#5,backgroundscreen=#8]{#2{text}}%
         \hskip.25em
         \framed[background=#6,backgroundscreen=.9]{#2{rightmargin}}%
         \hskip.25em
         \framed[background=#7,backgroundscreen=.9]{#2{rightedge}}}}%
   \setupframed[width=6.5em]
   \bgroup
   \setupframed[frame=off]
   \rijtjenamen{}\hbox \n\n\n\n\n .9
   \egroup
   \vskip.125em
   \rijtjenamen{top}\hphantom \n\n\n\n\n .9
   \vskip.25em
   \rijtjenamen{header}\hphantom \n\y\y\y\n .9
   \vskip.25em
   \rijtjenamen{text}\hphantom \n\y\y\y\n .5
   \vskip.25em
   \rijtjenamen{footer} \hphantom \n\y\y\y\n .9
   \vskip.25em
   \rijtjenamen{bottom}\hphantom \n\n\n\n\n .9
   \vskip.25em}
\stopbuffer

\chapter[color]{Colors}

\section{Introduction}

Judicious use of color can enhance your document's layout.
For example. in interactive documents color can be used to
indicate hyperlinks or other aspects that have no meaning in
paper documents, or background colors can be used to
indicate screen areas that are used for specific information
components.

In this chapter we describe the \CONTEXT\ color support. We
will also pay attention to backgrounds and overlays because
these are related to the color mechanism.

\section[color]{Color}
\index{color}
\index[rgb]{\RGB}
\index[cmyk]{\CMYK}
\index{gray conversion}
\macro{\tex{definecolor}}
\macro{\tex{setupcolors}}
\macro{\tex{setupcolors}}
\macro{\tex{color}}
\macro{\tex{startcolor}}
\macro{\tex{showcolor}}

One of the problems in typesetting color is that different
colors may result in identical gray shades. We did some
research in the past on this subject and we will describe
the \CONTEXT\ facilities on this matter and the way
\CONTEXT\ forces us to use color consistently. Color should
not be used indiscriminately, therefore you first have to
activate the color mechanism:

\startexample
\starttyping
\setupcolors[state=start]
\stoptyping
\stopexample

Other color parameters are also available:

\showsetup{setupcolors}

The parameter \type {state} can also be set at \type {local}
or \type {global}. If you do not know whether the use of
color will cross a page boundary, then you should use \type
{global} or \type {start} to keep track of the color. We use
\type {local} in documents where color will never cross a
page border, as is the case in many screen documents. This
will also result in a higher processing speed. (For most
documents it does not hurt that much when one simply uses
\type {start}).

By default both the \RGB\ and \CMYK\ colorspaces are
supported. When the parameter \type {cmyk} is set at \type
{no}, then the \CMYK\ color specifications are automatically
converted to \RGB. The reverse is done when \type {rgb=no}.
When no color is allowed the colors are automatically
converted to weighted grayshades. You can set this conversion
with \type {conversion}. When set to \type {always}, all
colors are converted to gray, when set to \type {yes}, only
gray colors are converted.

Colors must be defined. For some default color spaces, this
is done in the file \type{colo-<<xxx>>.tex}. After
definition the colors can be recalled with their mnemonic
name \type {<<xxx>>}. By default the file \type {colo-rgb.tex} is
loaded. In this file we find definitions like:

\startexample
\starttyping
\definecolor [darkred]   [r=.5, g=.0, b=.0]
\definecolor [darkgreen] [r=.0, g=.5, b=.0]
............ ...........  ..................
\stoptyping
\stopexample

A file with color definitions is loaded with:

\startexample
\starttyping
\setupcolor[rgb]
\stoptyping
\stopexample

Be aware of the fact that there is also a command \type
{\setupcolors} that has a different meaning. The \type {rgb}
file is loaded by default.

Color must be activated like this:

\startexample
\starttyping
\startcolor[darkgreen]
We can use as many colors as we like. But we do have to take into
account that the reader is possibly \color [darkred] {colorblind}. The
use of color in the running text should always be carefully considered.
The reader easily tires while reading multi||color documents.
\stopcolor
\stoptyping
\stopexample

In the same way you can define \CMYK\ colors and grayshades:

\startexample
\starttyping
\definecolor [cyan] [c=1,m=0,y=0,k=0]
\definecolor [gray] [s=0.75]
\stoptyping
\stopexample

gray can also be defined like this:

\startexample
\starttyping
\definecolor [gray] [r=0.75,r=0.75,b=0.75]
\stoptyping
\stopexample

When the parameter \type {conversion} is set at \type {yes}
the color definitions are automatically downgraded to the
\type{s}||form: \type {[s=.75]}. The~\type {s} stands for
\quote {screen}. When \type {reduction} is \type {yes}, the
black component of a \CMYK\ color is distilled from the
other components.

One of the facillities of color definition is the heritage
mechanism:

\startbuffer
\definecolor [important] [red]
\stopbuffer

\getbuffer

\startexample
\typebuffer
\stopexample

These definitions enable you to use colors consistently.
Furthermore it is possible to give all \color [marked]
{important} issues a different color, and change colors
afterwards or even in the middle of a document.

So, next to \type {\setupcolors} we have the following
commands for defining colors:

\showsetup{definecolor}

A color definition file is loaded with:

\showsetup{setupcolor}

Typesetting color is done with:

\showsetup{color}

\showsetup{startcolor}

A complete palette of colors is generated with:

\showsetup{showcolor}

\in{Figure}[fig:some colors] shows the colors that are
standard available (see \type {colo-rgb.tex}).

\placefigure
  [][fig:some colors]
  {Some examples of colors.}
  {\getbuffer[colo-1]}

\startcolor[darkgreen] The use of color in \TEX\ is not
trivial. \TEX\ itself has no color support. Currently color
support is implemented using \TEX's low level \type
{\mark}'s and \type {\special}'s. This means that there are
some limitations, but in most cases these go unnoticed.

It is possible to cross page boundaries with colors. The
headers and footers and the floating figures or tables will
stil be set in the correct colors. However, the mechanism is
not robust.

In this sentence we use colors within colors. Aesthetically
this is bad.

As soon as a color is defined it is also available as a
command. So there is a command \type {\darkred}. These
commands do obey grouping. So we can say {\darkred \type
{{\darkred this is typeset in dark red}}}.

\stopcolor

There are a number of commands that have the parameter \type
{color}. In general, when a \type {style} can be set, \type
{color} can also be set.

The default color setup is:

\starttyping
\setupcolors [conversion=yes, reduction=no, rgb=yes, cmyk=yes]
\stoptyping

This means that both colorspaces are supported and that the
$k$||component in \CMYK\ colors is maintained. When \type
{reduction=yes}, the $k$||component is \quote {reduced}. With
\type{conversion=no} equal color components are converted to
gray shades.

\section[gray]{Grayscales}
\index{grayscales}
\macro{\tex{graycolor}}
\macro{\tex{grayvalue}}
\macro{\tex{colorvalue}}

When we print a document on a black and white printer we
observe that the differences between somes colors are gone.
\in{Figure}[fig:cyan] illustrates this effect.

\placefigure
  [][fig:cyan]
  {Three cyan variations with equal gray shades.}
  {\getbuffer[colo-2]}

In a black and white print all blocks look the same but
the three upper blocks have different cyan based colors. The
lower blocks simulate grayshades. We use the following
conversion formula:

\placeformula[-]
\startformula
\rm gray = .30 \times red   +
           .59 \times green +
           .11 \times blue
\stopformula

A color can be displayed in gray with the command:

\showsetup{graycolor}

The actual values of a color can be recalled by the commands
\type{\colorvalue{<<name>>}} and
\type{\grayvalue{<<name>>}}.

We can automatically convert all used colors in weighted
grayshades.

\starttyping
\setupcolors [conversion=always]
\stoptyping

\section[colorgroups,palettes]{Colorgroups and palettes}
\index{colorgroups}
\index{palettes}
\macro{\tex{definepalet}}
\macro{\tex{definecolorgroup}}
\macro{\tex{setuppalet}}
\macro{\tex{showpalet}}
\macro{\tex{showcolorgroup}}
\macro{\tex{comparepalet}}
\macro{\tex{comparecolorgroup}}

\TEX\ itself has hardly any built||in graphical features.
However the \CONTEXT\ color mechanism is designed by looking
at the way colors in pictures are used. One of the problems
is the effect we described in the last section. On a color
printer the picure may look fine, but in black and white
the results may be disappointing.

In \TEX\ we can aproach this problem systematically.
Therefore we designed a color mechanism that can be compared
with that in graphical packages.

We differentiate between individual colors and colorgroups.
A colorgroup contains a number of gradations of a color.
By default the following colorgroups are defined.

\placefigure{none}{\getbuffer[colo-3]}

The different gradations within a colorgroup are represented
by a number. A colorgroup is defined with:

\showsetup{definecolorgroup}

An example of a part of the \RGB\ definition is:

\startexample
\starttyping
\definecolorgroup
  [blue][rgb]
  [1.00:1.00:1.00,
   0.90:0.90:1.00,
   ..............,
   0.40:0.40:1.00,
   0.30:0.30:1.00]
\stoptyping
\stopexample

The \type {[rgb]} is not mandatory in this case, because
\CONTEXT\ expects \RGB\ anyway. This command can be viewed
as a range of color definitions.

\startexample
\starttyping
\definecolor [blue:1] [r=1.00, g=1.00, b=1.00]
\definecolor [blue:2] [r=0.90, g=0.90, b=1.00]
..............
\definecolor [blue:7] [r=0.40, g=0.40, b=1.00]
\definecolor [blue:8] [r=0.30, g=0.30, b=1.00]
\stoptyping
\stopexample

A color within a colorgroup can be recalled with
\type{<<name>>:<<number>>}, for example: \type{blue:4}.

There is no maximum to the number of gradations within a
colorgroup, but on the bases of some experiments we advise
you to stay within 6~to 8~gradations. We can explain this.
Next to colorgroups we have palettes. A pallet consists of a
limited number of {\em logical} colors. Logical means that
we indicate a color with a name. An example of a palette is:

\placefigure[force][]{none}
  {\showpalet[alfa][horizontal,name,number]}

The idea behind palettes is that we have to avoid colors
that are indistinguishable in black and white print. A
palette is defined by:

\startexample
\starttyping
\definepalet
  [example]
  [strange=red:3,
       top=green:1,
        .....
    bottom=yellow:8]
\stoptyping
\stopexample

We define a palette with the command:

\showsetup{definepalet}

\CONTEXT\ contains a number of predefined palettes. Within a
palette we use the somewhat abstract names of quarks: {\em
top}, {\em bottom}, {\em up}, {\em down}, {\em strange} and
{\em charm}. There is also {\em friend} and {\em rude}
because we ran out of names. Be aware of the fact that these
are just examples in the \RGB\ definition file and based on
our own experiments. Any name is permitted.

The system of colorgroups and palettes is based on the idea
that we compose a palette from the elements of a colorgroup
with different numbers. Therefore the prerequisite is that
equal numbers should have an equal grayshade.

\placefigure[force][]{none}{\getbuffer[colo-4]}

When a palette is composed we can use the command:

\showsetup{setuppalet}

After that we can use the colors of the chosen palette. The
logical name can be used in for example \type
{\color[strange]{is this not strange}}.

An example of the use of palettes is shown in the verbatim
typesetting of \TEX\ code. Within this mechanism colors
with names like \type {prettyone}, \type {prettytwo}, etc.
are used. There are two palettes, one for color and one for
gray:

\startexample
\starttyping
\definecolor [colorprettyone] [r=.9, g=.0, b=.0]
\definecolor [grayprettyone]  [s=.3]
\stoptyping
\stopexample

These palettes are combined into one with:

\startexample
\starttyping
\definepalet
  [colorpretty]
  [  prettyone=colorprettyone,    prettytwo=colorprettytwo,
   prettythree=colorprettythree, prettyfour=colorprettyfour]

\definepalet
  [graypretty]
  [  prettyone=grayprettyone,     prettytwo=grayprettytwo,
   prettythree=grayprettythree,  prettyfour=grayprettyfour]
\stoptyping
\stopexample

Now we can change all colors by resetting the palette with:

\startexample
\starttyping
\setuptyping[palet=colorpretty]
\stoptyping
\stopexample

Each filter can be set differently:

\startexample
\starttyping
\definepalet [MPcolorpretty] [colorpretty]
\definepalet [MPgraypretty]  [graypretty]
\stoptyping
\stopexample

As you can see a palette can inherit its properties from
another palette. This example shows something of the color
philosophy in \CONTEXT: you can treat colors as abstractions
and group them into palettes and change these when
necessary.

On behalf of the composition of colorgroups and palettes
there are some commands available to test whether the colors
are distinguishable.

\showsetup{showcolorgroup}

\showsetup{showpalet}

\showsetup{comparecolorgroup}

\showsetup{comparepalet}

The overviews we have shown thusfar are generated by the
first two commands and the gray values are placed below the
baseline. On the left there are the colors of the grayshades.

\placefigure[force][]{none}{\comparecolorgroup[green]}

This overview is made with \type {\comparecolorgroup[green]}
and the one below with \type {\comparepalet[gamma]}.

\placefigure[force][]{none}{\comparepalet[gamma]}

The standard colorgroups and palettes are composed very
carefully and used systematically for coloring pictures.
These can be displayed adequately in color and black and
white.

\placefigure
  {Some examples of the use of color.}
  \startcombination[4*1]
    {\externalfigure[vew1179]} {}
    {\externalfigure[vew1182]} {}
    {\externalfigure[vew1218]} {}
    {\externalfigure[spin016]} {}
  \stopcombination

\stopcomponent

