[metapost] Network Diagramming

Dan White dwhite at olp.net
Fri Sep 3 01:13:41 CEST 2010


I'm new to metapost and was wondering if someone could assist me in
troubleshooting an error I'm unable to figure out.

I'm attempting to use the cloud vardef found here:

http://editthis.info/metapost/Functions

for a network diagram I'm trying to create.

I've created a test source file of:

outputtemplate := "figure.mps";
vardef cloud(expr p, segments) =
   save thestep, lasttime, thistime, lastpoint,  thisdir, lastdir, cpath,
xpath;
   thestep = arclength(p)/segments;
   numeric lasttime; lasttime = 0;
   for i = 1 upto segments:
     hide(
       numeric thistime;
       pair lastpoint, thispoint, lastdir, thisdir;
       path cpath, xpath;
       thistime = arctime (i if i < segments: + symrand(0.2) fi)
*arclength(p) / segments of p;
       lastpoint = point lasttime of p;
       thispoint = point thistime of p;
       lastdir = (direction lasttime of p) rotated (-cloudangle +
symrand(10));
       thisdir = (direction thistime of p) rotated (cloudangle +
symrand(10));
       cpath = lastpoint{lastdir} .. {thisdir}thispoint;
       xpath = subpath (1-cloudperc-symrand(0.1), 1) of cpath
reflectedabout(thispoint, thispoint + (thisdir rotated 90));
       lasttime := thistime;
     )
     cpath -- (reverse xpath) & xpath --
   endfor
   cycle
enddef;
beginfig(1);
      z100 = (75,75);
      z101 = (0,50);
      z102 = (75,25);
      draw cloud(z100..z101..z102,3);
endfig;
end;


When attempting to run this through mpost, I get:

This is MetaPost, version 1.208 (kpathsea version 5.0.0)
(./figure-2.mp
! Missing `)' has been inserted.
<to be read again> 
                     (
<argument> ...stime=arctime((1)if(1)<(3):+symrand(
                                                    0.2)fi)*arclength((path))/...

hide->exitif.numeric.begingroup(TEXT0)
                                        ;endgroup;
<for(1)> ...isdir.rotated90));lasttime:=thistime;)
                                                    cpath--(reverse.xpath)&xpa...

cloud->...me;)cpath--(reverse.xpath)&xpath--endfor
                                                    .cycle.endgroup
l.28     draw cloud(z100..z101..z102,3)
                                         ;
? 


 From what I can gather (I'm still learning how to interpret this output),
I'm encountering an error near the call to symrand. I suspect that my
metapost installation does not have that function defined. In fact,
while searching for this function at google, I can find no other reference
to that function (related to metapost).

Does anyone have any pointers on how to trouble shoot this or if there
might be another function which serves the same purpose?

Thank You,
-- 
Dan White


More information about the metapost mailing list