meta-lua.mkiv /size: 3220 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=meta-lua,
3
%D version=2012.07.23,
4
%D title=\METAPOST\ Integrated Graphics,
5
%D subtitle=Templates,
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 Don't use this code yet. I use it in some experimental rendering of graphics
15
%D based on output from database queries. It's not that pretty but will be
16
%D considered when the (similar) lmx code is redone. Also, dropping the print
17
%D variant makes it nicer. This experiment is part of playing with several template
18
%D mechanisms. (Also see trac-lmx.)
19
%D
20
%D Note for myself: see if the (bar)chart code use in q2p can use this kind of
21
%D magic. Basically we then need a channel to data.
22 23
\writestatus
{
loading
}{
MetaPost
Library
Graphics
/
Templates
}
24 25
\registerctxluafile
{
meta
-
lua
}{}
26 27
\continueifinputfile
{
meta
-
lua
.
mkiv
}
28 29
\starttext
30 31
% conforming btex ... etex
32 33
\startbuffer
[
test
-
a
]
34
blua
for
i
=
1
,
1
0
0
,
5
do
elua
35
draw
fullcircle
scaled
(
blua
p
(
i
)
elua
*
cm
)
withcolor
green
withpen
pencircle
scaled
4
;
36
blua
end
elua
37 38
blua
for
i
=
1
,
1
0
0
,
1
0
do
elua
39
draw
fullcircle
scaled
(
blua
p
(
i
)
elua
*
cm
)
withcolor
red
withpen
pencircle
scaled
2
;
40
blua
end
elua
41
\stopbuffer
42 43
\startMPpage
[
offset
=
10
pt
]
44
input
"
mpstemplate://buffer?name=test-a
"
;
45
\stopMPpage
46 47
% conforming lmx
48 49
\startbuffer
[
test
-
b
]
50
<?lua
for
i
=
1
,
100
,
5
do
?>
51
draw
fullcircle
scaled
(<
?
lua
p
(
i
)
?
>
*
cm
)
withcolor
green
withpen
pencircle
scaled
4
;
52
<?lua
end
?>
53 54
<?lua
for
i
=
1
,
100
,
10
do
?>
55
draw
fullcircle
scaled
(<
?
lua
p
(
i
)
?
>
*
cm
)
withcolor
red
withpen
pencircle
scaled
2
;
56
<?lua
end
?>
57
\stopbuffer
58 59
\startMPpage
[
offset
=
10
pt
]
60
input
"
mpstemplate://buffer?name=test-b
"
;
61
\stopMPpage
62 63
\startMPpage
[
offset
=
10
pt
]
64
picture
p
[
]
;
% we can't input nested
65
input
"
mpstemplate://buffer?name=test-a&method=metapost
"
;
66
p
[
1
]
:
=
currentpicture
;
currentpicture
:
=
nullpicture
;
67
input
"
mpstemplate://buffer?name=test-b&method=xml
"
;
68
p
[
2
]
:
=
currentpicture
;
currentpicture
:
=
nullpicture
;
69
draw
p
[
1
]
ysized
3
cm
;
70
draw
p
[
2
]
ysized
4
cm
shifted
(
4
cm
,
0
)
;
71
\stopMPpage
72 73
% a mixture (using a wrapped input)
74 75
\startMPpage
[
offset
=
10
pt
]
76
draw
image
(
loadfile
(
"
mpstemplate://buffer?name=test-a&method=metapost
"
)
)
ysized
3
cm
shifted
(
4
cm
,
0
cm
)
;
77
draw
image
(
loadfile
(
"
mpstemplate://buffer?name=test-b&method=xml
"
)
)
ysized
3
cm
shifted
(
0
cm
,
4
cm
)
;
78
draw
loadimage
(
"
mpstemplate://buffer?name=test-a&method=metapost
"
)
ysized
4
cm
shifted
(
4
cm
,
4
cm
)
;
79
draw
loadimage
(
"
mpstemplate://buffer?name=test-b&method=xml
"
)
ysized
4
cm
shifted
(
0
cm
,
0
cm
)
;
80
\stopMPpage
81 82
% conforming myself
83 84
\startluacode
85
context
.
startMPpage
{
offset
=
"
10pt
"
}
86
for
i
=
1
,
100
,
5
do
87
context
(
"
draw fullcircle scaled (%s * cm) withcolor green withpen pencircle scaled 4 ;
"
,
i
)
88
end
89
for
i
=
1
,
100
,
10
do
90
context
(
"
draw fullcircle scaled (%s * cm) withcolor red withpen pencircle scaled 2 ;
"
,
i
)
91
end
92
context
.
stopMPpage
(
)
93
\stopluacode
94 95
\stoptext
96