meta-grd.mkxl /size: 3146 b    last modification: 2021-10-28 13:51
1%D \module
2%D   [       file=meta-grd,
3%D        version=2012.06.28,
4%D          title=\METAPOST\ Graphics,
5%D       subtitle=grids,
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\writestatus{loading}{MetaPost Graphics / Grids}
15
16\unprotect
17
18%D This used to be a \TEX\ method, and a rather old one too. We keep it around but
19%D in a more modern way.
20%D
21%D \startbuffer
22%D \basegrid
23%D   [nx=8,ny=5,
24%D    dx=.5,dy=.25,
25%D    unit=cm,scale=2,factor=1,
26%D    offset=1ex,xstep=2,ystep=1,
27%D    align=middle,style=\tt\tx]
28%D \stopbuffer
29%D
30%D \typebuffer
31%D
32%D \placefigure
33%D   {An example of a grid.}
34%D   {\getbuffer}
35
36\startuseMPgraphic{meta:grd:basegrid}
37    begingroup ;
38
39        save nx, ny, dx, dy, ox, oy, sx, sy ;
40
41        sc := \directdummyparameter\c!factor*\directdummyparameter\c!scale ;
42        nx := \directdummyparameter\c!nx ;
43        ny := \directdummyparameter\c!ny ;
44        dx := \MPdpar\directdummyparameter\c!dx * sc ;
45        dy := \MPdpar\directdummyparameter\c!dy * sc ;
46        ox := \MPdpar\directdummyparameter\c!xoffset ;
47        oy := \MPdpar\directdummyparameter\c!yoffset ;
48        sx := \directdummyparameter\c!xstep ;
49        sy := \directdummyparameter\c!ystep ;
50
51        if "\directdummyparameter\c!align" = "\v!middle" :
52            ax := dx / 2 ;
53            ay := dy / 2 ;
54        else :
55            ax := 0 ;
56            ay := 0 ;
57        fi ;
58
59        draw lmt_grid [ nx = nx, ny = ny, dx = 1, dy = 1 ]
60            xyscaled (dx,dy) shifted (ax, ay)
61            withpen pencircle scaled \MPdpar\directdummyparameter\c!rulethickness\space
62            withcolor "\directdummyparameter\c!rulecolor" ;
63
64        draw image (
65            if sx > 0 :
66                for i=1 step sx until nx :
67                    draw thetextext.bot(decimal i,(i*dx-ax,oy));
68                endfor ;
69            fi ;
70            if sy > 0 :
71                for i=1 step sy until ny :
72                    draw thetextext.lft(decimal i,(ox,i*dy-ay)) ;
73                endfor ;
74            fi ;
75        )
76            withcolor "\directdummyparameter\c!color" ;
77
78    endgroup ;
79\stopuseMPgraphic
80
81\permanent\tolerant\protected\def\basegrid[#1]%
82  {\dontleavehmode
83   \hbox\bgroup
84   \getdummyparameters
85     [\c!nx=10,\c!ny=10,%
86      \c!dx=.5,\c!dy=.5,%
87      \c!xstep=0,\c!ystep=0,%
88      \c!unit=\s!cm,\c!scale=1,\c!factor=1,%
89      \c!offset=.25\exheight,%
90      \c!xoffset=\directdummyparameter\c!offset,%
91      \c!yoffset=\directdummyparameter\c!offset,%
92      \c!align=,%
93      \c!color=\currentcolorname,%
94      \c!rulecolor=\currentcolorname,%
95      \c!rulethickness=\linewidth,%
96      #1]%
97   \usedummystyleandcolor\c!style\c!color
98   \setexpandeddummyparameter\c!dx{\directdummyparameter\c!dx\directdummyparameter\c!unit}%
99   \setexpandeddummyparameter\c!dy{\directdummyparameter\c!dy\directdummyparameter\c!unit}%
100   \useMPgraphic{meta:grd:basegrid}%
101   \egroup}
102
103\aliased\let\grid\basegrid
104
105\protect \endinput
106