mp-back.mpiv /size: 7339 b    last modification: 2021-10-28 13:50
1%D \module
2%D   [       file=mp-back.mp,
3%D        version=2000.05.31,
4%D          title=\CONTEXT\ \METAPOST\ graphics,
5%D       subtitle=backgrounds,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See licen-en.pdf for
12%C details.
13
14if known context_back : endinput ; fi ;
15
16boolean context_back ; context_back := true ;
17
18def some_hash ( expr hash_width     ,
19                     hash_height    ,
20                     hash_linewidth ,
21                     hash_linecolor ,
22                     hash_angle     ,
23                     hash_gap       ) =
24
25    begingroup ;
26        stripe_gap := hash_gap ;
27        stripe_angle := hash_angle ;
28        drawoptions (withpen pencircle scaled hash_linewidth
29                     withcolor hash_linecolor) ;
30        path p ; p := unitsquare xscaled hash_width yscaled hash_height ;
31        stripe_path_a () (draw) p ;  % next we move it all to quadrant 1
32        currentpicture := currentpicture shifted urcorner currentpicture ;
33    endgroup ;
34enddef ;
35
36% \starttext
37%
38% \startMPpage
39%     input "mp-back"
40%
41%     some_double_back (1, 4.5cm, 1.5cm, .25cm, 1mm, .5white, .8white, .7white, .6white, .7white, .6white) currentpicture := currentpicture shifted (0,-3cm) ;
42%     some_double_back (2, 4.5cm, 1.5cm, .25cm, 1mm, .5white, .8white, .7white, .6white,   white,   white) currentpicture := currentpicture shifted (0,-3cm) ;
43%     some_double_back (3, 4.5cm, 1.5cm, .25cm, 1mm, .5white, .8white, .7white,  white,    white,   white) currentpicture := currentpicture shifted (0,-3cm) ;
44%     some_double_back (4, 4.5cm, 1.5cm, .25cm, 1mm, .5white, .8white, .7white,  white,    white,   white) currentpicture := currentpicture shifted (0,-3cm) ;
45%     some_double_back (5, 4.5cm, 1.5cm, .25cm, 1mm, .5white, .8white, .7white,  white,    white,   white) currentpicture := currentpicture shifted (0,-3cm) ;
46%     some_double_back (6, 4.5cm, 1.5cm, .25cm, 1mm, .5white, .8white, .7white,  white,    white,   white) currentpicture := currentpicture shifted (0,-3cm) ;
47%     some_double_back (7, 4.5cm, 1.5cm, .25cm, 1mm, .5white, .8white, .7white,  white,    white,   white) currentpicture := currentpicture shifted (0,-3cm) ;
48%     some_double_back (8, 4.5cm, 1.5cm, .25cm, 1mm, .5white, .8white, .7white,  white,    white,   white)
49% \stopMPpage
50
51% \stoptext
52
53def some_double_back (expr back_type        ,
54                           back_width       ,
55                           back_height      ,
56                           back_delta       ,
57                           back_linewidth   ,
58                           back_linecolor   ,
59                           back_fillcolor   ,
60                           back_topcolor    ,
61                           back_bottomcolor ,
62                           back_leftcolor   ,
63                           back_rightcolor  ) =
64
65    begingroup ;
66
67    save ww, hh, dd, p, q, r, s, t, u, v, w, a, c, d, e, f, back_nillcolor ;
68
69    numeric ww ; ww := back_width  ;
70    numeric hh ; hh := back_height ;
71    numeric dd ; dd := back_delta  ;
72
73    color back_nillcolor ; back_nillcolor := back_topcolor ;
74
75    path p ; p := fullsquare xscaled  ww      yscaled  hh      ;
76    path q ; q := fullsquare xscaled (ww-2dd) yscaled (hh-2dd) ;
77    path r ; r := llcorner p --
78                  lrcorner p shifted (-3dd,0) .. controls lrcorner p ..
79                  lrcorner p shifted (0, 3dd) --
80                  urcorner p shifted (0,-3dd) .. controls urcorner p ..
81                  urcorner p shifted (-3dd,0) --
82                  ulcorner p -- cycle ;
83    path s ; s := r xscaled ((ww-2dd)/ww) yscaled ((hh-2dd)/hh) ;
84    path t ; t := llcorner p --
85                  lrcorner p --
86                  urcorner p shifted (0,-3dd) .. controls urcorner p ..
87                  urcorner p shifted (-3dd,0) --
88                  ulcorner p shifted ( 3dd,0) .. controls ulcorner p ..
89                  ulcorner p shifted (0,-3dd) --
90                  llcorner p -- cycle ;
91    path u ; u := t xscaled ((ww-2dd)/ww) yscaled ((hh-2dd)/hh) ;
92    path v ; v := llcorner p shifted ( 3dd,0) --
93                  lrcorner p shifted (-3dd,0) .. controls lrcorner p ..
94                  lrcorner p shifted (0, 3dd) --
95                  urcorner p shifted (0,-3dd) .. controls urcorner p ..
96                  urcorner p shifted (-3dd,0) --
97                  ulcorner p shifted ( 3dd,0) .. controls ulcorner p ..
98                  ulcorner p shifted (0,-3dd) ..
99                  llcorner p shifted (0, 3dd) .. controls llcorner p .. cycle ; % {down}  .. cycle ;
100    path w ; w := t xscaled ((ww-2dd)/ww) yscaled ((hh-2dd)/hh) ;
101    path a ; a := llcorner p -- ulcorner p --
102                  ulcorner q -- llcorner q -- cycle ;
103    path b ; b := llcorner p -- lrcorner p --
104                  lrcorner q -- llcorner q -- cycle ;
105    path c ; c := lrcorner p -- urcorner p --
106                  urcorner q -- lrcorner q -- cycle ;
107    path d ; d := ulcorner p -- urcorner p --
108                  urcorner q -- ulcorner q -- cycle ;
109    path e ; e := llcorner p -- lrcorner p --
110                  urcorner p -- urcorner q --
111                  lrcorner q -- llcorner q -- cycle ;
112    path f ; f := llcorner p -- ulcorner p --
113                  urcorner p -- urcorner q --
114                  ulcorner q -- llcorner q -- cycle ;
115
116    linecap := butt ; pickup pencircle scaled back_linewidth ;
117
118    if back_type = 1 :
119
120      fill p withcolor back_fillcolor   ;
121      fill a withcolor back_leftcolor   ;
122      fill b withcolor back_bottomcolor ;
123      fill c withcolor back_rightcolor  ;
124      fill d withcolor back_topcolor    ;
125      draw a withcolor back_linecolor   ;
126      draw d withcolor back_linecolor   ;
127      draw b withcolor back_linecolor   ;
128      draw c withcolor back_linecolor   ;
129
130    elseif back_type = 2 :
131
132      fill p withcolor back_fillcolor   ;
133      fill e withcolor back_bottomcolor ;
134      fill f withcolor back_topcolor    ;
135      draw e withcolor back_linecolor   ;
136      draw f withcolor back_linecolor   ;
137
138    elseif back_type = 3 :
139
140      fill v withcolor back_nillcolor   ;
141      fill w withcolor back_fillcolor   ;
142      draw v withcolor back_linecolor   ;
143      draw w withcolor back_linecolor   ;
144
145    elseif back_type = 4 :
146
147      fill t withcolor back_nillcolor   ;
148      fill u withcolor back_fillcolor   ;
149      draw t withcolor back_linecolor   ;
150      draw u withcolor back_linecolor   ;
151
152    elseif back_type = 5 :
153
154      t := t rotatedaround(center t,180) ;
155      u := u rotatedaround(center u,180) ;
156
157      fill t withcolor back_nillcolor   ;
158      fill u withcolor back_fillcolor   ;
159      draw t withcolor back_linecolor   ;
160      draw u withcolor back_linecolor   ;
161
162    elseif back_type = 6 :
163
164      r := r rotatedaround(center r,180) ;
165      s := s rotatedaround(center s,180) ;
166
167      fill r withcolor back_nillcolor   ;
168      fill s withcolor back_fillcolor   ;
169      draw r withcolor back_linecolor   ;
170      draw s withcolor back_linecolor   ;
171
172    elseif back_type = 7 :
173
174      fill r withcolor back_nillcolor   ;
175      fill s withcolor back_fillcolor   ;
176      draw r withcolor back_linecolor   ;
177      draw s withcolor back_linecolor   ;
178
179    fi ;
180
181    endgroup;
182enddef ;
183