ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Problems with MetaFun Transparency Groups
@ 2022-06-13 21:37 Stefan Haller via ntg-context
  0 siblings, 0 replies; only message in thread
From: Stefan Haller via ntg-context @ 2022-06-13 21:37 UTC (permalink / raw)
  To: ntg-context; +Cc: Stefan Haller

Hi everyone!

I have a question regarding transparency groups in MetaFun. As a toy example, I
want to draw a grid of lines where the whole grid should have an opacity of 25%.

If I draw intersecting lines individually with `withtransparency(1, .25)` the
overlapping parts will have a total opacity of 50%. However, I want to draw the
whole grid as one group and then blend it as a whole so that the whole grid is
evenly colored when blended. According to the MetaFun manual we should be able
to get the desired effect with the `asgroup` operator applied to a picture.
(Actually, the manual says the operator is called `grouped` but the source code
of the graphics above uses the `asgroup` operator [1].)

The `asgroup` does in fact insert a transparency group into the PDF output:

> << /Type /XObject /Subtype /Form /FormType 1 /Group << /S /Transparency /I false /K false

However, the group does not seem to be blended as one group and we can still
see that the overlapping parts are darker than the other parts of the line.
Something seems to be off. Looking at the compiled manual also shows that the
transparency groups are not working (both parts of the arrow, the head and the
tail, are blended independently and not as a group).

When I recreate the graphics in Tikz/PGF everything works. The resulting PDF
output looks similar, at least with my limited understanding of PDF format I am
unable to understand the differences.

The full example is attached below the text of my mail. The Tikz example on the
fifth page shows the desired result.

Do I misunderstand the syntax of transparency groups in MetaFun? Or is there
some other problem? Maybe someone can point me in the right direction.

Thanks in advance!
Stefan Haller

[1]: https://source.contextgarden.net/doc/context/sources/general/manuals/metafun/metafun-effects.tex?search=asgroup&docs=yes#l2543



\nopdfcompression
\usemodule[tikz]

\starttext
\startMPdefinitions
  vardef draw_grid =
    def withmycolor = withcolor red withtransparency(normaltransparent, .25) enddef;
    linecap := butt;
    u := 10mm;
    n := 20;
    pickup pencircle scaled 7mm;
    for i = 1 upto n:
      draw (0, i) * u -- (n+1, i) * u withmycolor;
      draw (i, 0) * u -- (i, n+1) * u withmycolor;
    endfor;
  enddef;
\stopMPdefinitions
\startMPpage
  draw image( draw_grid ) asgroup "";
  addbackground withcolor yellow;
\stopMPpage
\startMPpage
  draw image( draw_grid ) asgroup "isolated";
  addbackground withcolor yellow;
\stopMPpage
\startMPpage
  draw image( draw_grid ) asgroup "knockout";
  addbackground withcolor yellow;
\stopMPpage
\startMPpage
  draw image( draw_grid ) asgroup "isolated,knockout";
  addbackground withcolor yellow;
\stopMPpage
\startTEXpage
\starttikzpicture
  \fill[yellow] (-0.35cm, -0.35cm) rectangle (21.35cm, 21.35cm);
  \startscope[opacity=.25, transparency group]
    \startscope[x=10mm, y=10mm, every path/.style={line width=7mm}]
      \foreach \i in {1,...,20}{
        \draw[red] (0, \i) -- (21, \i);
        \draw[red] (\i, 0) -- (\i, 21);
      };
    \stopscope
  \stopscope
\stoptikzpicture
\stopTEXpage
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-13 21:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-13 21:37 Problems with MetaFun Transparency Groups Stefan Haller via ntg-context

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).