Changes

Jump to navigation Jump to search
1,888 bytes added ,  09:16, 22 June 2020
Created page with "In Metapost (or rather in Metafun) one can define arrays of colors, strings, paths, pens and other variables. An example is the following: <texcode> \starttext \startMPpage s..."
In Metapost (or rather in Metafun) one can define arrays of colors, strings, paths, pens and other variables.
An example is the following:
<texcode>
\starttext
\startMPpage
string MyColors[] ;
path MyPaths [] ;
pen MyPens[] ;
for j = -1 step 1 until 3 :
MyPens[j] := pencircle scaled ((2+j)*pt) ;
endfor
MyPaths[-1] := (-1.5cm,1.5cm) -- (1.5cm,1.5cm) ; MyColors[-1] := "magenta" ;
MyPaths[0] := (-2cm,2cm) -- (2*cos(0)*cm,-2cm) ; MyColors[0] := "darkyellow" ;
MyPaths[1] := fullcircle scaled 3cm ; MyColors[1] := "darkred" ;
MyPaths[2] := fullsquare scaled 2cm ; MyColors[2] := "darkgreen" ;
MyPaths[3] := (-2cm,-2cm) -- (2cm,2cm) ; MyColors[3] := "darkblue" ;

for j = -1 step 1 until 3 :
draw MyPaths[j] withpen MyPens[j] withcolor MyColors[j] ;
endfor
\stopMPpage
\stoptext
</texcode>
In the above example, instead of
<texcode>
string MyColors[] ;
</texcode>
one could have said
<texcode>
color MyColors[] ;
</texcode>
and then we should have defined each component of {{code|1=MyColors}} as colors instead of strings:
<texcode>
\starttext
\startMPpage
color MyColors[] ;
path MyPaths [] ;
pen MyPens[] ;
for j = -1 step 1 until 3 :
MyPens[j] := pencircle scaled ((2+j)*pt) ;
endfor
MyPaths[-1] := (-1.5cm,1.5cm) -- (1.5cm,1.5cm) ; MyColors[-1] := magenta ;
MyPaths[0] := (-2cm,2cm) -- (2*cos(0)*cm,-2cm) ; MyColors[0] := darkyellow ;
MyPaths[1] := fullcircle scaled 3cm ; MyColors[1] := darkred ;
MyPaths[2] := fullsquare scaled 2cm ; MyColors[2] := darkgreen ;
MyPaths[3] := (-2cm,-2cm) -- (2cm,2cm) ; MyColors[3] := darkblue ;

for j = -1 step 1 until 3 :
draw MyPaths[j] withpen MyPens[j] withcolor MyColors[j] ;
endfor
\stopMPpage
\stoptext
</texcode>
Also note that in order to specify the size of the pen in {{code|1=MyPens[j]}} we have to say {{code|1=((2+j)*pt)}} in order for Metapost to interpret correctly the desired size of the pen.
106

edits

Navigation menu