\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