summaryrefslogtreecommitdiff
path: root/info/examples/lgc2/4-1-14.mp
blob: e8264755a444a4ca16565baab07d110548478ca9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
% --- start of displayed preamble in the book ---
% alphafill as defined above
% --- end of displayed preamble in the book ---

% graphic converted to gray in book using 'color2gray'

picture alphapict_; alphapict_=nullpicture;

vardef alphafill(expr c,col,transparency)=
  alphapict_:=nullpicture;
  alphafill_(currentpicture,c,col,transparency);
  addto currentpicture also alphapict_;
enddef;

def alphafill_(expr p,c,col,transparency)=
  begingroup
    save p_,xmax_,xmin_,ymax_,ymin_; picture p_;
    p_=nullpicture;
    (xmin_,ymin_)=llcorner c;(xmax_,ymax_)=urcorner c;
    addto p_ contour c withcolor transparency[background,col];
    for p__ within p:
      numeric xmin__,xmax__,ymin__,ymax__;
      (xmin__,ymin__)=llcorner p__;
      (xmax__,ymax__)=urcorner p__;
      if (xmax__<=xmin_) or (xmin__>=xmax_):
      else:
        if (ymax__<=ymin_) or (ymin__>=ymax_):
        else:
          if (not clipped p__) and (not bounded p__):
            addto p_ also p__ withcolor
            transparency[(redpart p__,greenpart p__,bluepart p__),col];
          else:
            begingroup save alphapict_;
              picture alphapict_; alphapict_ = nullpicture;
              alphafill_(p__,pathpart p__,col,transparency);
              addto p_ also alphapict_;
            endgroup;
          fi
        fi
      fi
    endfor
    clip p_ to c;
    addto alphapict_ also p_;
  endgroup;
enddef;

defaultfont:="ptmr8r";
warningcheck:=0;
beginfig(1)
numeric u;
u=4cm;
fill unitsquare scaled u
                shifted (u,.5u+2u)
                withcolor blue;
unfill unitsquare
       scaled .8u
       shifted (.1u+u,.1u+.5u+2u);
alphafill (unitsquare scaled u
  shifted (u-.2u,2u),(.8,0,.5),.5);
alphafill (fullcircle shifted (.5,.5)
  xscaled .75u  yscaled 1.5u
  shifted (u+.5u,1.75u+.5u),(1,1,0),.5);
fill unitsquare scaled .5u
     shifted (.25u+u,.25u+.5u+2u)
     withcolor green;
alphafill (unitsquare scaled .5u
     shifted (.15u+u,.35u+.5u+2u),(0,.4,.5),.5);
endfig;
end;