File: alphafill.mp

package info (click to toggle)
mlpost 0.8.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,976 kB
  • sloc: ml: 19,575; javascript: 4,047; makefile: 608; ansic: 34; lisp: 19; sh: 15
file content (45 lines) | stat: -rw-r--r-- 1,314 bytes parent folder | download | duplicates (3)
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
% taken from http://wwwmathlabo.univ-poitiers.fr/~phan/metalpha.html
%
picture alphapict_; alphapict_=nullpicture;
color fillcolor; fillcolor=red;
fgalpha := 0.5; % usual alpha parameter
bgalpha:= 1; % alpha parameter with respect to the background

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

def alphafill_(expr p, c) =
  begingroup
    save p_, xmax_, xmin_, ymax_, ymin_; picture p_;
    p_ = nullpicture;
    (xmin_, ymin_) = llcorner c; (xmax_, ymax_) = urcorner c;
    addto p_ contour c withcolor bgalpha[background, fillcolor];
    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
	    fgalpha[(redpart p__, greenpart p__, bluepart p__),
	    fillcolor];
	  else:
	    begingroup save alphapict_;
	      picture alphapict_; alphapict_ = nullpicture;
	      alphafill_(p__, pathpart p__);
	      addto p_ also alphapict_;
	    endgroup;
	  fi
	fi
      fi
    endfor
    clip p_ to c;
    addto alphapict_ also p_;
  endgroup;
enddef;