ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* mp: choose colors randomly from list
@ 2014-02-19 10:10 Schmitz Thomas A.
  2014-02-19 10:37 ` Alan BRASLAU
  2014-02-19 10:59 ` Otared Kavian
  0 siblings, 2 replies; 7+ messages in thread
From: Schmitz Thomas A. @ 2014-02-19 10:10 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-02-19 14:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-19 10:10 mp: choose colors randomly from list Schmitz Thomas A.
2014-02-19 10:37 ` Alan BRASLAU
2014-02-19 11:11   ` Schmitz Thomas A.
2014-02-19 11:16     ` Wolfgang Schuster
2014-02-19 11:38       ` Schmitz Thomas A.
2014-02-19 14:36         ` Alan BRASLAU
2014-02-19 10:59 ` Otared Kavian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).