Graphics and media/Collections of tips and tricks/Fill-unfill or even-odd rule in Metafun

From Wiki
Jump to navigation Jump to search

Metapost doesn't support even-odd rule filling so it uses a fake unfilling via a background color. This is problematic in cases when one deals with e.g. transparency. To overcome this difficulty, Metafun implements some extensions, such as eofill. To fill a shape using the even-odd rule we need a sequence of nofill ending with a eofill statement, as it can be seen in the following examples.

Some examples

  • %Adapted from Metafun's manual
    \startMPpage
    nofill fullsquare scaled 2cm ;
    nofill fullsquare scaled 2cm 
           shifted (1cm,0) ;
    eofill fullsquare scaled 2cm 
           shifted (0,1cm) withcolor darkred;
    \stopMPpage
    
  • \startMPpage
        path A; A := (unitcircle 
                      shifted (-center unitcircle)) 
                      scaled 4cm;
        path B; B := (unitcircle 
                      shifted (-center unitcircle)) 
                      scaled 1cm;
        path C; C := B shifted (left*1.4cm);
        nofill A; nofill B; 
        eofill C withcolor darkblue;
    \stopMPpage