Metapost lines with fancy line endings and connections
Hi, I have a bunch of similar graphics on a 7x7 where some lines have exceptions for the endings and connections. - When a line ends in one of the four corners the line end has an angle of 45 degrees. - When a line takes a turn the outer corner results also in a 45 degree angle. - Single points always use straight endings. - Lines which end outside of a corner end with a straight line. While I can get the desired result which a filled path I'm looking for a solution where I have to set fewer control points. The example below shows the simpler draw alternative where I need only a start and end point versus the outline alternative where I need at least twice as many points to get the desired output. \starttext \startuseMPgraphic{draw} draw hlingrid(0, 7, 1, 7, 7) withpen pencircle scaled 1/20 shifted (0.5,0.5) withcolor "darkgray" ; draw vlingrid(0, 7, 1, 7, 7) withpen pencircle scaled 1/20 shifted (0.5,0.5) withcolor "darkgray" ; pickup pensquare scaled 1; drawoptions(withcolor "red"); draw (1,7) -- (7,7) ; draw (1,1) -- (3,1) -- (3,5) ; draw (7,3) -- (5,3) -- (5,5) -- (7,5) ; draw (7,1) ; \stopuseMPgraphic \startuseMPgraphic{fill} draw hlingrid(0, 7, 1, 7, 7) withpen pencircle scaled 1/20 withcolor "darkgray" ; draw vlingrid(0, 7, 1, 7, 7) withpen pencircle scaled 1/20 withcolor "darkgray" ; drawoptions(withcolor "green"); fill (0,6) -- (7,6) -- (6,7) -- (1,7) -- cycle ; fill (1,0) -- (2,0) -- (3,1) -- (3,5) -- (2,5) -- (2,1) -- (0,1) -- cycle ; fill (7,2) -- (5,2) -- (4,3) -- (4,4) -- (5,5) -- (7,5) -- (7,4) -- (5,4) -- (5,3) -- (7,3) -- cycle ; fill (6,0) -- (7,0) -- (7,1) -- (6,1) -- cycle ; \stopuseMPgraphic \startcombination[2*1] {\scale[s=10]{\useMPgraphic{draw}}}{draw option} {\scale[s=10]{\useMPgraphic{fill}}}{fill option} \stopcombination \startoverlay {\scale[s=10]{\useMPgraphic{draw}}} {\scale[s=10]{\useMPgraphic{fill}}} \stopoverlay \stoptext Wolfgang
On 1 Dec 2024, at 09:51, Wolfgang Schuster
wrote: While I can get the desired result which a filled path I'm looking for a solution where I have to set fewer control points.
Draw the paths two grid squares sorter and at each end draw a “dot” which is a triangle of the right direction and shading? So your first line draw (1,7) -- (7,7) ; becomes triangle_dot_bottom_right_fill (1,7) ; draw (2,6) ; triangle_dot_bottom_left_fill (7,7) ; If there are load of them then it might be easier to write a macro to walk the (1,7) — (7,7) path and insert “dots” at the changes of direction. Regards, — Bruce Horrocks Hampshire, UK
On 1 Dec 2024, at 10:45, Bruce Horrocks
wrote: On 1 Dec 2024, at 09:51, Wolfgang Schuster
wrote: While I can get the desired result which a filled path I'm looking for a solution where I have to set fewer control points.
Draw the paths two grid squares sorter and at each end draw a “dot” which is a triangle of the right direction and shading?
s/sorter/shorter/
So your first line
draw (1,7) -- (7,7) ;
becomes
triangle_dot_bottom_right_fill (1,7) ; draw (2,6) ; triangle_dot_bottom_left_fill (7,7) ;
triangle_dot_bottom_right_fill (1,7) ; draw (2,7) -- (6,7) ; triangle_dot_bottom_left_fill (7,7) ; <sigh> Sorry, brain not in gear
If there are load of them then it might be easier to write a macro to walk the (1,7) — (7,7) path and insert “dots” at the changes of direction.
Regards,
— Bruce Horrocks Hampshire, UK
On 12/1/2024 11:54 AM, Bruce Horrocks wrote:
<sigh> Sorry, brain not in gear
so once you're rebooted, you can figure out the logic behind this: linecap := butt ; linejoin := beveled ; or even pickup pensquare rotated -60 scaled (1/sqrt(2)) ; linecap := 1 ; Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
Hans Hagen via ntg-context schrieb am 01.12.2024 um 12:34:
On 12/1/2024 11:54 AM, Bruce Horrocks wrote:
<sigh> Sorry, brain not in gear
so once you're rebooted, you can figure out the logic behind this:
linecap := butt ; linejoin := beveled ;
This doesn't result in the desired output I want.
or even
pickup pensquare rotated -60 scaled (1/sqrt(2)) ; linecap := 1 ;
I played with custom pens but failed to create a working triangle pen. I'll take another look into it because a few custom pens can draw all lines. Wolfgang
Hi
On Sun, Dec 1, 2024 at 1:28 PM Wolfgang Schuster
Hans Hagen via ntg-context schrieb am 01.12.2024 um 12:34:
On 12/1/2024 11:54 AM, Bruce Horrocks wrote:
<sigh> Sorry, brain not in gear
so once you're rebooted, you can figure out the logic behind this:
linecap := butt ; linejoin := beveled ;
This doesn't result in the desired output I want.
or even
pickup pensquare rotated -60 scaled (1/sqrt(2)) ; linecap := 1 ;
I played with custom pens but failed to create a working triangle pen. I'll take another look into it because a few custom pens can draw all lines.
\startuseMPgraphic{draw} draw hlingrid(0, 7, 1, 7, 7) withpen pencircle scaled 1/20 shifted (0.5,0.5) withcolor "darkgray" ; draw vlingrid(0, 7, 1, 7, 7) withpen pencircle scaled 1/20 shifted (0.5,0.5) withcolor "darkgray" ; pen pentriangle ; pentriangle := (makepen ((0,0) -- (1,0) -- (1,1) -- cycle) shifted (-1/2,-1/2)) scaled 1 ; drawoptions(withcolor "red"); pickup pensquare scaled 1; draw (1,7) -- (7,7) ; draw (7,1) ; draw (5,4) ; pickup pentriangle ; draw (1,1) -- (2,1) withpen pentriangle rotated 90 ; draw (3,1) -- (3,5) withpen pentriangle rotated 180 ; draw (7,3) -- (5,3) withpen pentriangle rotated 90 ; draw (7,5) -- (5,5) withpen pentriangle rotated 0 ; \stopuseMPgraphic seems to work here. But I happily admit it is a bit cumbersome... /Mikael
On 12/1/2024 2:02 PM, Mikael Sundqvist wrote:
Hi
On Sun, Dec 1, 2024 at 1:28 PM Wolfgang Schuster
wrote: Hans Hagen via ntg-context schrieb am 01.12.2024 um 12:34:
On 12/1/2024 11:54 AM, Bruce Horrocks wrote:
<sigh> Sorry, brain not in gear
so once you're rebooted, you can figure out the logic behind this:
linecap := butt ; linejoin := beveled ;
This doesn't result in the desired output I want.
or even
pickup pensquare rotated -60 scaled (1/sqrt(2)) ; linecap := 1 ;
I played with custom pens but failed to create a working triangle pen. I'll take another look into it because a few custom pens can draw all lines.
\startuseMPgraphic{draw} draw hlingrid(0, 7, 1, 7, 7) withpen pencircle scaled 1/20 shifted (0.5,0.5) withcolor "darkgray" ; draw vlingrid(0, 7, 1, 7, 7) withpen pencircle scaled 1/20 shifted (0.5,0.5) withcolor "darkgray" ; pen pentriangle ; pentriangle := (makepen ((0,0) -- (1,0) -- (1,1) -- cycle) shifted (-1/2,-1/2)) scaled 1 ; drawoptions(withcolor "red"); pickup pensquare scaled 1; draw (1,7) -- (7,7) ; draw (7,1) ; draw (5,4) ; pickup pentriangle ; draw (1,1) -- (2,1) withpen pentriangle rotated 90 ; draw (3,1) -- (3,5) withpen pentriangle rotated 180 ; draw (7,3) -- (5,3) withpen pentriangle rotated 90 ; draw (7,5) -- (5,5) withpen pentriangle rotated 0 ; \stopuseMPgraphic
seems to work here. But I happily admit it is a bit cumbersome...
i wonder of we can use our new secret penstroked feature but i'm not in that mode now, Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
Mikael Sundqvist schrieb am 01.12.2024 um 14:02:
Hi
Hans Hagen via ntg-context schrieb am 01.12.2024 um 12:34:
On 12/1/2024 11:54 AM, Bruce Horrocks wrote:
<sigh> Sorry, brain not in gear so once you're rebooted, you can figure out the logic behind this:
linecap := butt ; linejoin := beveled ; This doesn't result in the desired output I want. or even
pickup pensquare rotated -60 scaled (1/sqrt(2)) ; linecap := 1 ; I played with custom pens but failed to create a working triangle pen. I'll take another look into it because a few custom pens can draw all lines. \startuseMPgraphic{draw} draw hlingrid(0, 7, 1, 7, 7) withpen pencircle scaled 1/20 shifted (0.5,0.5) withcolor "darkgray" ; draw vlingrid(0, 7, 1, 7, 7) withpen pencircle scaled 1/20 shifted (0.5,0.5) withcolor "darkgray" ;
On Sun, Dec 1, 2024 at 1:28 PM Wolfgang Schuster
wrote: pen pentriangle ; pentriangle := (makepen ((0,0) -- (1,0) -- (1,1) -- cycle) shifted (-1/2,-1/2)) scaled 1 ; drawoptions(withcolor "red"); pickup pensquare scaled 1; draw (1,7) -- (7,7) ; draw (7,1) ; draw (5,4) ; pickup pentriangle ; draw (1,1) -- (2,1) withpen pentriangle rotated 90 ; draw (3,1) -- (3,5) withpen pentriangle rotated 180 ; draw (7,3) -- (5,3) withpen pentriangle rotated 90 ; draw (7,5) -- (5,5) withpen pentriangle rotated 0 ; \stopuseMPgraphic seems to work here. But I happily admit it is a bit cumbersome...
It's a good starting point and I can work with it. When I look at your pen setting it's possible I forgot the parentheses before the shift operation. Wolfgang
Bruce Horrocks schrieb am 01.12.2024 um 11:45:
On 1 Dec 2024, at 09:51, Wolfgang Schuster
wrote: While I can get the desired result which a filled path I'm looking for a solution where I have to set fewer control points. Draw the paths two grid squares sorter and at each end draw a “dot” which is a triangle of the right direction and shading?
So your first line
draw (1,7) -- (7,7) ;
becomes
triangle_dot_bottom_right_fill (1,7) ; draw (2,6) ; triangle_dot_bottom_left_fill (7,7) ;
If there are load of them then it might be easier to write a macro to walk the (1,7) — (7,7) path and insert “dots” at the changes of direction.
I had this in my mind but wasn't sure if this is the best solution. Using a macro to create the line is a must here but I have to think how to set which delimiters for the line should be used (using different macros for each variation or passing the shape as argument). BTW: Use && to connect the parts of the line to avoid graphical errors in your pdf viewer. \startMPpage[offset=1pt] pickup pensquare scaled 1 ; draw (0,0) ; draw (1,0) ; draw (0,2) && (1,2) ; \stopMPpage Wolfgang
participants (5)
-
Bruce Horrocks
-
Hans Hagen
-
Hans Hagen
-
Mikael Sundqvist
-
Wolfgang Schuster