* draw & fill
@ 2006-10-18 13:08 Peter Rolf
2006-10-18 17:35 ` Taco Hoekwater
0 siblings, 1 reply; 5+ messages in thread
From: Peter Rolf @ 2006-10-18 13:08 UTC (permalink / raw)
[-- Attachment #1: Type: text/plain, Size: 521 bytes --]
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
[-- Attachment #2: draw_and_fill.tex --]
[-- Type: text/plain, Size: 1265 bytes --]
\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
[-- Attachment #3: Type: text/plain, Size: 139 bytes --]
_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: draw & fill
2006-10-18 13:08 draw & fill Peter Rolf
@ 2006-10-18 17:35 ` Taco Hoekwater
2006-10-18 19:11 ` Peter Rolf
0 siblings, 1 reply; 5+ messages in thread
From: Taco Hoekwater @ 2006-10-18 17:35 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: draw & fill
2006-10-18 17:35 ` Taco Hoekwater
@ 2006-10-18 19:11 ` Peter Rolf
2006-10-19 7:58 ` Taco Hoekwater
0 siblings, 1 reply; 5+ messages in thread
From: Peter Rolf @ 2006-10-18 19:11 UTC (permalink / raw)
[-- Attachment #1: Type: text/plain, Size: 739 bytes --]
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
>
>
[-- Attachment #2: draw_and_fill.tex --]
[-- Type: text/plain, Size: 1268 bytes --]
\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
[-- Attachment #3: Type: text/plain, Size: 139 bytes --]
_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: draw & fill
2006-10-18 19:11 ` Peter Rolf
@ 2006-10-19 7:58 ` Taco Hoekwater
2006-10-19 8:40 ` Peter Rolf
0 siblings, 1 reply; 5+ messages in thread
From: Taco Hoekwater @ 2006-10-19 7:58 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: draw & fill
2006-10-19 7:58 ` Taco Hoekwater
@ 2006-10-19 8:40 ` Peter Rolf
0 siblings, 0 replies; 5+ messages in thread
From: Peter Rolf @ 2006-10-19 8:40 UTC (permalink / raw)
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
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-10-19 8:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-18 13:08 draw & fill Peter Rolf
2006-10-18 17:35 ` Taco Hoekwater
2006-10-18 19:11 ` Peter Rolf
2006-10-19 7:58 ` Taco Hoekwater
2006-10-19 8:40 ` Peter Rolf
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).