luametafun-arrow.tex /size: 4299 b    last modification: 2021-10-28 13:50
1% language=us runpath=texruns:manuals/luametafun
2
3\environment luametafun-style
4
5\startcomponent luametafun-arrow
6
7\startchapter[title={Arrow}]
8
9Arrows are somewhat complicated because they follow the path, are constructed
10using a pen, have a fill and draw, and need to scale. One problem is that the
11size depends on the pen but the pen normally is only known afterwards.
12
13\startbuffer[1a]
14\startMPcode
15draw lmt_arrow [
16    path = (fullcircle scaled 3cm),
17]
18    withpen pencircle scaled 2mm
19    withcolor "darkred" ;
20\stopMPcode
21\stopbuffer
22
23\startbuffer[1b]
24\startMPcode
25draw lmt_arrow [
26    path   = (fullcircle scaled 3cm),
27    length = 8,
28]
29    withpen pencircle scaled 2mm
30    withcolor "darkgreen" ;
31\stopMPcode
32\stopbuffer
33
34\startbuffer[1c]
35\startMPcode
36draw lmt_arrow [
37    path = (fullcircle scaled 3cm rotated 145),
38    pen  = (pencircle xscaled 4mm yscaled 2mm rotated 45),
39]
40    withpen pencircle xscaled 1mm yscaled .5mm rotated 45
41    withcolor "darkblue" ;
42\stopMPcode
43\stopbuffer
44
45\startbuffer[1d]
46\startMPcode
47pickup pencircle xscaled 2mm yscaled 1mm rotated 45 ;
48draw lmt_arrow [
49    path = (fullcircle scaled 3cm rotated 45),
50    pen  = "auto",
51]
52    withcolor "darkyellow" ;
53\stopMPcode
54\stopbuffer
55
56To some extent \METAFUN\ can help you with this issue. In \in {figure} [arrows:1]
57we see some variants. The definitions are given below:
58
59\typebuffer[1a][option=TEX]
60\typebuffer[1b][option=TEX]
61\typebuffer[1c][option=TEX]
62\typebuffer[1d][option=TEX]
63
64\startplacefigure[reference=arrows:1]
65    \startcombination[4*1]
66        {\getbuffer[1a]} {default}
67        {\getbuffer[1b]} {length}
68        {\getbuffer[1c]} {pen}
69        {\getbuffer[1d]} {auto}
70    \stopcombination
71\stopplacefigure
72
73There are some options that influence the shape of the arrowhead and its
74location on the path. You can for instance ask for two arrowheads:
75
76\startbuffer[3]
77\startMPcode
78    pickup pencircle scaled 1mm ;
79    draw lmt_arrow [
80        pen      = "auto",
81        location = "both"
82        path     = fullcircle scaled 3cm rotated 90,
83    ] withcolor "darkgreen" ;
84\stopMPcode
85\stopbuffer
86
87\typebuffer[3][option=TEX]
88
89\startlinecorrection
90\getbuffer[3]
91\stoplinecorrection
92
93The shape can also be influenced although often this is not that visible:
94
95\startbuffer[4]
96\startMPcode
97    pickup pencircle scaled 1mm ;
98    draw lmt_arrow [
99        kind        = "draw",
100        pen         = "auto",
101        penscale    = 4,
102        location    = "middle",
103        alternative = "curved",
104        path        = fullcircle scaled 3cm,
105    ] withcolor "darkblue" ;
106\stopMPcode
107\stopbuffer
108
109\typebuffer[4][option=TEX]
110
111\startlinecorrection
112\getbuffer[4]
113\stoplinecorrection
114
115The location can also be given as percentage, as this example demonstrates. Watch
116how we draw only arrow heads:
117
118\startbuffer[5]
119\startMPcode
120    pickup pencircle scaled 1mm ;
121    for i = 0 step 5 until 100 :
122        draw lmt_arrow [
123            alternative = "dimpled",
124            pen         = "auto",
125            location    = "percentage",
126            percentage  = i,
127            dimple      = (1/5 + i/200),
128            headonly    = (i = 0),
129            path        = fullcircle scaled 3cm,
130        ] withcolor "darkyellow" ;
131    endfor ;
132\stopMPcode
133\stopbuffer
134
135\typebuffer[5][option=TEX]
136
137\startlinecorrection
138\getbuffer[5]
139\stoplinecorrection
140
141The supported parameters are:
142
143\starttabulate[|T|T|T|p|]
144\FL
145\BC name        \BC type    \BC default \BC comment \NC \NR
146\ML
147\NC path        \NC path    \NC        \NC \NC \NR
148\NC pen         \NC path    \NC        \NC \NC \NR
149\NC             \NC string  \NC auto   \NC \NC \NR
150\NC kind        \NC string  \NC fill   \NC \type {fill} or \type {draw} \NC \NR
151\NC dimple      \NC numeric \NC 1/5    \NC \NC \NR
152\NC scale       \NC numeric \NC 3/4    \NC \NC \NR
153\NC penscale    \NC numeric \NC 3      \NC \NC \NR
154\NC length      \NC numeric \NC 4      \NC \NC \NR
155\NC angle       \NC numeric \NC 45     \NC \NC \NR
156\NC location    \NC string  \NC end    \NC \type {end}, \type {middle} or \type {both} \NC \NR  % middle both
157\NC alternative \NC string  \NC normal \NC \type {normal}, \type {dimpled} or \type {curved} \NC \NR
158\NC percentage  \NC numeric \NC 50     \NC \NC \NR
159\NC headonly    \NC boolean \NC false  \NC \NC \NR
160\LL
161\stoptabulate
162
163\stopchapter
164
165\stopcomponent
166
167