[NTG-context] metapost: shading and transparency

Marco netuse at lavabit.com
Thu Jun 17 19:01:58 CEST 2010


Hi,

while using shading in metapost I cannot get transparency work.
The transparency is simply ignored and the result is the same colour as with
no transparency specified.

Here's an example that demonstrates the problem:

\definecolor [a]  [darkyellow]
\definecolor [b]  [r=1,  g=1,  b=1, a=1, t=0]
\definecolor [c]  [r=1,  g=1,  b=1, a=1, t=.5]
\definecolor [bg] [r=.8, g=.8, b=1]

% Define test background to see transparency (not) working
\defineoverlay[bg][\uniqueMPgraphic{bg}]
\startuniqueMPgraphic {bg}
  fill unitsquare
    xyscaled (\overlaywidth, \overlayheight) withcolor \MPcolor{bg};
    picture pic; pic := nullpicture;
    addto pic contour fullcircle scaled .5mm withcolor .2white;
    for i=1 upto 52:
      for j=1 upto 73:
	addto currentpicture also pic shifted (4mm*i, 4mm*j);
      endfor;
    endfor;
\stopuniqueMPgraphic
\setupbackgrounds [page] [background=bg]

\starttext
\startMPcode
  path p[];
  p1 := unitsquare xyscaled (4cm, 2cm);
  p2 := p1 yshifted -2.5cm;
  p3 := p2 yshifted -2.5cm;

  % Transparency does not work, background is white instead of full alpha
  linear_shade(p1,0,\MPcolor{a},\MPcolor{b});

  % Setting 2nd colour to background colour works only with plain coloured
  % backgrounds not with patterns
  linear_shade(p2,0,\MPcolor{a},\MPcolor{bg});

  % Transparency with simple »fill« works as expected
  fill p3 withcolor \MPcolor{c};
\stopMPcode
\stoptext

Thanks for any hints
Marco




More information about the ntg-context mailing list