mp-misc.mpxl /size: 3098 b    last modification: 2025-02-21 11:03
1%D \module
2%D   [       file=mp-misc.mpxl,
3%D        version=2024.03.15,
4%D          title=\CONTEXT\ \METAPOST\ graphics,
5%D       subtitle=anchored background macros,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14%D I moved some code here that was in local files (mostly for documentation)
15%D but this module is not loaded by default.
16
17if known metafun_loaded_misc : endinput ; fi ;
18
19newinternal boolean metafun_loaded_misc ; metafun_loaded_misc := true ; immutable metafun_loaded_misc ;
20
21%D Mikael Sundqvist and I made these when we were playing with envelopes and writing an article
22%D about it.
23
24def showenvelope(expr pth, psh) =
25    image (
26        save e, usedpath, convpath, usedpen ;
27        path e, usedpath, convpath, somepath ; pen usedpen ;
28
29interim linejoin := 1;
30
31        usedpath := psh rotated eps ; % gets rid of bad end condition (rectangle) (introduced close points)
32        usedpen  := makepen(usedpath) ;
33        convpath := convexed usedpath ;
34
35        if cycle pth :
36            enfill
37                pth
38                withpen usedpen
39                withcolor red
40        fi ;
41
42        if cycle pth : fill else : draw fi
43            pth
44            withcolor blue
45            withpen usedpen
46            withtransparency (1,.5)
47        ;
48        drawarrow pth ;
49        drawpoints pth ;
50
51        for i within pth :
52            drawarrow  convpath shifted pathpoint withcolor yellow dashed evenly ;
53            drawarrow  usedpath shifted pathpoint withcolor white;
54            drawpoints usedpath shifted pathpoint withcolor white ;
55        endfor ;
56
57        interim defaultscale := .4 ;
58
59        e := envelope usedpen of pth ;
60        draw            e withcolor green withpen pencircle scaled 1 ; % 1mm;
61        drawpoints      e ;
62        drawpointlabels e withcolor green ;
63
64        e := envelope usedpen of reverse pth ;
65        draw            e withcolor yellow withpen pencircle scaled 1 ; % 1mm;
66        drawpoints      e ;
67        drawpointlabels e withcolor yellow ;
68
69    )
70enddef ;
71
72vardef showreducedenvelope(expr pth, psh, pthtxt, pshtxt) =
73    image (
74        save e, r ; path e, r ;
75        e := envelope psh of pth ;
76        r := reducedenvelope(e) ;
77        draw pth withpen pencircle scaled 2 withcolor "darkgray";
78        draw e withpen pencircle scaled 2 withcolor "darkred" ;
79        drawpoints e withcolor "darkred" ;
80        drawpointlabels e withcolor "darkred" ;
81        draw r withpen pencircle scaled 1 withcolor "darkgreen" ;
82        drawpoints r withpen pencircle scaled 5 withcolor "darkblue" ;
83        drawpointlabels r withcolor "darkblue" ;
84        draw r dashed evenly withcolor "white" ;
85        draw
86            textext.bot ("\strut\tttf path " & pthtxt & " pen " & pshtxt)
87            shifted (center bottomboundary currentpicture)
88            shifted (0,-LineHeight) ;
89        ;
90    )
91enddef ;
92
93% So far for envelopes.
94