| 1 |
%%% addto clip hatchfill hatchfill_ |
| 2 |
%%% numeric color |
| 3 |
%%% length withcolor |
| 4 |
% This is HATCHING.MP file defining a set of METAPOST macros for |
| 5 |
% hatching interior of closed paths. |
| 6 |
% |
| 7 |
% Made in BOP, Gda\'nsk, Poland |
| 8 |
% E-mail contact: [email protected] |
| 9 |
% Public domain software (no copyrights, copylefts, copyups, copydowns, etc.) |
| 10 |
% Current version: 11.07.2000 -- ver 0.1 (pre-release) |
| 11 |
% Current version: 21.09.2000 -- ver 0.11 (ending semicolon |
| 12 |
% added in |extra_beginfig|; |hatchfill_| introduced in order |
| 13 |
% to make possible something like |def fill = hatchfill enddef| |
| 14 |
def hatchfill_ expr c = addto currentpicture contour c _op_ enddef; |
| 15 |
|
| 16 |
vardef hatchfill text p = |
| 17 |
save c_,p_; path p_; color c_[\\]; c_.num:=0; |
| 18 |
save withcolor_; let withcolor_:=withcolor; |
| 19 |
def withcolor = ; c_[incr c_.num]:= enddef; |
| 20 |
p_:=p; let withcolor:=withcolor_; |
| 21 |
for i_:=c_.num downto 1: % find the least ``true'' fill |
| 22 |
c_.num':=i_; exitif bluepart(c_[i_])>0; |
| 23 |
endfor |
| 24 |
if c_.num>0: |
| 25 |
for i_:=c_.num' upto c_.num: |
| 26 |
if bluepart(c_[i_])<0: draw hatched(p_)c_[i_]; |
| 27 |
else: hatchfill_ p_ withcolor c_[i_]; fi |
| 28 |
endfor |
| 29 |
else: hatchfill_ p_; fi |
| 30 |
enddef; |
| 31 |
|
| 32 |
vardef hatched(expr o) primary c = |
| 33 |
save a_, b_, d_, l_, i_, r_, za_, zb_, zc_, zd_; |
| 34 |
path b_; picture r_; pair za_, zb_, zc_, zd_; |
| 35 |
r_:=image( |
| 36 |
a_:=redpart(c) mod 180; l_:=greenpart(c); d_:=-bluepart(c); |
| 37 |
b_:=o rotated -a_; |
| 38 |
b_:=if a_>=90: (lrcorner b_--llcorner b_--ulcorner b_--urcorner b_--cycle) |
| 39 |
else: (llcorner b_--lrcorner b_--urcorner b_--ulcorner b_--cycle) fi |
| 40 |
rotated a_; |
| 41 |
za_:=point 0 of b_; zb_:=point 1 of b_; |
| 42 |
zc_:=point 2 of b_; zd_:=point 3 of b_; |
| 43 |
if hatch_match>0: |
| 44 |
n_:=round(length(zd_-za_)/l_); if n_<2: n_:=2; fi; l_:=length(zd_-za_)/n_; |
| 45 |
else: n_:=length(zd_-za_)/l_; fi |
| 46 |
% show (greenpart(c), l_); |
| 47 |
for i_:=if hatch_match>0: 1 else: 0 fi upto ceiling n_-1: |
| 48 |
draw_hatched_band((i_/n_)[zd_,za_],(i_/n_)[zc_,zb_],a_,l_,d_); |
| 49 |
endfor |
| 50 |
); |
| 51 |
clip r_ to o; r_ |
| 52 |
enddef; |
| 53 |
|
| 54 |
def draw_hatched_band(expr za,zb,a,l,d) = % normally, |a| and |l| are ignored |
| 55 |
draw za--zb withpen pencircle scaled d _hop_; |
| 56 |
enddef; |
| 57 |
|
| 58 |
def hatchoptions(text t) = def _hop_ = t enddef enddef; |
| 59 |
|
| 60 |
newinternal hatch_match; hatch_match:=1; |
| 61 |
hatchoptions(); extra_beginfig:=extra_beginfig & ";hatchoptions();"; |
| 62 |
|
| 63 |
endinput |
| 64 |
%%\end |