[NTG-context] Code that run in Metapost but not in starMPcode enviroment

DesdeChaves desdechaves at gmail.com
Sun Feb 1 12:29:06 CET 2015


I'm trying to draw some random arrows using Metapost. For that I use a
piece of code from fpast that in found at stackexchange
<http://tex.stackexchange.com/questions/179745/generating-random-arrows-in-tikz/180111#180111>

Unfortunately this code does not work in context (request for a solution
<http://tex.stackexchange.com/questions/225864/metapost-error-related-with-context>)
because the freelabel() function. If I disable it the result is the
expected.
What is wrong with this code?


\starttext

\startMPcode
numeric u, nb_vectors, wd;
u := 1cm; % unit length
nb_vectors := 20; wd = .5;
boolean intersect; pair random_origin; color random_color; path candidate,
random_vector[];
%
vardef bb(expr p) =
  save orig, extr; pair orig, extr; orig = point 0 of p; extr = point 1 of
p;
  pair v,w; v = wd*unitvector(extr-orig)*u; w = v rotated 90;
  (orig - v + w) -- (extr + v + w) -- (extr + v - w) -- (orig - v - w) --
cycle
enddef;
%

  pickup pencircle scaled 2bp;
  i = 1;
  forever:
    exitunless (i <=  nb_vectors);
    intersect := false;
    random_length := u*(2+uniformdeviate(1));
    random_angle := uniformdeviate(359);
    random_origin := u*(uniformdeviate(wd*nb_vectors),
uniformdeviate(wd*nb_vectors));
    random_color := (uniformdeviate(1), uniformdeviate(1),
uniformdeviate(1));
    candidate := random_origin -- (random_origin +
random_length*dir(random_angle));
    j := 1;
    forever:
      exitif (j = i) or (intersect = true);
      if bb(random_vector[j]) intersectiontimes bb(candidate) <>  (-1, -1):
        intersect := true;
      fi;
      j := j+1;
    endfor;
    if intersect = false:
      random_vector[i] = candidate;
      drawarrow candidate withcolor random_color;
      freelabel(btex $v$ etex, point .5 of candidate, point .5 of candidate
+ dir (random_angle + 90));
      i := i+1;
    fi;
  endfor;
\stopMPcode


\stoptext
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.ntg.nl/pipermail/ntg-context/attachments/20150201/be3f016d/attachment.html>


More information about the ntg-context mailing list