[NTG-context] metafun- how to pass array as an argument

dalyoung haksan at me.com
Mon Jan 24 13:18:05 CET 2011

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.



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);
  bwidth := .32i*u+.5u;
  draw (lastpoint,0) -- (lastpoint +bwidth,0) -- (lastpoint +bwidth,u);
  lastpoint := lastpoint+bwidth;




More information about the ntg-context mailing list