Rounded pens with Metapost
Hi, are there now better ways to create rounded pens without adding many support points? \starttext \startMPpage[offset=1dk] path Halfcircle ; Halfcircle = (1,0){up} for i = 1 upto 180 : .. ((1,0) rotated i) endfor -- cycle ; draw Halfcircle scaled 10 shifted (0,12) ; pen HalfcirclePen ; HalfcirclePen := makepen Halfcircle ; draw ((0,1) -- (1,1)) scaled 10 withpen HalfcirclePen ; draw ((0,0) -- (0,1)) scaled 10 withpen HalfcirclePen rotated 90 ; draw ((1,0) -- (1,1)) scaled 10 withpen HalfcirclePen rotated 270 ; draw ((0,0) -- (1,0)) scaled 10 withpen HalfcirclePen rotated 180 ; \stopMPpage \startMPpage[offset=1dk] path RoundedRectangle ; RoundedRectangle = (-1,0){up} for i = 180 step -1 until 89 : .. ((1,0) rotated i) endfor -- (1,1){down} for i = 360 step -1 until 269 : .. ((1,0) rotated i shifted (0,1)) endfor -- cycle ; draw RoundedRectangle scaled 10 shifted (0,12) ; pen RoundedRectanglePen ; RoundedRectanglePen := makepen RoundedRectangle ; draw ((1,0) -- (1,1)) scaled 10 withpen RoundedRectanglePen reflectedabout (up,down) rotated 270 ; draw ((0,0) -- (1,0)) scaled 10 withpen RoundedRectanglePen rotated 180 ; \stopMPpage \stoptext Wolfgang
Hi Wolfgang I thought using the metapost variable tcircle as a pen would work but for some reason it does not give rounded corners for the square in the first MPpage. Not a solution unfortunately. Best Wishes Keith path Tcircle; Tcircle := tcircle; draw Tcircle scaled 20 shifted(0,24)withcolor red; pen TcirclePen ; TcirclePen := makepen Tcircle ; draw ((0,1)-- (1,1))scaled 10 withpen TcirclePen shifted (12,12)withcolor red; draw ((0,0)-- (0,1))scaled 10 withpen TcirclePen rotated 90 shifted (12,12)withcolor red; draw ((1,0)-- (1,1))scaled 10 withpen TcirclePen rotated 270 shifted (12,12)withcolor red; draw ((0,0)-- (1,0))scaled 10 withpen TcirclePen rotated 180 shifted (12,12)withcolor red; On 06/12/2024 19:16, Wolfgang Schuster wrote:
Hi,
are there now better ways to create rounded pens without adding many support points?
\starttext
\startMPpage[offset=1dk]
path Halfcircle ; Halfcircle = (1,0){up} for i = 1 upto 180 : .. ((1,0) rotated i) endfor -- cycle ;
draw Halfcircle scaled 10 shifted (0,12) ;
pen HalfcirclePen ; HalfcirclePen := makepen Halfcircle ;
draw ((0,1) -- (1,1)) scaled 10 withpen HalfcirclePen ; draw ((0,0) -- (0,1)) scaled 10 withpen HalfcirclePen rotated 90 ; draw ((1,0) -- (1,1)) scaled 10 withpen HalfcirclePen rotated 270 ; draw ((0,0) -- (1,0)) scaled 10 withpen HalfcirclePen rotated 180 ;
\stopMPpage
\startMPpage[offset=1dk]
path RoundedRectangle ; RoundedRectangle = (-1,0){up} for i = 180 step -1 until 89 : .. ((1,0) rotated i) endfor -- (1,1){down} for i = 360 step -1 until 269 : .. ((1,0) rotated i shifted (0,1)) endfor -- cycle ;
draw RoundedRectangle scaled 10 shifted (0,12) ;
pen RoundedRectanglePen ; RoundedRectanglePen := makepen RoundedRectangle ;
draw ((1,0) -- (1,1)) scaled 10 withpen RoundedRectanglePen reflectedabout (up,down) rotated 270 ; draw ((0,0) -- (1,0)) scaled 10 withpen RoundedRectanglePen rotated 180 ;
\stopMPpage
\stoptext
Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror) archive : https://github.com/contextgarden/context wiki : https://wiki.contextgarden.net ___________________________________________________________________________________
Keith McKay schrieb am 07.12.2024 um 13:29:
Hi Wolfgang
I thought using the metapost variable tcircle as a pen would work but for some reason it does not give rounded corners for the square in the first MPpage. Not a solution unfortunately.
Best Wishes
Keith
path Tcircle; Tcircle := tcircle;
draw Tcircle scaled 20 shifted(0,24)withcolor red;
pen TcirclePen ; TcirclePen := makepen Tcircle ;
draw ((0,1)-- (1,1))scaled 10 withpen TcirclePen shifted (12,12)withcolor red;
draw ((0,0)-- (0,1))scaled 10 withpen TcirclePen rotated 90 shifted (12,12)withcolor red;
draw ((1,0)-- (1,1))scaled 10 withpen TcirclePen rotated 270 shifted (12,12)withcolor red;
draw ((0,0)-- (1,0))scaled 10 withpen TcirclePen rotated 180 shifted (12,12)withcolor red;
This is the first thing I tried but it doesn't work with pens. The following example shows how the curve gets rounder with the number of steps. \starttext \doloopoverlist {90,60,45,30,20,15,10,5,1} {\recursestring: \startMPcode draw ((-1cm,0)--(5cm,0)) shifted (0,1cm) withcolor (1,0,0); pen testpen ; testpen := makepen ((1,0){up} for i = 1 step \recursestring\space until 181 : .. ((1,0) rotated i) endfor -- cycle) ; draw (0,0)--(4cm,0) withpen testpen scaled 1cm; \stopMPcode \blank} \stoptext Wolfgang
Hi,
as far as I have understood one can only either use a circle (and
then, lowlevel, Postscript/PDF uses that) or a polygon (and then that
is used low-level).
Since a few weeks (not sure if it is in distribution yet) there is
also a penstroked macro that imitates the penstroke a bit (one can
make variants of it). Example:
\startMPpage[offset=1dk]
fill function(2,"x","sin(x)",0,epsed(6*pi),0.1)
scaled 20
penstroked
function(2,"x","1+7*(sin(x)^2)",0,epsed(pi),0.001)
withcolor "orange" ;
\stopMPpage
/Mikael
On Fri, Dec 6, 2024 at 8:19 PM Wolfgang Schuster
Hi,
are there now better ways to create rounded pens without adding many support points?
\starttext
\startMPpage[offset=1dk]
path Halfcircle ; Halfcircle = (1,0){up} for i = 1 upto 180 : .. ((1,0) rotated i) endfor -- cycle ;
draw Halfcircle scaled 10 shifted (0,12) ;
pen HalfcirclePen ; HalfcirclePen := makepen Halfcircle ;
draw ((0,1) -- (1,1)) scaled 10 withpen HalfcirclePen ; draw ((0,0) -- (0,1)) scaled 10 withpen HalfcirclePen rotated 90 ; draw ((1,0) -- (1,1)) scaled 10 withpen HalfcirclePen rotated 270 ; draw ((0,0) -- (1,0)) scaled 10 withpen HalfcirclePen rotated 180 ;
\stopMPpage
\startMPpage[offset=1dk]
path RoundedRectangle ; RoundedRectangle = (-1,0){up} for i = 180 step -1 until 89 : .. ((1,0) rotated i) endfor -- (1,1){down} for i = 360 step -1 until 269 : .. ((1,0) rotated i shifted (0,1)) endfor -- cycle ;
draw RoundedRectangle scaled 10 shifted (0,12) ;
pen RoundedRectanglePen ; RoundedRectanglePen := makepen RoundedRectangle ;
draw ((1,0) -- (1,1)) scaled 10 withpen RoundedRectanglePen reflectedabout (up,down) rotated 270 ; draw ((0,0) -- (1,0)) scaled 10 withpen RoundedRectanglePen rotated 180 ;
\stopMPpage
\stoptext
Wolfgang
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror) archive : https://github.com/contextgarden/context wiki : https://wiki.contextgarden.net ___________________________________________________________________________________
participants (3)
-
Keith McKay
-
Mikael Sundqvist
-
Wolfgang Schuster