[NTG-context] change numeral to string in Metafun

dalyoung haksan at me.com
Wed Jul 14 02:19:54 CEST 2010

Dear all,

I'd like to draw boxes with a label in a certain rule.
I define drawbox macro for it.
It receives 3 numbers, (the height of box, x position, y position).
I'd like to label the height of the box in the middle of the box.

I tired 
 label( h ,(3s*u+u, t*u + h*u/2)); %h is a received numeral.
But it is not working. If I change h to "letter" in label command, it is working.

So, I'd like to know how to put received numeral(the height of the box) as a label.
Or, how to change the value of a variable to a string.

Here is a working sample code.

numeric u;
u := 0.5cm;

def drawbox (expr h, s, t) =
%numeric h,s,t;
draw unitsquare xyscaled (1cm, h*u) shifted (3*s*u, t*u);
label("1",(3s*u+u, t*u + h*u/2));

drawbox (3, 0, 0); 
drawbox (6, 0, 3); 
drawbox (2, 1, 0); 
drawbox (1, 1, 2); 
drawbox (3, 2, 0) 
drawbox (4, 2, 3)




Thank you.

More information about the ntg-context mailing list