ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* randomize direction of arrow in metafun
@ 2021-05-15 12:30 Thomas A. Schmitz
  2021-05-15 12:42 ` Mikael Sundqvist
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas A. Schmitz @ 2021-05-15 12:30 UTC (permalink / raw)
  To: ntg-context

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
___________________________________________________________________________________

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

* Re: randomize direction of arrow in metafun
  2021-05-15 12:30 randomize direction of arrow in metafun Thomas A. Schmitz
@ 2021-05-15 12:42 ` Mikael Sundqvist
  2021-05-15 13:02   ` Thomas A. Schmitz
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Sundqvist @ 2021-05-15 12:42 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
<thomas.schmitz@uni-bonn.de> wrote:
>
> 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
> ___________________________________________________________________________________
___________________________________________________________________________________
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
___________________________________________________________________________________

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

* Re: randomize direction of arrow in metafun
  2021-05-15 12:42 ` Mikael Sundqvist
@ 2021-05-15 13:02   ` Thomas A. Schmitz
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas A. Schmitz @ 2021-05-15 13:02 UTC (permalink / raw)
  To: ntg-context

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
___________________________________________________________________________________
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
___________________________________________________________________________________

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

end of thread, other threads:[~2021-05-15 13:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-15 12:30 randomize direction of arrow in metafun Thomas A. Schmitz
2021-05-15 12:42 ` Mikael Sundqvist
2021-05-15 13:02   ` Thomas A. Schmitz

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