Hi all, [maybe this is a bit off topic and you think that the Metapost mailing list is the right place for such stuff. But I have quit this list quite some time ago, as there was more spam than regular posts. Try to forgive me... :D ] After buying the 'Metafont' manual, I'm now playing around with some mp macro programming. The problem in the attached example is, that the 'draw' variants of the [hv]line macro always work with a *fixed* pen size of 1pt (and I can't figure out why). I'm clueless.. Greetings, Peter \setupoutput[pdftex] \setupcolors[state=start] \starttext \startMPinclusions % default unit u:= .5 ; % u:=1 works, u:=2 doesn't pen upen ; upen = makepen(unitsquare scaled u shifted -(.5u,.5u)) ; % width, height, shift-x, shift-y, color def fill_square(expr w,h,a,b,c)= fill unitsquare xyscaled(w*u,h*u) shifted (a*u,b*u) withcolor c enddef ; def fill_hline(expr w,a,b,c)= fill_square(w,u,a,b,c) enddef ; def fill_vline(expr h,a,b,c)= fill_square(u,h,a,b,c) enddef ; % the drawing macros always use a pen of 1pt ; % even with an extra defined pen def draw_hline(expr w,a,b,c)= draw (.5u,.5u)--(w*u-.5u,.5u) withpen upen shifted (a*u,b*u) withcolor c enddef ; def draw_vline(expr h,a,b,c)= draw (.5u,.5u)--(.5u,h*u-.5u) withpen pensquare scaled u shifted (a*u,b*u) withcolor c enddef ; def draw_frame(expr w,h,a,b,c)= draw (.5u,.5u)--(w*u-.5u,.5u)--(w*u-.5u,h*u-.5u)--(.5u,h*u-.5u)--cycle withpen pensquare scaled u shifted (a*u,b*u) withcolor c enddef ; \stopMPinclusions \startMPpage fill_hline(20,5,5,red) ; fill_vline(20,5,5,red) ; draw_vline(20,5,25,blue) ; draw_hline(20,25,5,blue) ; draw_frame(50,50,0,0,black) ; \stopMPpage \stoptext
Hi Peter,
def draw_vline(expr h,a,b,c)= draw (.5u,.5u)--(.5u,h*u-.5u) withpen pensquare scaled u
That scales the whole draw statement, just like if you had said: draw (.5u,.5u)--(.5u,h*u-.5u) scaled u withpen pensquare So you need to do it like this: draw (.5u,.5u)--(.5u,h*u-.5u) withpen (pensquare scaled u) Cheers, Taco
Taco Hoekwater wrote:
Hi Peter,
def draw_vline(expr h,a,b,c)= draw (.5u,.5u)--(.5u,h*u-.5u) withpen pensquare scaled u
That scales the whole draw statement, just like if you had said:
draw (.5u,.5u)--(.5u,h*u-.5u) scaled u withpen pensquare
So you need to do it like this:
draw (.5u,.5u)--(.5u,h*u-.5u) withpen (pensquare scaled u)
Hi Taco, thanks for the answer. Sadly I doesn't work here; all drawn lines are still fixed to 1pt. Even my own defined pen (upen) in draw_hline is completely ignored. Greetings, Peter
Cheers, Taco _______________________________________________ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context
\setupoutput[pdftex] \setupcolors[state=start] \starttext \startMPinclusions % default unit u:= 2 ; % u:=1 works, u:=2 doesn't pen upen ; upen = makepen(unitsquare scaled u shifted -(.5u,.5u)) ; % width, height, shift-x, shift-y, color def fill_square(expr w,h,a,b,c)= fill unitsquare xyscaled(w*u,h*u) shifted (a*u,b*u) withcolor c enddef ; def fill_hline(expr w,a,b,c)= fill_square(w,u,a,b,c) enddef ; def fill_vline(expr h,a,b,c)= fill_square(u,h,a,b,c) enddef ; % the drawing macros always use a pen of 1pt ; % even with an extra defined pen def draw_hline(expr w,a,b,c)= draw (.5u,.5u)--(w*u-.5u,.5u) withpen upen shifted (a*u,b*u) withcolor c enddef ; def draw_vline(expr h,a,b,c)= draw (.5u,.5u)--(.5u,h*u-.5u) withpen (pensquare scaled u) shifted (a*u,b*u) withcolor c enddef ; def draw_frame(expr w,h,a,b,c)= draw (.5u,.5u)--(w*u-.5u,.5u)--(w*u-.5u,h*u-.5u)--(.5u,h*u-.5u)--cycle withpen (pensquare scaled u) shifted (a*u,b*u) withcolor c enddef ; \stopMPinclusions \startMPpage fill_hline(20,5,5,red) ; fill_vline(20,5,5,red) ; draw_vline(20,5,25,blue) ; draw_hline(20,25,5,blue) ; draw_frame(50,50,0,0,black) ; \stopMPpage \stoptext
Peter Rolf wrote:
Hi Taco,
thanks for the answer. Sadly I doesn't work here; all drawn lines are still fixed to 1pt. Even my own defined pen (upen) in draw_hline is completely ignored.
I was somewhat wrong before. The problem in your case is not the grouping but that you are scaling *everything* by u. Try this: set u back to 1, then add a second MPpage like this: \startMPpage u:= 2; fill_hline(20,5,5,red) ; fill_vline(20,5,5,red) ; draw_vline(20,5,25,blue) ; draw_hline(20,25,5,blue) ; draw_frame(50,50,0,0,black) ; \stopMPpage It should be clear from the output pages what happens. Greetings, Taco
Taco Hoekwater wrote:
Peter Rolf wrote:
Hi Taco,
thanks for the answer. Sadly I doesn't work here; all drawn lines are still fixed to 1pt. Even my own defined pen (upen) in draw_hline is completely ignored.
I was somewhat wrong before. The problem in your case is not the grouping but that you are scaling *everything* by u.
Try this: set u back to 1, then add a second MPpage like this:
\startMPpage u:= 2; fill_hline(20,5,5,red) ; fill_vline(20,5,5,red) ;
draw_vline(20,5,25,blue) ; draw_hline(20,25,5,blue) ;
draw_frame(50,50,0,0,black) ; \stopMPpage
It should be clear from the output pages what happens.
Many thanks Taco! Now I clearly see what happens :) Greetings, Peter
Greetings, Taco
_______________________________________________ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context
participants (2)
-
Peter Rolf
-
Taco Hoekwater