Graphics and media/Collections of tips and tricks/Use MetaPost arrays

Unofficial ConTeXt Wiki mirror

Last modified: 2025-01-18

In Metapost (or rather in Metafun) one can define arrays of colors, strings, paths, pens and other variables. An example is the following:

In the above example, instead of

string MyColors[] ;

one could have said

color MyColors[] ;

and then we should have defined each component of MyColors as colors instead of strings:

Also note that in order to specify the size of the pen in MyPens[j] we have to say ((2+j)*pt) in order for Metapost to interpret correctly the desired size of the pen. The outer parentheses are to prevent MetaPost from interpreting the definition as

MyPens[j] := (pencircle scaled (2+j)) * pt ;

which would result in an error.