[NTG-context] mp: choose colors randomly from list
Schmitz Thomas A.
thomas.schmitz at uni-bonn.de
Wed Feb 19 11:10:57 CET 2014
I would like to have mp choose a (transparent) color randomly from a predefined list. My naive approach was (let’s restrict it to three colors):
save mycolor ; color mycolor ;
mycolor := (0.07, 0.21, 0.65) ;
mycolor := (0.6, 0.6, 0.4) ;
mycolor := (0.5, 0.8, 0.5) ;
path p ;
p := unitsquare scaled 2cm ;
for i=1 upto 3:
fill p shifted (i*2.5cm, 0) withcolor transparent (1,0.3,mycolor[round(uniformdeviate(i))]) ;
Is there a better approach? The selection isn’t random enough for my taste :-) Sometimes, in my real document, I get black color, even though black isn’t in the list, so I suspect that mp doesn’t get a correct value for mycolor[round(uniformdeviate(i))]. And finally: how could I define the colors in a way that I could also use them outside of mp? Or do I have to copy-paste the definitions into \definecolor’s?
More information about the ntg-context