randomize direction of arrow in metafun
Hi all, for a slide template, I want to draw colored arrows in a randomized color (from a list of colors). This works (and the code is far too clever for me, I must have copied it somewhere): save mycolor ; color mycolor[] ; mycolor[1] := (0.2, 0.3, 0.4) ; mycolor[2] := (0.6, 0.6, 0.4) ; mycolor[3] := (0.5, 0.8, 0.5) ; so I can write drawarrow p withcolor mycolor[round(uniformdeviate(9))] ; But I also want the direction of the arrow to be random. My first idea was to define a variable that would expand either to "reverse" or the empty string right after drawarrow, but that's where I'm stuck. Anyone has an idea how to achieve this? (It's probably somewhere in the source, but I can't find it.) And is the method of defining the random color OK, or could this also be improved. Thanks, and all best Thomas
Hi,
you could do something like this:
\startMPpage
for i = 0 upto 10:
drawarrow if uniformdeviate(1)<0.5: reverse fi ((0,0)--(2cm,0)) yshifted i*cm;
endfor;
\stopMPpage
/Mikael
On Sat, May 15, 2021 at 2:30 PM Thomas A. Schmitz
Hi all,
for a slide template, I want to draw colored arrows in a randomized color (from a list of colors). This works (and the code is far too clever for me, I must have copied it somewhere):
save mycolor ; color mycolor[] ; mycolor[1] := (0.2, 0.3, 0.4) ; mycolor[2] := (0.6, 0.6, 0.4) ; mycolor[3] := (0.5, 0.8, 0.5) ;
so I can write
drawarrow p withcolor mycolor[round(uniformdeviate(9))] ;
But I also want the direction of the arrow to be random. My first idea was to define a variable that would expand either to "reverse" or the empty string right after drawarrow, but that's where I'm stuck. Anyone has an idea how to achieve this? (It's probably somewhere in the source, but I can't find it.) And is the method of defining the random color OK, or could this also be improved.
Thanks, and 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
On 5/15/21 2:42 PM, Mikael Sundqvist wrote:
Hi,
you could do something like this:
\startMPpage for i = 0 upto 10: drawarrow if uniformdeviate(1)<0.5: reverse fi ((0,0)--(2cm,0)) yshifted i*cm; endfor; \stopMPpage
/Mikael
Hi Mikael, wonderful, thanks for the quick answer! Yes that works as intended! Thomas
participants (2)
-
Mikael Sundqvist
-
Thomas A. Schmitz