Overview
Looking to randomize the colours of squares of a checkerboard so that some are slightly lighter and some are slightly darker, relative to another colour.
Problem
The following sets a base colour and a lighter version:
\definecolor[BaseColour][h=66CEF1]
\definespotcolor[BaseColourLighter][BaseColour][a=1,t=.5]
The following code in MetaPost fails:
lightColour := \MPcolor{BaseColourLighter};
Code
Here is the code:
\setupcolors[state=start]
\definecolor[BaseColour][h=66CEF1]
\definespotcolor[BaseColourLighter][BaseColour][a=1,t=.5]
\startuseMPgraphic{ThemeBase}
fill Page withcolor blue;
\stopuseMPgraphic
\startuseMPgraphic{page:ThemeElement}
tiles_x := 8;
tiles_y := 13;
dim_x := OverlayWidth / tiles_x;
dim_y := dim_x;
color baseColour;
color lightColour;
baseColour := \MPcolor{BaseColour};
lightColour := \MPcolor{BaseColourLighter};
path s;
s := (0, 0) -- (dim_x, 0) -- (dim_x, dim_y) -- (0, dim_y) -- cycle;
for x = 0 upto tiles_x:
for y = 0 upto tiles_y:
path p;
p := s shifted( x * dim_x, y * dim_y );
if (x mod 2) = (y mod 2):
fill p withcolor baseColour;
draw p withcolor baseColour;
else:
def lightColour = transparent( 1, .55-.25uniformdeviate(1), baseColour ) enddef;
fill p withcolor lightColour;
draw p withcolor lightColour;
fi
endfor;
endfor;
setbounds currentpicture to
boundingbox currentpicture shifted( -dim_x/2, dim_y*(tiles_x/tiles_y)/2 );
\stopuseMPgraphic
\defineoverlay[ThemeBase][\uniqueMPgraphic{ThemeBase}]
\defineoverlay[page:ThemeElement][\uniqueMPgraphic{page:ThemeElement}]
\starttext
\setupbackgrounds[page][background={ThemeBase,page:ThemeElement}]
\startchapter[title=One]
\input knuth
\stopchapter
\stoptext
Error
The error message is:
Equation cannot be performed (color=numeric).
<to be read again>
withprescript
Transparency
The following uses transparency:
fill s shifted( x * dim_x, y * dim_y ) withcolor transparent(1,0.5,baseColour);
draw s shifted( x * dim_x, y * dim_y ) withcolor transparent(1,0.5,baseColour);
However, I really want something like:
transparent( 1, .55-.25uniformdeviate(1), baseColour )
To achieve something like:
Or like:
Or with any shape, really. Hence setting an initial background colour and using MetaPost.
Question
How do you use relatively coloured colours in ConTeXt/MetaPost?