luametafun-shade.tex /size: 6601 b    last modification: 2021-10-28 13:50
1% language=us runpath=texruns:manuals/luametafun
2
3\environment luametafun-style
4
5\startcomponent luametafun-shade
6
7\startchapter[title={Shade}]
8
9{\em This interface is still experimental!}
10
11Shading is complex. We go from one color to another on a continuum either linear
12or circular. We have to make sure that we cover the whole shape and that means
13that we have to guess a little, although one can influence this with parameters.
14It can involve a bit of trial and error, which is more complex that using a
15graphical user interface but this is the price we pay. It goes like this:
16
17\startbuffer[1]
18\startMPcode
19definecolor [ name = "MyColor3", r = 0.22, g = 0.44, b = 0.66 ] ;
20definecolor [ name = "MyColor4", r = 0.66, g = 0.44, b = 0.22 ] ;
21
22draw lmt_shade [
23    path      = fullcircle scaled 4cm,
24    direction = "right",
25    domain    = { 0, 2 },
26    colors    = { "MyColor3", "MyColor4" },
27] ;
28
29draw lmt_shade [
30    path      = fullcircle scaled 3cm,
31    direction = "left",
32    domain    = { 0, 2 },
33    colors    = { "MyColor3", "MyColor4" },
34] shifted (45mm,0) ;
35
36draw lmt_shade [
37    path      = fullcircle scaled 5cm,
38    direction = "up",
39    domain    = { 0, 2 },
40    colors    = { "MyColor3", "MyColor4" },
41] shifted (95mm,0) ;
42
43draw lmt_shade [
44    path      = fullcircle scaled 1cm,
45    direction = "down",
46    domain    = { 0, 2 },
47    colors    = { "MyColor3", "MyColor4" },
48] shifted (135mm,0) ;
49\stopMPcode
50\stopbuffer
51
52\typebuffer[1][option=TEX]
53
54Normally this is good enough as demonstrated in \in {figure} [shade:1] because
55we use shades as backgrounds. In the case of a circular shade we need to tweak
56the domain because guessing doesn't work well.
57
58\startplacefigure[reference=shade:1,title={Simple circular shades.}]
59    \getbuffer[1]
60\stopplacefigure
61
62\startbuffer[2]
63\startMPcode
64draw lmt_shade [
65    path        = fullsquare scaled 4cm,
66    alternative = "linear",
67    direction   = "right",
68    colors      = { "MyColor3", "MyColor4" },
69] ;
70
71draw lmt_shade [
72    path        = fullsquare scaled 3cm,
73    direction   = "left",
74    alternative = "linear",
75    colors      = { "MyColor3", "MyColor4" },
76] shifted (45mm,0) ;
77
78draw lmt_shade [
79    path        = fullsquare scaled 5cm,
80    direction   = "up",
81    alternative = "linear",
82    colors      = { "MyColor3", "MyColor4" },
83] shifted (95mm,0) ;
84
85draw lmt_shade [
86    path        = fullsquare scaled 1cm,
87    direction   = "down",
88    alternative = "linear",
89    colors      = { "MyColor3", "MyColor4" },
90] shifted (135mm,0) ;
91\stopMPcode
92\stopbuffer
93
94\typebuffer[2][option=TEX]
95
96\startplacefigure[reference=shade:2,title={Simple rectangular shades.}]
97    \getbuffer[2]
98\stopplacefigure
99
100The \type {direction} relates to the boundingbox. Instead of a keyword you can
101also give two values, indicating points on the boundingbox. Because a boundingbox
102has four points, the \type {up} direction is equivalent to \type {{0.5,2.5}}.
103
104The parameters \type {center}, \type {factor}, \type {vector} and \type {domain}
105are a bit confusing but at some point the way they were implemented made sense,
106so we keep them as they are. The center moves the center of the path that is used
107as anchor for one color proportionally to the bounding box: the given factor is
108multiplied by half the width and height.
109
110\startbuffer[3]
111\startMPcode
112draw lmt_shade [
113    path      = fullcircle scaled 5cm,
114    domain    = { .2, 1.6 },
115    center    = { 1/10, 1/10 },
116    direction = "right",
117    colors    = { "MyColor3", "MyColor4" },
118    trace     = true,
119] ;
120\stopMPcode
121\stopbuffer
122
123\typebuffer[3][option=TEX]
124
125\startplacefigure[reference=shade:3,title={Moving the centers.}]
126    \getbuffer[3]
127\stopplacefigure
128
129A vector takes the given points on the path as centers for the colors, see \in
130{figure} [shade:4].
131
132\startbuffer[4]
133\startMPcode
134draw lmt_shade [
135    path      = fullcircle scaled 5cm,
136    domain    = { .2, 1.6 },
137    vector    = { 2, 4 },
138    direction = "right",
139    colors    = { "MyColor3", "MyColor4" },
140    trace     = true,
141] ;
142\stopMPcode
143\stopbuffer
144
145\typebuffer[4][option=TEX]
146
147\startplacefigure[reference=shade:4,title={Using a vector (points).}]
148    \getbuffer[4]
149\stopplacefigure
150
151Messing with the radius in combination with the previously mentioned domain
152is really trial and error, as seen in \in {figure} [shade:5].
153
154\startbuffer[5]
155\startMPcode
156draw lmt_shade [
157    path      = fullcircle scaled 5cm,
158    domain    = { 0.5, 2.5 },
159    radius    = { 2cm, 6cm },
160    direction = "right",
161    colors    = { "MyColor3", "MyColor4" },
162    trace     = true,
163] ;
164\stopMPcode
165\stopbuffer
166
167\typebuffer[5][option=TEX]
168
169\startplacefigure[reference=shade:5,title={Tweaking the radius.}]
170    \getbuffer[5]
171\stopplacefigure
172
173But actually the radius used alone works quite well as shown in \in {figure}
174[shade:6].
175
176\startbuffer[6]
177\startMPcode
178draw lmt_shade [
179    path        = fullcircle scaled 5cm,
180    colors      = { "red", "green" },
181    trace       = true,
182] ;
183
184draw lmt_shade [
185    path        = fullcircle scaled 5cm,
186    colors      = { "red", "green" },
187    radius      = 2.5cm,
188    trace       = true,
189] shifted (6cm,0) ;
190
191draw lmt_shade [
192    path        = fullcircle scaled 5cm,
193    colors      = { "red", "green" },
194    radius      = 2.0cm,
195    trace       = true,
196] shifted (12cm,0) ;
197\stopMPcode
198\stopbuffer
199
200\typebuffer[6][option=TEX]
201
202\startplacefigure[reference=shade:6,title={Just using the radius.}]
203    \getbuffer[6]
204\stopplacefigure
205
206\starttabulate[|T|T|T|p|]
207\FL
208\BC name         \BC type           \BC default      \BC comment \NC \NR
209\ML
210\NC alternative \NC string          \NC circular \NC or \type {linear} \NC \NR
211\NC path        \NC path            \NC          \NC \NC \NR
212\NC trace       \NC boolean         \NC false    \NC \NC \NR
213\NC domain      \NC set of numerics \NC          \NC \NC \NR
214\NC radius      \NC numeric         \NC          \NC \NC \NR
215\NC             \NC set of numerics \NC          \NC \NC \NR
216\NC factor      \NC numeric         \NC          \NC \NC \NR
217\NC origin      \NC pair            \NC          \NC \NC \NR
218\NC             \NC set of pairs    \NC          \NC \NC \NR
219\NC vector      \NC set of numerics \NC          \NC \NC \NR
220\NC colors      \NC set of strings  \NC          \NC \NC \NR
221\NC center      \NC numeric         \NC          \NC \NC \NR
222\NC             \NC set of numerics \NC          \NC \NC \NR
223\NC direction   \NC string          \NC          \NC \type{up}, \type {down}, \type {left}, \type {right} \NC \NR
224\NC             \NC set of numerics \NC          \NC two points on the boundingbox \NC \NR
225\LL
226\stoptabulate
227
228\stopchapter
229
230\stopcomponent
231