From: dalyoung <haksan@me.com>
To: ntg-context@ntg.nl
Subject: metafun- how to pass array as an argument
Date: Mon, 24 Jan 2011 21:18:05 +0900 [thread overview]
Message-ID: <B52C4FC9-C78C-4F6F-8945-A9B631AE7F72@me.com> (raw)
Dear all,
I draw a simple figure using the code as below.
In the code, I use "for i = 3,5,0,2,1,7:" in def draw_balls.
However, if I can pass the array "3,5,0,2,1,7" as an argument for def draw_balls (expr n) and call draw_balls (3,5,0,2,1,7), then it can be used for different number of balls and number of boxes.
Is there a way to do that or any suggestions?
Thank you for reading.
Regards,
Dalyoung
\startbuffer[a]
path p;
numeric bwidth, u, lastpoint;
u :=1cm;
p := fullcircle scaled .3u;
lastpoint := 0;
def draw_balls = %(expr s)
draw (0,0) -- (0, u);
for i=3,5,0,2,1,7:
for j = 1 upto i:
draw p shifted (lastpoint+.32*j*u,.3u);
endfor;
bwidth := .32i*u+.5u;
draw (lastpoint,0) -- (lastpoint +bwidth,0) -- (lastpoint +bwidth,u);
lastpoint := lastpoint+bwidth;
endfor;
enddef;
draw_balls;
\stopbuffer
\starttext
\processMPbuffer[a]
\stoptext
___________________________________________________________________________________
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://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
next reply other threads:[~2011-01-24 12:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-24 12:18 dalyoung [this message]
2011-01-24 12:50 ` Peter Rolf
2011-01-24 13:26 ` Peter Rolf
2011-01-24 13:33 dalyoung
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=B52C4FC9-C78C-4F6F-8945-A9B631AE7F72@me.com \
--to=haksan@me.com \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).