[metapost] Network Diagramming

Karel horakk at math.cas.cz
Fri Sep 3 17:21:39 CEST 2010


Dne 3.9.2010 0:13, Dan White napsal(a):
> 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;
>

I think that problem is that symrand was never defined, I have not 
found it nor in base palin macros, nor in metafun. It is clear 
that it should mean some probably uniform randomness added to the 
path... Also the numeric cludperc and cloudangle is missing; adding
cloudangle:=5;
cloudperc:=.1;
let symrand=uniformdeviate;
then works, but I am not sure the result is what should be expected?

Karel


More information about the metapost mailing list