[metapost] cloudit
Stephan Hennig
mailing_list at arcor.de
Mon Apr 14 10:52:34 CEST 2008
David Van Horn schrieb:
> I'm new to MetaPost and am trying to write a circleit-like macro that,
> instead of circling its contents, will draw a "cloud" around its
> contents. As a first step, I've tried to just draw a cloud.
> (Understanding the definition of circleit is beyond my ability at this
> point.)
Understanding the circleit macro is probably mandatory for writing a
similar macro.
> I'd like to generalize this to work for arbitrary values of n, but I
> don't see how to construct the pcloud path in general.
>
> 1) How can I generalize this?
Pre-calculations aren't necessary, all can be done on the fly.
def cloud(expr k) =
begingroup
save ang, da;
numeric ang, da;
ang := 360/k;
da := 5;
(.5, 0){dir da} ..% First point.
for i=1 upto k-1:% Inner points.
{dir(ang*i-180-da)} (.5, 0) rotated (ang*i) {dir(ang*i+da)} ..
endfor
{dir(-180-da)}cycle% Close path.
endgroup
enddef;
This macro returns a k-angular cloud with inner diameter 1bp. Note,
while all inner points in the path definition are of the form
{dir in} ( cardinal point ) {dir out}
unfortunately, a path definition can't begin with a direction specifier.
So {dir in} of the very first point is only applied finally, before the
closing 'cycle'. Additionally, the last point on the path from your
initial solution can be omitted, since it is identical to the first
point. Just closing the path (with a direction specifier) is
sufficient. Compare the results of
show cloud(5);
(in the log file) with i iterating from 1 to k and to k-1.
> 2) How can I make a circleit like macro that draws a cloud around its
> contents?
If I ever were to write a cloudit macro I'd not use the boxes package,
but MetaObj. But this is probably still not a beginner's task. For
using standard objects only, the manual should be read starting at
section 7 "Standard Library -- Gallery".
Best regards,
Stephan Hennig
More information about the metapost
mailing list