summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/manuals/luametafun/luametafun-shade.tex
blob: a139be95460cc25ba02e5d8aef02d92ac0c5f73b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
% language=us

\environment luametafun-style

\startcomponent luametafun-shade

\startchapter[title={Shade}]

{\em This interface is still experimental!}

Shading is complex. We go from one color to another on a continuum either linear
or circular. We have to make sure that we cover the whole shape and that means
that we have to guess a little, although one can influence this with parameters.
It can involve a bit of trial and error, which is more complex that using a
graphical user interface but this is the price we pay. It goes like this:

\startbuffer[1]
\startMPcode
definecolor [ name = "MyColor3", r = 0.22, g = 0.44, b = 0.66 ] ;
definecolor [ name = "MyColor4", r = 0.66, g = 0.44, b = 0.22 ] ;

draw lmt_shade [
    path      = fullcircle scaled 4cm,
    direction = "right",
    domain    = { 0, 2 },
    colors    = { "MyColor3", "MyColor4" },
] ;

draw lmt_shade [
    path      = fullcircle scaled 3cm,
    direction = "left",
    domain    = { 0, 2 },
    colors    = { "MyColor3", "MyColor4" },
] shifted (45mm,0) ;

draw lmt_shade [
    path      = fullcircle scaled 5cm,
    direction = "up",
    domain    = { 0, 2 },
    colors    = { "MyColor3", "MyColor4" },
] shifted (95mm,0) ;

draw lmt_shade [
    path      = fullcircle scaled 1cm,
    direction = "down",
    domain    = { 0, 2 },
    colors    = { "MyColor3", "MyColor4" },
] shifted (135mm,0) ;
\stopMPcode
\stopbuffer

\typebuffer[1][option=TEX]

Normally this is good enough as demonstrated in \in {figure} [shade:1] because
we use shades as backgrounds. In the case of a circular shade we need to tweak
the domain because guessing doesn't work well.

\startplacefigure[reference=shade:1,title={Simple circular shades.}]
    \getbuffer[1]
\stopplacefigure

\startbuffer[2]
\startMPcode
draw lmt_shade [
    path        = fullsquare scaled 4cm,
    alternative = "linear",
    direction   = "right",
    colors      = { "MyColor3", "MyColor4" },
] ;

draw lmt_shade [
    path        = fullsquare scaled 3cm,
    direction   = "left",
    alternative = "linear",
    colors      = { "MyColor3", "MyColor4" },
] shifted (45mm,0) ;

draw lmt_shade [
    path        = fullsquare scaled 5cm,
    direction   = "up",
    alternative = "linear",
    colors      = { "MyColor3", "MyColor4" },
] shifted (95mm,0) ;

draw lmt_shade [
    path        = fullsquare scaled 1cm,
    direction   = "down",
    alternative = "linear",
    colors      = { "MyColor3", "MyColor4" },
] shifted (135mm,0) ;
\stopMPcode
\stopbuffer

\typebuffer[2][option=TEX]

\startplacefigure[reference=shade:2,title={Simple rectangular shades.}]
    \getbuffer[2]
\stopplacefigure

The \type {direction} relates to the boundingbox. Instead of a keyword you can
also give two values, indicating points on the boundingbox. Because a boundingbox
has four points, the \type {up} direction is equivalent to \type {{0.5,2.5}}.

The parameters \type {center}, \type {factor}, \type {vector} and \type {domain}
are a bit confusing but at some point the way they were implemented made sense,
so we keep them as they are. The center moves the center of the path that is used
as anchor for one color proportionally to the bounding box: the given factor is
multiplied by half the width and height.

\startbuffer[3]
\startMPcode
draw lmt_shade [
    path      = fullcircle scaled 5cm,
    domain    = { .2, 1.6 },
    center    = { 1/10, 1/10 },
    direction = "right",
    colors    = { "MyColor3", "MyColor4" },
    trace     = true,
] ;
\stopMPcode
\stopbuffer

\typebuffer[3][option=TEX]

\startplacefigure[reference=shade:3,title={Moving the centers.}]
    \getbuffer[3]
\stopplacefigure

A vector takes the given points on the path as centers for the colors, see \in
{figure} [shade:4].

\startbuffer[4]
\startMPcode
draw lmt_shade [
    path      = fullcircle scaled 5cm,
    domain    = { .2, 1.6 },
    vector    = { 2, 4 },
    direction = "right",
    colors    = { "MyColor3", "MyColor4" },
    trace     = true,
] ;
\stopMPcode
\stopbuffer

\typebuffer[4][option=TEX]

\startplacefigure[reference=shade:4,title={Using a vector (points).}]
    \getbuffer[4]
\stopplacefigure

Messing with the radius in combination with the previously mentioned domain
is really trial and error, as seen in \in {figure} [shade:5].

\startbuffer[5]
\startMPcode
draw lmt_shade [
    path      = fullcircle scaled 5cm,
    domain    = { 0.5, 2.5 },
    radius    = { 2cm, 6cm },
    direction = "right",
    colors    = { "MyColor3", "MyColor4" },
    trace     = true,
] ;
\stopMPcode
\stopbuffer

\typebuffer[5][option=TEX]

\startplacefigure[reference=shade:5,title={Tweaking the radius.}]
    \getbuffer[5]
\stopplacefigure

But actually the radius used alone works quite well as shown in \in {figure}
[shade:6].

\startbuffer[6]
\startMPcode
draw lmt_shade [
    path        = fullcircle scaled 5cm,
    colors      = { "red", "green" },
    trace       = true,
] ;

draw lmt_shade [
    path        = fullcircle scaled 5cm,
    colors      = { "red", "green" },
    radius      = 2.5cm,
    trace       = true,
] shifted (6cm,0) ;

draw lmt_shade [
    path        = fullcircle scaled 5cm,
    colors      = { "red", "green" },
    radius      = 2.0cm,
    trace       = true,
] shifted (12cm,0) ;
\stopMPcode
\stopbuffer

\typebuffer[6][option=TEX]

\startplacefigure[reference=shade:6,title={Just using the radius.}]
    \getbuffer[6]
\stopplacefigure

\starttabulate[|T|T|T|p|]
\FL
\BC name         \BC type           \BC default      \BC comment \NC \NR
\ML
\NC alternative \NC string          \NC circular \NC or \type {linear} \NC \NR
\NC path        \NC path            \NC          \NC \NC \NR
\NC trace       \NC boolean         \NC false    \NC \NC \NR
\NC domain      \NC set of numerics \NC          \NC \NC \NR
\NC radius      \NC numeric         \NC          \NC \NC \NR
\NC             \NC set of numerics \NC          \NC \NC \NR
\NC factor      \NC numeric         \NC          \NC \NC \NR
\NC origin      \NC pair            \NC          \NC \NC \NR
\NC             \NC set of pairs    \NC          \NC \NC \NR
\NC vector      \NC set of numerics \NC          \NC \NC \NR
\NC colors      \NC set of strings  \NC          \NC \NC \NR
\NC center      \NC numeric         \NC          \NC \NC \NR
\NC             \NC set of numerics \NC          \NC \NC \NR
\NC direction   \NC string          \NC          \NC \type{up}, \type {down}, \type {left}, \type {right} \NC \NR
\NC             \NC set of numerics \NC          \NC two points on the boundingbox \NC \NR
\LL
\stoptabulate

\stopchapter

\stopcomponent