## Re: [PyX-user] Mid-arrows and patterns

 Re: [PyX-user] Mid-arrows and patterns From: Andre Wobst - 2005-09-22 13:01:59 ```Hi, On 21.09.05, Andy Buckley wrote: > I've got a couple of questions relating to PyX... specifically for drawing > Feynman diagrams. Here goes: > > 1. Is there a standard way to produce arrows a specified fraction of the > way along a path? In particular, is there a built-in "midway-arrow" > decorator I can apply, or do I have to chop up the path into appropriate > sections, one of which gets an earrow? Yes, the current implementation of the arrow decorator is restricted to the beginning and end point. However, there is a arrowhead path conctructor, which might be worth a look. You can use it to build your own decorator. As a quick starting point for you: import math from pyx import * class myarrow(deco.deco, attr.attr): def __init__(self, pos=0.5, size=6*unit.v_pt, angle=45, constriction=0.8): self.pos = pos self.size = size self.angle = angle self.constriction = constriction def decorate(self, dp): dp.ensurenormpath() constrictionlen = self.size*self.constriction*math.cos(self.angle*math.pi/360.0) arrowtopos = self.pos*dp.path.arclen()+0.5*self.size arrowtopath = dp.path.split(arrowtopos)[0] arrowpath = deco._arrowhead(arrowtopath, self.size, 45, constrictionlen, 1) dp.ornaments.fill(arrowpath) return dp c = canvas.canvas() c.stroke(path.curve(0, 0, 2, 0, 2, 2, 4, 2), [myarrow(0.5)]) c.writeEPSfile("arrow") Although this might not yet be the result you want for a feynman diagram, it is a start along the "PyX-way". You may want to add some features to the arrow and the _arrowhead method (like stroking only the front of the arrow and not its back) ... we should even discuss to add those features to the PyX distribution. Already this pos-argument above might be worth to be added ... > 2. Searching for info on using the pattern module to fill shapes, I found > the recipe in this mail: > http://sourceforge.net/mailarchive/message.php?msg_id=8845253 > As far as I can tell, since then pattern has moved to its own module and > I can run the code snippet when that's taken into account. However, the > documentation at > http://sourceforge.net/mailarchive/message.php?msg_id=8845253 > says that pre-defined patterns do exist, but I can't find them documented: > any suggestions? Mayby the're missing. I'll drop a note to correct that. Beside that have a look into the pattern module. There are quite a list of predefined patterns. > Additionally, looking at the EPS output from the code snippet in gv shows > very jagged pattern lines (although they print smoothly): can this > jaggedness be avoided onscreen or is it a problem with gv's rendering of > the PostScript primitives? I've used PostScript hatched fills before (using > this code: http://www.feyndiagram.com) and they came out much more smoothly. It depends on what operations you perform in the pattern. Our example having Text in the pattern indeed generates strange output in ghostscript when antialiasing is turned on. BTW you can turn antialiasing off by the shortkey "a" in gv. Overall we can savely claim this to be a ghostscript bug ... ;-) André -- by _ _ _ Dr. André Wobst / \ \ / ) wobsta@..., http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript and PDF figures (_/ \_)_/\_/ with Python & TeX: visit http://pyx.sourceforge.net/ ```

 [PyX-user] Mid-arrows and patterns From: Andy Buckley - 2005-09-21 13:14:21 ```Hi, I've got a couple of questions relating to PyX... specifically for drawing Feynman diagrams. Here goes: 1. Is there a standard way to produce arrows a specified fraction of the way along a path? In particular, is there a built-in "midway-arrow" decorator I can apply, or do I have to chop up the path into appropriate sections, one of which gets an earrow? 2. Searching for info on using the pattern module to fill shapes, I found the recipe in this mail: http://sourceforge.net/mailarchive/message.php?msg_id=8845253 As far as I can tell, since then pattern has moved to its own module and I can run the code snippet when that's taken into account. However, the documentation at http://sourceforge.net/mailarchive/message.php?msg_id=8845253 says that pre-defined patterns do exist, but I can't find them documented: any suggestions? Additionally, looking at the EPS output from the code snippet in gv shows very jagged pattern lines (although they print smoothly): can this jaggedness be avoided onscreen or is it a problem with gv's rendering of the PostScript primitives? I've used PostScript hatched fills before (using this code: http://www.feyndiagram.com) and they came out much more smoothly. Thanks in advance for any help, and double-thanks for a very cool piece of code :) Andy -- Andy Buckley : CEDAR-HEP @ IPPP, Durham http://www.insectnation.org ```
 Re: [PyX-user] Mid-arrows and patterns From: Andre Wobst - 2005-09-22 13:01:59 ```Hi, On 21.09.05, Andy Buckley wrote: > I've got a couple of questions relating to PyX... specifically for drawing > Feynman diagrams. Here goes: > > 1. Is there a standard way to produce arrows a specified fraction of the > way along a path? In particular, is there a built-in "midway-arrow" > decorator I can apply, or do I have to chop up the path into appropriate > sections, one of which gets an earrow? Yes, the current implementation of the arrow decorator is restricted to the beginning and end point. However, there is a arrowhead path conctructor, which might be worth a look. You can use it to build your own decorator. As a quick starting point for you: import math from pyx import * class myarrow(deco.deco, attr.attr): def __init__(self, pos=0.5, size=6*unit.v_pt, angle=45, constriction=0.8): self.pos = pos self.size = size self.angle = angle self.constriction = constriction def decorate(self, dp): dp.ensurenormpath() constrictionlen = self.size*self.constriction*math.cos(self.angle*math.pi/360.0) arrowtopos = self.pos*dp.path.arclen()+0.5*self.size arrowtopath = dp.path.split(arrowtopos)[0] arrowpath = deco._arrowhead(arrowtopath, self.size, 45, constrictionlen, 1) dp.ornaments.fill(arrowpath) return dp c = canvas.canvas() c.stroke(path.curve(0, 0, 2, 0, 2, 2, 4, 2), [myarrow(0.5)]) c.writeEPSfile("arrow") Although this might not yet be the result you want for a feynman diagram, it is a start along the "PyX-way". You may want to add some features to the arrow and the _arrowhead method (like stroking only the front of the arrow and not its back) ... we should even discuss to add those features to the PyX distribution. Already this pos-argument above might be worth to be added ... > 2. Searching for info on using the pattern module to fill shapes, I found > the recipe in this mail: > http://sourceforge.net/mailarchive/message.php?msg_id=8845253 > As far as I can tell, since then pattern has moved to its own module and > I can run the code snippet when that's taken into account. However, the > documentation at > http://sourceforge.net/mailarchive/message.php?msg_id=8845253 > says that pre-defined patterns do exist, but I can't find them documented: > any suggestions? Mayby the're missing. I'll drop a note to correct that. Beside that have a look into the pattern module. There are quite a list of predefined patterns. > Additionally, looking at the EPS output from the code snippet in gv shows > very jagged pattern lines (although they print smoothly): can this > jaggedness be avoided onscreen or is it a problem with gv's rendering of > the PostScript primitives? I've used PostScript hatched fills before (using > this code: http://www.feyndiagram.com) and they came out much more smoothly. It depends on what operations you perform in the pattern. Our example having Text in the pattern indeed generates strange output in ghostscript when antialiasing is turned on. BTW you can turn antialiasing off by the shortkey "a" in gv. Overall we can savely claim this to be a ghostscript bug ... ;-) André -- by _ _ _ Dr. André Wobst / \ \ / ) wobsta@..., http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript and PDF figures (_/ \_)_/\_/ with Python & TeX: visit http://pyx.sourceforge.net/ ```
 Re: [PyX-user] Mid-arrows and patterns From: Michael Schindler - 2005-09-23 07:58:27 ```Hello, On 22.09.05, Andre Wobst wrote: > On 21.09.05, Andy Buckley wrote: > > I've got a couple of questions relating to PyX... specifically for drawing > > Feynman diagrams. Here goes: > > > > 1. Is there a standard way to produce arrows a specified fraction of the > > way along a path? In particular, is there a built-in "midway-arrow" > > decorator I can apply, or do I have to chop up the path into appropriate > > sections, one of which gets an earrow? > > Yes, the current implementation of the arrow decorator is restricted > to the beginning and end point. However, there is a arrowhead path > conctructor, which might be worth a look. You can use it to build your > own decorator. As a quick starting point for you: > Although this might not yet be the result you want for a feynman > diagram, it is a start along the "PyX-way". You may want to add some > features to the arrow and the _arrowhead method (like stroking only > the front of the arrow and not its back) ... we should even discuss to > add those features to the PyX distribution. > > Already this pos-argument above might be worth to be added ... +1 from me. We will need a direction-argument also. Michael. -- "A mathematician is a device for turning coffee into theorems" Paul Erdös. ```
 Re: [PyX-user] Mid-arrows and patterns From: Joerg Lehmann - 2005-09-23 08:08:48 ```Hi, On 23.09.05, Michael Schindler wrote: > On 22.09.05, Andre Wobst wrote: > > On 21.09.05, Andy Buckley wrote: > > > I've got a couple of questions relating to PyX... specifically for drawing > > > Feynman diagrams. Here goes: > > > > > > 1. Is there a standard way to produce arrows a specified fraction of the > > > way along a path? In particular, is there a built-in "midway-arrow" > > > decorator I can apply, or do I have to chop up the path into appropriate > > > sections, one of which gets an earrow? > > > > Yes, the current implementation of the arrow decorator is restricted > > to the beginning and end point. However, there is a arrowhead path > > conctructor, which might be worth a look. You can use it to build your > > own decorator. As a quick starting point for you: > > > Although this might not yet be the result you want for a feynman > > diagram, it is a start along the "PyX-way". You may want to add some > > features to the arrow and the _arrowhead method (like stroking only > > the front of the arrow and not its back) ... we should even discuss to > > add those features to the PyX distribution. > > Already this pos-argument above might be worth to be added ... > > +1 from me. We will need a direction-argument also. Yes, I will look into this on the weekend. Jörg ```