How to define an array of colors in Metafun
![](https://secure.gravatar.com/avatar/5faea8b4fa0adb143383811dc94f0d22.jpg?s=120&d=mm&r=g)
Hi all, I have a family of graphs to draw in Metapost and I would like to attribute a different color to each of them according to the value of a certain variable. Assuming that the path mygraph(j) depends on the variable j, which is computed within a lua code and passed to Metapost, I wonder if it is possible to define an array of colors named mycolor, so that I could say draw mygraph(j) withcolor mycolor(j) ; Here the variable j takes integer values (say between 1 and 10), and one would have defined mycolor(1) through mycolor(10). Thanks in advance for any help: Otared K.
![](https://secure.gravatar.com/avatar/46562c7d27388490d62e8d7a5bc960dd.jpg?s=120&d=mm&r=g)
On 6/20/2020 4:48 PM, Otared Kavian wrote:
Hi all,
I have a family of graphs to draw in Metapost and I would like to attribute a different color to each of them according to the value of a certain variable. Assuming that the path mygraph(j) depends on the variable j, which is computed within a lua code and passed to Metapost, I wonder if it is possible to define an array of colors named mycolor, so that I could say
draw mygraph(j) withcolor mycolor(j) ;
Here the variable j takes integer values (say between 1 and 10), and one would have defined mycolor(1) through mycolor(10). \startMPpage string MyColors[] ; path MyPaths [] ;
MyPaths[1] := fullcircle scaled 3cm; MyColors[1] := "red"; MyPaths[8] := fullsquare scaled 3cm; MyColors[8] := "green"; draw MyPaths[1] withcolor MyColors[1] ; draw MyPaths[8] withcolor MyColors[8] ; \stopMPpage ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
participants (2)
-
Hans Hagen
-
Otared Kavian