Hi all,

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):

\startuniqueMPgraphic{colortest}
save mycolor ; color mycolor[] ;
mycolor[1] := (0.07, 0.21, 0.65) ;
mycolor[2] := (0.6, 0.6, 0.4) ;
mycolor[3] := (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))]) ;
endfor ;
\stopuniqueMPgraphic

\starttext

\uniqueMPgraphic{colortest}

\stoptext

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? 

All best

Thomas
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to